PXE 安裝需要 httpd 提供安裝源、tftp 提供開機檔、DHCP 指路,三者搭配。
yum install -y httpd xinetd tftp-server
mkdir /var/www/html/centos7
mount -o loop centos7.iso /var/www/html/centos7
cp /var/www/html/centos7/images/pxeboot/{vmlinuz initrd.img} /var/lib/tftpboot/
cp /var/www/html/centos7/isolinux/{vesamenu.c32 boot.msg splash.png} /var/lib/tftpboot/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
把 ks.cfg 放到 /var/www/html/ks.cfg,並修改 /etc/xinetd.d/tftp 把 disable = yes 改為 no。
option domain-name "Robbie.com";
option domain-name-servers 218.2.135.1;
default-lease-time 6000;
max-lease-time 72000;
subnet 192.168.0.0 netmask 255.255.0.0 {
interface eth0;
option routers 192.168.0.1;
next-server 192.168.10.60; # tftp server 的 IP
filename "pxelinux.0"; # PXE 的 bootloader
class "test" {
match if substring (hardware,1,3) = 00:1a:4a;
}
pool {
range 192.168.10.67 192.168.10.70;
allow members of "test";
}
}
這裡用 class 加 pool 限定只有特定 MAC 前綴的機器才會拿到位址,避免影響既有網路。
default vesamenu.c32
timeout 80
display boot.msg
menu clear
menu background splash.png
menu title CentOS 7
menu tabmsg Press Tab for full configuration options on menu items.
label custom
menu label ^Custom auto install
kernel vmlinuz
menu default
append initrd=initrd.img ip=dhcp inst.ks=https://192.168.10.60/ks.cfg
append 這行是重點:ip=dhcp 讓安裝程式自動取址,inst.ks 指向 kickstart 檔位址,實現全自動化安裝。
systemctl start httpd xinetd tftp dhcp
之後把目標主機設為網路開機,就會進入選單並依 ks.cfg 自動完成安裝。