RHEL8+Kickstart+uefi批量部署最

准备环境

关闭selinux,防火墙

Server:192.168.4.51/24

安装所需软件包:dnf -y install dhcp-server tftp-server vsftp

部署环境

DHCP

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp-server/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
# dhcpd.conf
subnet 192.168.4.0 netmask 255.255.255.0 {
  range 192.168.4.100 192.168.4.200;
  option domain-name-servers 192.168.4.254;
  option routers 192.168.4.254;
  default-lease-time 600;
  max-lease-time 7200;
  next-server 192.168.4.51;
  filename "BOOTX64.EFI"; #注意差异,使用的不是pxelinux.0
}

FTP

注:这里ks.cfg为最小化安装,如果需要安装图形,我会在文章最后提供ks.cfg图形配置和kickstart配文文件详解,这里就不一一解释了。

[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# mkdir dvd
[root@localhost ftp]# mount /dev/cdrom  dvd
[root@localhost ftp]# vim ks.cfg
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use graphical install
graphical   #使用图形界面安装
# Reboot after installation
reboot
repo --name="AppStream" --baseurl=ftp://192.168.4.51/dvd/AppStream  
# Use network installation
url --url="ftp://192.168.4.51/dvd"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# Run the Setup Agent on first boot
firstboot --disable
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=dhcp --device=ens33 --ipv6=auto --activate  #ip获取方式
network  --hostname=localhost.localdomain
# Root password
rootpw --plaintext 1
# X Window System configuration information
xconfig  --startxonboot
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=it --password=$6$fI8GAHa5Q6JG1BB3$6/Dv5ndCa4KMIkVFBkmVzvnV.SvwSO5.h0ppaaI75f53G9dH4.l6yUR.IUYGTKX/ctKwyzliKJQtOpV7TAZqI. --iscrypted --gecos="it"

%packages
%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

TFTP

[root@localhost ~]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# cp /var/ftp/dvd/EFI/BOOT/* .
[root@localhost tftpboot]# vim grub.cfg
set default="1"

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2

set timeout=60
### END /etc/grub.d/00_header ###

search --no-floppy --set=root -l 'RHEL-8-0-0-BaseOS-x86_64'

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 8.0.0' --class fedora --class gnu-linux --class gnu --class os {
	linuxefi vmlinuz ks=ftp://192.168.4.51/ks.cfg     #指定你kickstart文件的路径
	initrdefi initrd.img
   }
}
#注意!!!linuxefi vmlinuz   initrdefi initrd.img 不要写绝对路径。

启动所有服务

systemctl start dhcpd tftp vsftpd 

测试

vmware虚拟机测试,固件类型改UEFI

uefi.jpg

kickstart应答文件(图形安装)

由于rhel8没有system-config-kickstart包,所以无法通过工具生成ks文件,可以对着rhel7的kickstart来改

#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use graphical install
graphical
# Reboot after installation
reboot
repo --name="AppStream" --baseurl=ftp://192.168.4.51/dvd/AppStream
# Use network installation
url --url="ftp://192.168.4.51/dvd"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# Run the Setup Agent on first boot
firstboot --disable
# System language
lang en_US.UTF-8
 
# Network information
network  --bootproto=dhcp --device=ens192 --ipv6=auto --activate
network  --hostname=localhost.localdomain
# Root password
rootpw --plaintext 1
# X Window System configuration information
xconfig  --startxonboot
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=it --password=$6$fI8GAHa5Q6JG1BB3$6/Dv5ndCa4KMIkVFBkmVzvnV.SvwSO5.h0ppaaI75f53G9dH4.l6yUR.IUYGTKX/ctKwyzliKJQtOpV7TAZqI. --iscrypted --gecos="it"
 
%packages
@^graphical-server-environment
kexec-tools
%end
 
%addon com_redhat_kdump --enable --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

Kickstart文件说明

ignoredisk: 在安装过程中控制对磁盘的连接,如果你使用的是自动分区,那么在安装过程中可以通过 ignoredisk --driver=sdc 指定自动分区忽略的磁盘,如果你有多个磁盘,并且只想使用其中一个进行自动分区,并安装操作系统,你可以使用 ignoredisk --only-use=sda 指定只使用 sda 这一个磁盘。

autopart: 自动创建根分区( / ),交换分区(swap)和适当的启动分区(/boot),在足够大的驱动器上,还会创建 /home 分区。通过 --type= 指定分区类型,如示例中使用的 lvm。你还可以通过 --fstype= 指定系统文件类型,如 xfsext4 等等,默认是 xfs。你还可以通过 --encrypted 选项,对所有分区进行加密。

clearpart: 在分区前,删除现有分区。可以通过 --drives= 指定要删除分区的磁盘,也可以通过 --all 清除所有设备的分区。

graphical: 安装过程以图形化的方式进行,就和手动安装一样。也可以使用 text 命令,以文本的方式显示安装过程。

reboot: 安装完成后重启。

repo: 指定额外的软件包安装源。

url: 通过网络安装时,安装文件的位置。

keyboard: 指定键盘布局。通过 --vckeymap= 指定应使用哪个 VConsole 键盘模式。通过 --xlayouts= 指定键盘的布局。

firstboot: 第一次启动系统时,是否显示 Initial Setup。如果启用,则必须安装 initial-setup 软件包。如果未指定,则默认禁用这个选项。--enable 表示启动 Initial Setup,--disable 表示禁用 Initial Setup。如果你使用 --enable ,你还可以使用 --reconfig 选项在引导系统时启动重配置(reconfiguration)模式。在这个模式下,你可以从新配置系统语言,键盘鼠标,root 密码,系统安全级别,时区以及一些网络配置。

lang: 配置系统语言。

network: 网络配置。使用 --bootproto= 指定计算机获取 IP 的方式,是 dchp 还是 static。使用 --device= 指定要配置的设备名称。使用 --activate 激活该设备。如果你的 --bootproto= 使用的是 static,那么你可以使用 ip= 指定 IP 地址,--netmask= 指定子网掩码,--gateway= 指定网关,--nameserver= 指定 DNS。使用 ipv6= 指定 IPv6 配置,使用 auto 表示自动配置。使用 --hostname 配置主机名。

rootpw: 指定 root 用户的密码。--iscrypted 表示密码以密文的方式显示。--plaintext 表示以明文的方式显示密码。你还可以使用 --lock 锁定 root 用户。

* 当你使用 --iscrypted 时,可以在一台已经安装好系统的机器上,通过 python 生成密码的密文(如果是 Python 3,则对应的命令应该是 python3.)。

$ python -c 'import crypt; print(crypt.crypt("My Password"))'

xconfig: 配置 X Windows 系统。--startxonboot 表示在安装的系统中使用图形界面登录。

services: 配置服务的默认状态。--disabled= 指定默认禁用的服务,使用 --enabled= 指定默认启用的服务。

timezone: 指定时区。

user: 添加额外的用户。通过 --name= 指定用户名,通过 --groups= 指定用户要添加的组(除默认组),通过 --password= 指定该用户的密码,--iscrypted 表示以密文的方式,通过**--gecos=** 定义用户的 GECOS信息,如,用户的全名等等。

%packages 表示要安装的软件包。

通过 @ 指定软件包组,如:

%packages
@core
@X Window System
@Desktop
%end

通过 @^ 指定环境组,如:

%packages
@^graphical-server-environment
%end

直接输入软件包名,指定独立的软件包,如:

%packages
@core
@desktop
sqlitebas
curl
%end

通过 - 号排错软件包组中的某个软件包

%packages
@Development Tools
-pkgconf
-pkgconf-m4
-pkgconf-pkg-config
-redhat-rpm-config
%end

* %package 要以 %end 结尾

%addon 配置 kdump。--enable 表示开启,并通过 --reserve-mb= 指定为 kdump 预留的内存大小,auto 表示自动。要以 %end结束。

%anaconda 部分指定了 password 策略,同样以 %end 结束。

你还可以通过 %pre 指定在磁盘分区前要执行的脚本,通过 %post 指定系统安装完成后要执行的脚本。这些模块都需要 %end 结束。

更多关于 kickstart 应答文件的语法可以参考官方网站的系统安装指南。到目前为止,红帽官网还没有关于 RHEL 8 的安装指南,你可以参考 RHEL 7 的安装指南进行编写。