1. 安装libvirtd,qemu-kvm,及配置network等虚拟化前提已配置完毕

2. 安装virt-install, virt-viewer, libvirt-client

3. 准备名为mini.ks的kickstart的文件

install
#cdrom
keyboard 'us'
rootpw --iscrypted $1$sTFxjNuW$9ARXzMVhX333l4SeyaGQt/
lang en_US
auth --useshadow --passalgo=sha512
text
selinux --disabled
skipx
firewall --disabled
reboot
timezone Asia/Shanghai
bootloader --location=mbr --append="net.ifnames=0 biosdevname=0"
zerombr
network --bootproto=dhcp
%include /tmp/my_partinfo.txt

%pre
set $(list-harddrives)
let numd=$#/2

echo "clearpart --drives=$1 --all --initlabel" >> /tmp/my_partinfo.txt
disk_capacity=`parted -s /dev/$1 print | grep ^Disk | sed -n '1p' | awk '{ print $3 }' | cut -d"G" -f1`
if test $disk_capacity -gt 2000; then
echo "part biosboot --fstype=biosboot --ondisk=$1 --size=1" >> /tmp/my_partinfo.txt
fi

cat >> /tmp/my_partinfo.txt <<EOF
part /boot --fstype="ext3" --ondisk=$1 --size=1024
part /boot/efi --fstype="efi" --ondisk=$1 --size=1024 --fsoptions="umask=0077,shortname=winnt"
part swap --fstype="swap" --ondisk=$1 --size=1024
part / --fstype="xfs" --grow --ondisk=$1 --size=1
EOF

%end

%post
echo "alias vi='vim'" > /etc/profile.d/vi_alias_vim.sh

# openssh-server config
sshd_config_file=/etc/ssh/sshd_config

sed -i '/GSSAPIAuthentication/d' ${sshd_config_file}
sed -i '$a\GSSAPIAuthentication no' ${sshd_config_file}
sed -i '/UseDNS/d' ${sshd_config_file}
sed -i '$a\UseDNS no' ${sshd_config_file}
%end

%packages
@^minimal
@core
wget
net-tools
vim
bind-utils
pciutils
util-linux
%end

%addon com_redhat_kdump --disable --reserve-mb='auto'
%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

4. 执行以下命令,开始安装

[root@master centos]# virt-install --name centos7.6 \
> --memory 2048 --vcpus 2 \
> --disk pool=default,format=qcow2,size=60 \
> --location ./CentOS-7.6-x86_64-Everything-1810.iso \
> --network network=nat-network \
> --os-variant=centos7.0 \
> --initrd-inject=./mini.ks --extra-args "ks=file:/mini.ks" \
> --graphics vnc

5. 正在安装(会自动调用virt-viewer显示安装界面,如下图所示)

6. 等待安装完毕即可