该文章仅介绍基于 UEFI 引导的 DHCP、TFTP 服务器配置和 kickstart 应答文件的特殊配置,基于 BIOS 的常规 PXE 安装服务器配置参见:使用PXE自动化部署Linux系统
1、修改DHCP服务配置文件
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
option domain-name "test.com";
option domain-name-servers 61.139.2.69, 114.114.114.114;
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
default-lease-time 86400;
max-lease-time 172800;
log-facility local7;
subnet 192.168.137.0 netmask 255.255.255.0 {
range 192.168.137.100 192.168.137.200;
option routers 192.168.137.1;
}
# 此处根据不同的引导类型,使用不同的引导文件
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.137.10;
if option architecture-type = 00:07 {
filename "shim.efi";
}
else {
filename "ipxelinux.0";
}
}
2、准备 EFI 文件
[root@localhost ~]# cp -pr /var/www/html/centos7/Packages/shim-x64-15-8.el7.x86_64.rpm /tmp/
[root@localhost ~]# cp -pr /var/www/html/centos7/Packages/grub2-efi-x64-2.02-0.86.el7.centos.x86_64.rpm /tmp/
[root@localhost ~]# cd /tmp
[root@localhost tmp]# rpm2cpio /tmp/shim-x64-15-8.el7.x86_64.rpm | cpio -dimv
[root@localhost tmp]# rpm2cpio /tmp/grub2-efi-x64-2.02-0.86.el7.centos.x86_64.rpm | cpio -dimv
# 将引导文件添加到TFTP目录
[root@localhost tmp]# cp boot/efi/EFI/centos/shim.efi /var/lib/tftpboot/
[root@localhost tmp]# cp boot/efi/EFI/centos/grubx64.efi /var/lib/tftpboot/
3、创建kickstart文件
使用 UEFI 引导安装系统时,在创建 kickstart 文件的时候,除了以下几个参数需要特别注意以外,其他参数和普通 BIOS 引导安装无区别
-
安装前执行的脚本
因为 UEFI 只支持 GPT 分区,因此在安装系统前,需要将硬盘初始化GPT分区 【特别重要】
%pre parted -s /dev/sda mklabel gpt %end
-
清除分区表
该参数可以不配置,因为在执行系统安装前,
parted
命令会将硬盘初始化为 GPT 格式,然后重新分区。如果配置,切记不可使用--all
参数clearpart --initlabel --drives=sda
-
创建EFI分区
part /boot/efi --fstype="efi" --size=200
4、创建grub.cfg文件
[root@localhost ~]# cat /var/lib/tftpboot/grub.cfg
set timeout=60
menuentry 'Auto Install CentOS 7 minimal' {
linuxefi centos7/vmlinuz ip=dhcp ks=http://192.168.137.10/ksfile/centos7_minimal.cfg
inst.repo=http://192.168.137.10/centos7
initrdefi centos7/initrd.img
}
menuentry 'Auto Install CentOS 7 GUI' {
linuxefi centos7/vmlinuz ip=dhcp ks=http://192.168.137.10/ksfile/centos7_gui.cfg
inst.repo=http://192.168.137.10/centos7
initrdefi centos7/initrd.img
}
menuentry 'Manual Install CentOS 7' {
linuxefi centos7/vmlinuz ip=dhcp inst.stage2=http://192.168.137.10/centos7
initrdefi centos7/initrd.img
}
menuentry 'CentOS 7 Rescue' {
linuxefi centos7/vmlinuz ip=dhcp inst.stage2=http://192.168.137.10/centos7 rescue
initrdefi centos7/initrd.img
}
5、重启相关服务
[root@localhost ~]# systemctl restart tftp dhcpd