文章目录
-
PXE Server Setup
PXE Server Setup
一、PXE原理介绍
预启动执行环境(Preboot eXecution Environment,PXE)也被称为预执行环境,提供了一种使用网络接口(Network Interface)启动计算机的机制。这种机制让计算机的启动可以不依赖本地数据存储设备(如硬盘)或本地已安装的操作系统。
要实现pxe,至少需要3个服务:
DHCP:提供网络参数,告知客户端TFTP位置
TFTP:提供boot loader及kernel file下载路径
HTTP/FTP/NFS:三种架构提供内核文件
1.1、PXE框架
1.2、PXE流程
以Legacy模式为例介绍
PXE启动过程的文字注释:
1)client向pxe server上的dhcp发送IP地址请求消息,dhcp检测client是否合法,同事将pxe环境下的boot loader文件pxelinux.0的位置信息发给client
2)client向pxe server上的tftp请求pxelinux.0,tftp收到消息向client发送pxelinux.0大小信息,试探client是否满意,当tftp收到client发回的统一大小信息后,发送pxelinux.0.
3)client执行接收到的pxelinux.0
4)client向TFTP请求pxelinux.cfg文件(其实是目录,里面放了启动菜单,即grub的配置文件),TFTP将配置文件发回client,继而client根据配置文件执行后续的操作
5)client向TFTP发送linux内核请求信息,TFTP发送内核
6)client向TFTP发送根文件请求信息,TFTP接受到消息之后返回linux根文件系统
7)client加载linux内核(启动参数已经在4中的配置文件中设置好了)。
8)client通过nfs/ftp/http下载系统安装文件进行安装,如果4中的配置文件指定了kickstart路径,则回根据此文件自动应答安装系统
1.3、文件介绍
- vmlinuz:核心文件(kernel file);
- initrd.img:开启过程中核心组件的参数;
- isolinux.cfg --> demo:Legace pxe选择菜单配置参考;
- EFI/BOOT/grub.cfg --> deme: UEFI pxe选择菜单配置参考;
1.4、Legacy BIOS和EFI BIOS引导区别:
-
传统Legacy BIOS:
一般使用syslinux提供的pxelinux.0来引导。
传统Legacy BIOS引导,在pxelinux.0引导后,它会请求并加载server端tftpboot目录中,与pxelinux.0同目录下的pxelinux.cfg目录里的default文件。Oct 12 21:43:35 Simonlinux in.tftpd[20331]: Client 192.168.15.34 finished legacy/pxelinux.0 Oct 12 21:43:35 Simonlinux in.tftpd[20342]: Client 192.168.15.34 finished legacy/pxelinux.cfg/default Oct 12 21:43:35 Simonlinux in.tftpd[20343]: Client 192.168.15.34 finished legacy/vesamenu.c32 Oct 12 21:43:35 Simonlinux in.tftpd[20344]: Client 192.168.15.34 finished legacy/pxelinux.cfg/default Oct 12 21:43:35 Simonlinux in.tftpd[20345]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf Oct 12 21:43:39 Simonlinux in.tftpd[20347]: Client 192.168.15.34 finished legacy/vesamenu.c32 Oct 12 21:43:39 Simonlinux in.tftpd[20348]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf Oct 12 21:43:39 Simonlinux in.tftpd[20349]: Client 192.168.15.34 finished legacy/pxelinux.cfg/centos_install Oct 12 21:43:39 Simonlinux in.tftpd[20350]: Client 192.168.15.34 finished legacy/pxelinux.cfg/graphics.conf Oct 12 21:43:44 Simonlinux in.tftpd[20352]: Client 192.168.15.34 finished /boot/centos/76/vmlinuz Oct 12 21:44:12 Simonlinux in.tftpd[20353]: Client 192.168.15.34 finished /boot/centos/76/initrd.img
-
EFI BIOS引导:
对于EFI BIOS,需要使用efi文件引导,一般可使用Grub2。为实现UEFI SecureBoot,大多数Linux使用shim.efi嵌套调用grubx64.efi来引导。
grubx64.efi和shimx64.efi有什么区别呢?在安全启动(serureboot)关闭的情况下,你可以使用grubx64.efi。如果安全启动打开则需要选择shimx64.efi。
在shim.efi嵌套引导了grubx64.efi之后,它会请求grubx64.efi同目录下的grub.cfg配置文件(redhat7),同时加载显示引导菜单。而对于RHEL6来说,它并不支持SecureBoot,所以必须要使用grub-efi 0.97来引导,一般是BOOTX64.efi,同时它会请求同目录下的efidefault配置文件(redhat6),加载并显示引导菜单。Oct 12 22:00:35 Simonlinux in.tftpd[21265]: Client 192.168.15.34 finished uefi/grubx64.efi Oct 12 22:00:35 Simonlinux in.tftpd[21275]: Client 192.168.15.34 finished /uefi/grub.cfg Oct 12 22:00:35 Simonlinux in.tftpd[21280]: Client 192.168.15.34 finished /uefi/grub.cfg Oct 12 22:00:53 Simonlinux in.tftpd[21289]: Client 192.168.15.34 finished /boot/centos/76/vmlinuz Oct 12 22:01:24 Simonlinux in.tftpd[21290]: Client 192.168.15.34 finished /boot/centos/76/initrd.img
二、PXE部署
首先完成准备工作,然后开始安装DHCP、TFTP,接着提供bootloader及配置文件,挂着ISO镜像把内核文件copy到tftp目录,部署httpd/vsftp/nfs提供文件服务,设置菜单及提供系统安装软件。
功能 | OS | IP | 用途 |
---|---|---|---|
PXE服务器 | Redhat 7.6 | 192.168.0.5 | DHCP、TFTP、HTTP、PXE |
客户端 | NA | 192.168.0.* | 测试机,通过PXE安装OS |
2.1、准备工作
关闭防火墙(service iptables stop)和SElinux (setenforcing 0)
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config
2.2、安装组件
- 组件功能介绍
Kickstart: 将安装过程的参数写入到ks.cfg文件,实现自动安装配置达到无人值守自动安装;
TFTP: 支持PXE 引导的网卡中从tftp服务器端下载pxelinux.0/shim.efi(grubx64.efi)文件、vmlinuz、initrd.img等内核引导文件;
DHCP: PXE引导过程中先获取IP地址,并提供pxelinux.0(legacy)/shim.efi(uefi)文件位置;
HTTP: 用于下载ks.cfg以及系统镜像文件。
[root@server ~]# yum install httpd
[root@server ~]# yum install dhcp
[root@server ~]# yum install tftp-server
[root@server ~]# yum install xinetd
[root@server ~]# yum install syslinux
2.3、DHCP配置
2.3.1 配置静态网络IP
[root@server ~]# vim /etc/sysconfig/network-script/ifcfg-eth0
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
NETBOOT=yes
#UUID="2a9f70b5-5920-4b44-bec6-986446613315"
IPV6INIT=yes
BOOTPROTO=static
#BOOTPROTO=none
IPV6ADDR=2001:db8:ffff:100:1::10
IPV6_DEFAULTGE=2001:db8:ffff:100:1::1
IPADDR=192.168.0.5
GATEWAY=192.168.0.39
NETMASK=255.255.255.192
TYPE=Ethernet
2.3.2 修改dhcp配置文件
- dhcp4
[root@server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@server ~]# vim /etc/dhcp/dhcpd.conf
allow booting;
allow bootp;
ddns‐update‐style none;
ignore client‐updates;
option arch code 93 = unsigned integer 16;
option domain-name-servers 192.168.0.5;
default-lease-time 14400;
subnet 192.168.0.0 netmask 255.255.255.192 {
range 192.168.0.40 192.168.0.60;
option broadcast‐address 192.168.0.63;
option routers 192.168.0.39;
option subnet‐mask 255.255.255.192;
default-lease-time 14400;
max-lease-time 172800;
next-server 192.168.0.5;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
if option arch = 00:07 or option arch = 00:09 {
filename "/uefi/shim.efi";
#filename "/uefi/BOOTX64.efi";
} else {
filename "pxelinux.0";
}
}
class "httpclients" {
match if substring (option vendor-class-identifier, 0, 10) = "HTTPClient";
option vendor-class-identifier "HTTPClient";
if option arch = 00:10 {
filename "http://192.168.0.5/httpboot/shim.efi";
}
}
}
- dhcp6
[root@server ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example /etc/dhcp/dhcpd6.conf
[root@server ~]# vim /etc/dhcp/dhcpd6.conf
allow booting;
allow bootp;
option dhcp6.bootfile-url code 59 = string;
option dhcp6.client-arch-type code 61 = array of unsigned integer 16;
option dhcp6.vendor-class code 16 = {integer 32, integer 16, string};
option dhcp6.name-servers 2001:db8:ffff:100::10;
if option dhcp6.client-arch-type = 00:07 or option dhcp6.client-arch-type = 00:09 {
#option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/uefi/shim.efi";
option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/uefi/grubx64.efi";
}
else {
option dhcp6.bootfile-url "tftp://[2001:db8:ffff:100::10]/pxelinux.0";
}
if option dhcp6.client-arch-type = 00:10 {
option dhcp6.bootfile-url "http://[2001:db8:ffff:100::10]/uefi/grubx64.efi";
option dhcp6.name-servers 2001:db8:ffff:100::10;
option dhcp6.vendor-class 0 10 "HTTPClient";
}
subnet6 2001:db8:ffff:100::/64 {
range6 2001:db8:ffff:100::10 2001:db8:ffff:100::1000;
}
另外dhcp配置文件可以做绑定,用Mac绑定某台主机的ip地址
host clientA {
hardware ethernet 38:68:dd:16:af:84;
fixed-address 192.168.0.62;
}
RHEL7以支持UEFI SecureBoot。通过TFTP把shim.efi加载后会继续嵌套加载引导同目录下的grubx64.efi,然后grub会获取同目录下的grub.cfg以显示引导菜单。
对于EFI模式下RHEL6 PXE引导,需要dhcpd.conf指定filename “uefi/BOOTX64.efi”,它其实是grub 0.97。通过TFTP加载了BOOTX64.efi之后它会继续加载同目录下的efidefault引导配置文件,并显示引导菜单。
2.3.4 启动服务
systemctl start dhcpd
systemctl enable dhcpd
systemctl start dhcpd6
systemctl enable dhcpd6
2.4. TFTP配置
从流程得知boot loader文件以及内核相关的配置文件主要都是由TFTP来提供的
2.4.1 编辑配置文件
[root@server ~]# vim /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot # tftp 目录
disable = no # 开启tftp只需要改为no
per_source = 11
cps = 100 2
flags = IPv4
}
TFTP是由xinetd这个super daemon所管理的,因此设定好TFTP之后,要启动的是xinetd;
2.4.2 启动服务
[root@server ~]# systemctl restart tftp
[root@server ~]# systemctl enable tftp
[root@server ~]# systemctl restart xinetd
[root@server ~]# systemctl enable xinetd
2.4.3 服务验证
[root@server ~]# netstat -untlp | grep :69
udp 0 0 0.0.0.0:69 0.0.0.0:* 6857/xinetd
2.5、文件共享服务器搭建(vsftp/nfs/http)
2.5.1 ISO挂载拷贝到/pxeimg目录
[root@server ~]# mkdir /pxeimg/centos/7.6/os/x86_64 -p
[root@server ~]# mkdir /pxeimg/centos/8.5/os/x86_64 -p
[root@server ~]# tree /pxeimg/
/pxeimg/
└── centos
├── 7.6
│ └── os
│ └── x86_64
└── 8.5
└── os
└── x86_64
7 directories, 0 files
[root@server ~]# mount -o loop CentOS-7.6-x86_64-DVD-1810.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@server ~]# cp -fr /mnt/* /pxeimg/centos/7.6/os/x86_64/
[root@server ~]# umount /mnt/
[root@server ~]# mount -o loop CentOS-8.5.2111-x86_64-dvd1.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@server ~]# cp -fr /mnt/* /pxeimg/centos/8.5/os/x86_64/
2.5.2 文件共享服务搭建
- 搭建http server
- 安装http rpm包
[root@server ~]# yum install httpd
- 开启http服务
systemctl restart httpd systemctl enable httpd
- 将/pxeimg 链接到http共享目录
ln -s /pxeimg /var/www/html
- 搭建nfs server
- 安装nfs rpm包
[root@server ~]# yum install nfs-utils
- 修改nfs配置文件
[root@server ~]# vim /etc/exports /nfs *(rw,no_root_squash) /var/lib/tftpboot *(rw,no_root_squash)
- 重启nfs设置开机自启动
[root@server ~]# systemctl restart nfs [root@server ~]# systemctl enable nfs
- 将/pxeimg软链接到nfs共享目录
ln -s /pxeimg /nfs
- 搭建vsftp server
- 安装vsftp rpm包
[root@server ~]# rpm -ivh vsftp
- 重启vsftp设置开机自启动
[root@server ~]# systemctl restart vsftp [root@server ~]# systemctl enable vsftp
- 将/pxeimg软链接到nfs共享目录
ln -s /pxeimg /var/ftp
2.6、BootLoader及boot文件准备
- Legacy
vesamenu.c32和menu.c32是syslinux所拥有众多模块中的两个,它们的功能是制定启动器使用什么模式。 vesamenu.c32图形模式,menu.c32文本模式。同时还需要pxelinux.0文件,它对整个引导器的作用就如同内核对系统的作用,它可以解释default文件(配置引导菜单的文件)中的每个配置项,并根据配置项做出不同的反应,如等待的时间、启动器背景、启动菜单、内核引导等。
[root@server ~]# yum install syslinux* -y [root@server ~]# cd /var/lib/tftpboot [root@server tftpboot]# cp /usr/share/syslinux/{vesamenu.c32,menu.c32,pxelinux.0} . [root@server tftpboot]# mkdir pxelinux.cfg [root@server tftpboot]# mkdir boot/centos/{7.6,8.5} [root@server tftpboot]# cp /pxeimg/centos/7.6/os/x86_64/isolinux/{vmlinuz,initrd.img} boot/centos/7.6 # Centos8环境拷贝以下文件 [root@server ~]# cd /var/lib/tftpboot/ [root@server tftpboot]# cp /pxeimg/centos/8.5/os/x86_64/isolinux/{ldlinux.c32,libutil.c32,libcom32.c32} . [root@server tftpboot]# cp /pxeimg/centos/8.5/os/x86_64/isolinux/{vmlinuz,initrd.img} boot/centos/8.5 # 目录结构 [root@server lib]# tree tftpboot/ tftpboot/ ├── boot │ └── centos │ ├── 7.6 │ │ ├── initrd.img │ │ └── vmlinuz │ └── 8.5 │ ├── initrd.img │ └── vmlinuz ├── ldlinux.c32 ├── libcom32.c32 ├── libutil.c32 ├── menu.c32 ├── pxelinux.0 ├── pxelinux.cfg └── vesamenu.c32 5 directories, 10 files
- UEFI
从RHEL7.6光盘中提取shim.efi和grubx64.efi
grubx64.efi和shimx64.efi有什么区别呢?在安全启动(serureboot)关闭的情况下,你可以使用grubx64.efi。如果安全启动打开则需要选择shimx64.efi。[root@server ~]# mount -o loop rhel-server-7.6-x86_64-dvd.iso /mnt [root@server ~]# cp /mnt/Packages/shim-0.9-2.el7.x86_64.rpm /tmp [root@server ~]# cp /mnt/Packages/grub2-efi-2.02-0.44.el7.x86_64.rpm /tmp [root@server ~]# rpm2cpio /tmp/shim-0.9-2.el7.x86_64.rpm | cpio -dimv [root@server ~]# rpm2cpio /tmp/grub2-efi-2.02-0.44.el7.x86_64.rpm| cpio -dimv [root@server ~]# mkdir -p /var/lib/tftpboot/uefi/ [root@server ~]# cp /tmp/boot/efi/EFI/redhat/shim.efi /var/lib/tftpboot/uefi/ [root@server ~]#cp /tmp/boot/efi/EFI/redhat/grubx64.efi /var/lib/tftpboot/uefi/ [root@server ~]#cp /mnt/EFI/BOOT/BOOTX64.EFI /var/lib/tftpboot/uefi/ [root@server ~]#cp /mnt/EFI/BOOT/grub.cfg /var/lib/tftpboot/uefi/ [root@server ~]# tree tftpboot/ tftpboot/ ├── boot │ └── centos │ ├── 7.6 │ │ ├── initrd.img │ │ └── vmlinuz │ └── 8.5 │ ├── initrd.img │ └── vmlinuz ├── ldlinux.c32 ├── libcom32.c32 ├── libutil.c32 ├── menu.c32 ├── pxelinux.0 ├── pxelinux.cfg ├── uefi │ ├── BOOTX64.EFI │ ├── efidefault │ ├── grub.cfg │ ├── grubx64.efi │ └── shim.efi └── vesamenu.c32
2.7、启动引导配置
-
default文件配置(Legacy)
[root@server tftpboot]# vim pxelinux.cfg/default default menu.c32 timeout 600 menu title ########## Legacy PXE Boot Menu ########## label centos7.6 menu label install centos 7.6 via http kernel boot/centos/7.6/vmlinuz append initrd=boot/centos/7.6/initrd.img method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 #append initrd=boot/centos/7.6/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 #append initrd=boot/centos/7.6/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 label centos8.5 menu label install centos 8.5 via http kernel boot/centos/8.5/vmlinuz append initrd=boot/centos/8.5/initrd.img method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 #append initrd=boot/centos/8.5/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 #append initrd=boot/centos/8.5/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 label local menu default menu label ^Boot from local drive localboot 0xffff
-
grub.cfg文件配置(UEFI)
[root@server tftpboot]# vim uefi/grub.cfg set timeout=5 menuentry 'Install CentOS 7.6 via http' { linuxefi boot/centos/7.6/vmlinuz method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 # linuxefi boot/centos/7.6/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 # linuxefi boot/centos/7.6/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 initrdefi boot/centos/7.6/initrd.img } menuentry 'Install CentOS 8.5 via http' { linuxefi boot/centos/8.5/vmlinuz method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 # linuxefi boot/centos/8.5/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 # linuxefi boot/centos/8.5/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 initrdefi boot/centos/8.5/initrd.img }
2.8、测试
1. IPV4:
-
Legacy PXE
-
UEFI PXE
-
UEFI httpboot
2. IPV6:
将选择菜单default/grub.cfg中ipv4 address改为ipv6 address,同理进行测试。
- Legacy PXE
- UEFI PXE
- UEFI httpboot
2.9、已知问题
- ipv6 httpboot 需要使用centos7.8以上版本的grub2 bootloader进行引导,低版本不支持 http ipv6
[Bug 1732765 - UEFI HTTP boot over IPv6 does not work][https://bugzilla.redhat.com/show_bug.cgi?id=1732765]
三、Kickstart 自动化安装
3.1、 简介
kickstart是一个利用Anconda工具实现服务器自动化安装的方法;通过生成的kickstart配置文件ks.cfg,服务器安装可以实现从裸机到全功能服务的的非交互式(无人值守式)安装配置;
ks.cfg是一个简单的文本文件,文件包含Anconda在安装系统及安装后配置服务时所需要获取的一些必要配置信息(如键盘设置,语言设置,分区设置等);Anconda直接从该文件中读取必要的配置,只要该文件信息配置正确无误且满足所有系统需求,就不再需要同用户进行交互获取信息,从而实现安装的自动化;但是配置中如果忽略任何必需的项目,安装程序会提示用户输入相关的项目的选择,就象用户在典型的安装过程中所遇到的一样。一旦用户进行了选择,安装会以非交互的方式(unattended)继续。
3.2、流程
文字描述过程:
1. PXE Client 从⾃⼰的PXE⽹卡启动,向本⽹络中的DHCP服务器索取IP︔
2. DHCP 服务器返回分配给客户机的IP 以及PXE文件的放置位置︔
3. PXE Client 向本⽹络中的TFTP服务器索取pxelinux.0 文件︔
4. PXE Client 取得pxelinux.0 文件后之执⾏该文件︔
5. PXE Client 请求下载kickstart⽣成的配置文件(*.ks)︔
6. PXE Client ks文件访问NFS服务器并完成⾃动装机。
Note:
1. PXE Client 需要带有⽀持PXE的⽹卡,并且从PXE模式启动。
2. 以上逻辑图和原理放在实际⽣产中,只需要把DHCP、TFTP、NFS和Kickstart架设在同⼀个
Server/PC即可
使用kickstart优势:
1. 流线化自动化的安装;
2. 快速大量的裸机部署;
3. 强制建立的一致性(软件包,分区,配置,监控,安全性)
4. 减少人为的部署失误
3.3、kickstart服务安装和使⽤
3.3.1 服务安装
- 如果PXE的Server是文字界⾯,需要安装gdm,图形界⾯⽆需此步骤
yum -y install gdm
- 安装kickstart服务包
yum -y install system-config-kickstart
3.3.2 创建development.repo
以CentOS7.6为例
- Copy and mount centos7.6 iso file to SUT.
# mount -o loop CentOS-7.6-x86_64-DVD-1810.iso /mnt
- Create local yum repo for SUT
# vim /etc/yum.repos.d/development.repo [development] #必须是development,否则kickstart读取不到 name=development baseurl=file:///mnt/ #iso挂载本地光盘的路径 gpgcheck=0 #检查GPG-KEY,0为不检查 enabled=1 #启用yum源,0为不启用,1为启用
- Download yum repository data to cache
# yum makecache
3.3.3 制作kickstart文件
使⽤条件:图形界⾯
- 执行system-config-kickstart
制作过程省略#system-config-kickstart
[root@server ~]# cat /root/ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$Mz5Qd9s6$xnnbW5O.9FdsOPPvUiOU01 # Use network installation url --url="http://192.168.15.10/image/centos/76" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # SELinux configuration selinux --enforcing # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp --device=eth0 # Reboot after installation reboot # System timezone timezone Asia/Shanghai # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel %packages @additional-devel @anaconda-tools @backup-client @backup-server @base @compat-libraries @console-internet @core @debugging @desktop-debugging @development %end
3.3.4 检查kickstart文件语法及完整性
[root@server ~]# ksvalidator /root/Desktop/ks.cfg
[root@server ~]#
3.4、使用kickstart文件自动部署
3.4.1 创建kickstart共享文件目录
[root@server ~]# mkdir /kickstart
[root@server ~]# ln -s /kickstart /var/www/html/ #for http
[root@server ~]# ln -s /kickstart /nfs/ # for nfs
[root@server ~]# ln -s /kickstart /var/ftp/ # for vsftp
3.4.2 将步骤三创建的ks文件拷贝到/kickstart目录
[root@server ~]# mkdir -p /kickstart/centos/76
[root@server ~]# cp ks.cfg /kickstart/centos/76
3.4.3 更新引导菜单
- Legacy
[root@server tftpboot]# vim pxelinux.cfg/default default menu.c32 timeout 600 menu title ########## Legacy PXE Boot Menu ########## label centos7.6 menu label install centos 7.6 via http kernel boot/centos/7.6/vmlinuz append initrd=boot/centos/7.6/initrd.img method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 #append initrd=boot/centos/7.6/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 #append initrd=boot/centos/7.6/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 label centos8.5 menu label install centos 8.5 via http kernel boot/centos/8.5/vmlinuz append initrd=boot/centos/8.5/initrd.img method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 #append initrd=boot/centos/8.5/initrd.img method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 #append initrd=boot/centos/8.5/initrd.img method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 label centos7.6-auto menu label install centos 7.6 via http+kickstart kernel boot/centos/7.6/vmlinuz append initrd=boot/centos/7.6/initrd.img ks=http://192.168.0.5/kickstart/centos/7.6/ks.cfg #append initrd=boot/centos/7.6/initrd.img ks=nfs://192.168.0.5:/nfs/kickstart/centos/7.6/ks.cfg #append initrd=boot/centos/7.6/initrd.img ks=ftp://192.168.0.5:/kickstart/centos/7.6/ks.cfg label local menu default menu label ^Boot from local drive localboot 0xffff
- UEFI
[root@server tftpboot]# vim uefi/grub.cfg set timeout=5 submenu '01 Manual Install Menu-->' { menuentry 'Install CentOS 7.6 via http' { linuxefi boot/centos/7.6/vmlinuz method=http://192.168.0.5/pxeimg/centos/7.6/os/x86_64 # linuxefi boot/centos/7.6/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/7.6/os/x86_64 # linuxefi boot/centos/7.6/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/7.6/os/x86_64 initrdefi boot/centos/7.6/initrd.img } menuentry 'Install CentOS 8.5 via http' { linuxefi boot/centos/8.5/vmlinuz method=http://192.168.0.5/pxeimg/centos/8.5/os/x86_64 # linuxefi boot/centos/8.5/vmlinuz method=nfs://192.168.0.5:/nfs/pxeimg/centos/8.5/os/x86_64 # linuxefi boot/centos/8.5/vmlinuz method=ftp://192.168.0.5:/pxeimg/centos/8.5/os/x86_64 initrdefi boot/centos/8.5/initrd.img } } submenu '02 KickStart Auto Install Menu-->' { menuentry 'Install CentOS 7.6 via http+kickstart' { linuxefi boot/centos/7.6/vmlinuz ks=http://192.168.0.5/kickstart/centos/7.6/ks.cfg # linuxefi boot/centos/7.6/vmlinuz ks=nfs://192.168.0.5:/nfs/kickstart/centos/7.6/ks.cfg # linuxefi boot/centos/7.6/vmlinuz ks=ftp://192.168.0.5:/kickstart/centos/7.6/ks.cfg initrdefi boot/centos/7.6/initrd.img } }