kvm虚拟化二: 字符界面管理及 无人值守安装

1. 安装必要工具
yum install /
tigervnc //vnc远程桌面客户端
virt-viewer //虚拟机查看器

2.安装虚拟机
virt-install /
-n 名字 //虚拟机名
-m 1024 //内存大小
--vcpus=2 //虚拟内存数量
--disk_path=/...,size=5 //硬盘文件位置(.qcow2等), size指定大小,如果用qemu-img已生成可省略
-c /mnt/cdrom/centos7.iso //指定iso镜像
--accelerate KVM //开启内核加速器KVM或KQEMU都可,默认kvm
--network default //指定网卡模式,默认nat,可选bridge
--graphics vnc //vnc图形查看
--extra-args=EXTRA //加载内核参数,如无人值守安装系统

3.ks文件, 无人值守安装
vi ks.cfg

4.搭建本地源
yum install httpd -y
mkdir /var/www/html/centos7
mount /dev/sr0 /var/www/html/centos7
systemctlf start httpd
iptables -F
vi ks.cfg

#####========ks.cfg=========#####

#platform=x86, AMD64, or Inter EM64T
#version=DEVEL
#Firewall configuration
firewall --disabled
#Install OS instead of upgrade
install
#Use network installation
url --url="http://192.168.1.11/centos7"
#Root password
rootpw --iscrypted $1$wPwHiich$KLX4zsMQWtmBVND.qo8k.1
#System authorization information
auth --useshadow --passalgo=sha512
#Use graphical install
graphical
firstboot --disable
#System keyboard
keyboard us
#System language
lang zh_CN
#SELinux configuration
selinux --disabled
#Installation logging level
logging --level=info
#Reboot after installation
reboot
#System timezone
timezone Asia/Shanghai
#Network information
network --bootproto=dhcp --device=eth0 --onboot=on
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part /boot --fstype="ext4" --size=100
part swap --fstype="swap" --size=1024
part / --fstype="ext4" --size=10000

%post
touch /tmp/a.txt
%end

%packages
@basic-desktop
@chinese-support
%end

#####======== end =========#####

5. 安装
virt-install --name centos7 --ram 1024 --vcpus=1 --disk path=/var/lib/libvirt/images/centos7-74.qcow2,size=10 --accelerate --localtion=http://192.168.1.11/centos7/ --network bridge=br0 -x "ks=http://192.168.1.11/ks.cfg"
cp ks.cfg /var/www/html

# cdrom 改为localtion使用已经挂载的cdrom , -x “ks=”指定无人值守配置文件位置
# ps:dhcp 分配网段必须与源地址同一网段

原文地址:https://www.cnblogs.com/caya-yuan/p/10534606.html