####如何建立ks.cfg
yum install system-config-kickstart httpd
system-config-kickstart 保存在/var/www/html
cd /var/www/html
ls
vim ks.cfg
%packages
@base
lftp
%end
%post
cat >>/etc/yum.repos.d/yum.repo <<EOF
[rhel7.2]
name=rhel7.2
baseurl=http://172.25.254.49/rhel7.2
gpgcheck=0
EOF
%end
ksvalidator ks.cfg
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
####自动安装脚本##
vim create_vm.sh
#!/bin/bash
virt-install \
--name $1 \
--ram 1024 \
--cpus 1 \
--disk /var/lib/libvirt/images/$1.qcow2,bus=virtio,size=9 \
--network bridge=br0,model=virtio \
--location http://172.25.254.49/rhel7.2 \
--extra-args ks=http://172.25.254.100/ks.cfg &
chmod 755 create_vm.sh
sh /mnt/create_vm.sh hello
便可以自动安装虚拟机了