CentOS自动安装(kickstart)

kickstart

kickstart是红帽发行版中的一种安装方式,它通过以配置文件的方式来记录linux系统安装是的各项参数和想要安装的软件。只要配置正确,整个安装过程中无需人工交互参与,达到无人值守安装的目的。

kickstart配置文件生成

1). 自动化安装系统

yum install system-config-kickstart.noarch -y

2). 安装完成后,执行如下命令启动kickstart

system-config-kickstart 

3). 启动选择配置安装系统的root用户密码,安装方式,案例中使用HTTP方式进行安装

CentOS自动安装(kickstart)

4). 选择bootloader安装方式,清除原硬盘上的所有分区

CentOS自动安装(kickstart)

5). 创建磁盘分区

CentOS自动安装(kickstart)

6). 选择网卡并配置网卡信息

CentOS自动安装(kickstart)

7). 不安装图形界面

CentOS自动安装(kickstart)

8). 保存配置文件

CentOS自动安装(kickstart)

9). 由于没有选择安装包,需要在文件末尾指定需要安装的软件

vim ks.cfg #编辑文件,指定安装过程中需要安装的软件,在文件末尾添加

CentOS自动安装(kickstart)

10). 检测语法是否正确

ksvalidator ks.cfg 

利用生成的配置文件进行自动安装

1). 安装配置Web服务器,使用缺省目录(案例中使用目录/home/www/html), 监听端口为8081

将镜像文件挂载到http://192.168.20.230:8081/CentOS8目录下

[root@h230]#mkdir /home/www/html/CentOS8
[root@h230]#mount  /home/admin/Images/CentOS-7-x86_64-DVD-1810.iso /home/www/html/CentOS8/
mount: /dev/loop0 is write-protected, mounting read-only

2). 开始创建虚拟机并执行自动安装

virt-install \
--connect qemu:///system \
--virt-type kvm \
--name CentOS8 \
--vcpus 2,maxvcpus=2 \
--ram 4096 \
--disk path=/home/admin/VM/CentOS8.qcow2,size=40,format=qcow2,bus=virtio,sparse \
--network bridge=br0,model=virtio \
--nographics \
--location http://192.168.20.230:8081/CentOS8 \
--extra-args "ks=http://192.168.20.230:8081/ks.cfg  console=ttyS0" \
--force  \
--video=cirrus

#若出现如下错误表示没有将将镜像正确挂载

ERROR Error validating install location: Could not find an installable distribution at \’http://192.168.20.230/CentOS8\’: The URL could not be accessed, maybe you mistyped?

出现如下错误,则可能是DHCP Server没有正确配置,虚拟机网口起来时没有正确获取到地址所致

Warning: dracut-initqueue timeout – starting timeout scripts

制作kickstart启动镜像

1). 将原始的镜像文件挂载到/home/www/html/CentOS8目录下(需要事先创建该目录)

 mount /home/admin/Images/CentOS-8.1.1911-x86_64-dvd1.iso /home/www/html/CentOS8

2). 创建/home/myiso目录,将镜像文件同步到该目录下

mkdir  /home/myiso
rsync -a /home/www/html/CentOS8/ /home/myiso/

3). 将创建好的ks.cfg文件复制到/home/myiso, 并修改安装方式为cdrom

cp /home/www/html/ks.cfg /home/myiso/ks.cfg
vim  /home/myiso/ks.cfg
#验证ks配置文件正确性
 ksvalidator /home/myiso/ks.cfg 

3). 编辑/home/myiso/isolinux/isolinux.cfg

chmod 777 /home/myiso/isolinux/isolinux.cfg 
vim /home/myiso/isolinux/isolinux.cfg 
增加ks启动项
label ks
  menu label ^kickstart
  menu default
  kernel vmlinuz
  append ks ks=cdrom:/ks.cfg initrd=initrd.img console=ttyS0,115200n8

4). 制作ISO镜像文件

mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 \
          --boot-info-table -V "CentOS 6.8 x86_64 boot" \
	        -b isolinux/isolinux.bin -c isolinux/boot.cat \
       	-o /home/CentOS8.kickstart.iso /home/myiso/

5). 使用新的镜像文件安装虚拟机

virt-install \
--connect qemu:///system \
--virt-type kvm \
--name CentOS8.2 \
--vcpus 1,maxvcpus=1 \
--ram 4096 \
--disk path=/home/admin/VM/CentOS8.2.qcow2,size=40,format=qcow2,bus=virtio,sparse \
--network bridge=br1,model=virtio \
--nographics \
--location=/home/CentOS8.kickstart.iso \
--extra-args "console=ttyS0" \
--video=cirrus

#自动启动配置文件内容示例:

#version=RHEL7 Kickstart
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use text mode install
text
# Shutdown after installation
shutdown
# Use CDROM installation media
cdrom
# Run the Setup Agent on first boot
firstboot --disable
# ignoredisk --drives="/dev/disk/by-label/CentOS\\x207\\x20x8*"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts=\'us\'
# System language
lang en_US.UTF-8
#SELinux configuration
selinux --disable
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=static --hostname=localhost.localdomain
# Root password
rootpw 123.com
# Do not configure the X Window System
skipx
# System services
services --disabled="abrtd,atd,chronyd,avahi-daemon,postfix"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
%include /tmp/bootloader.cfg
#autopart --type=lvm
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype=ext4 --size=500
part / --fstype=ext4 --grow --size=2000

%packages 
@base
@core
@php
freeradius
ftp
ntp
perl-core
php-mysql
sqlite-devel
telnet
%end

内容出处:,

声明:本网站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时修改或删除。文章链接:http://www.yixao.com/soft/16130.html

发表评论

登录后才能评论