一、什么是kickstart
通过上节课的学习,成功创建了虚拟机。但是运行时发现还需要安装系统,而这个过程是非常繁琐和费时的。
这时候可以用到kickstart工具,kickstart能够完成无人执守安装。
二、kichstart脚本
1.在虚拟机下载httpd和system-config-kickstart
yum install system-config-kickstart
2.
systemctl stop firewalld.service #关火墙
systemctl disable firewalld.service #设置火墙开机不启动
systemctl start httpd #开启httpd
systemctl enable httpd #设置httpd开机启动
3.执行system-config-kickstart,生成ks.cfg文件
填写密码
保存到/mnt下
4.更改ks.cfg文件
vim /mnt/ks.cfg 在末尾添加
%packages
@base
lftp
%end
检查文件是否错误
5.编写自动安装脚本
#!/bin/bash #命令运行环境的指定
virt-install \ #安装虚拟机
--location http://172.25.254.64/rhel7.0 \ #安装源
--ram 1024 \ #内存
--cpus 1 \ #cpu数
--disk /var/lib/libvirt/images/$1.qcow2,size=9,bus=virtio \ #硬盘位置,大小
--name $1 \ #指定虚拟机名称
--network source=br0,model=virtio #网络
--extra-args "ks=http://172.25.254.123/ks.cfg"
运行脚本,自动安装虚拟机了。