PXE (Preboot Execution Environment) 由 Intel 定義,讓電腦透過網路載入開機載入器、核心、根檔案系統,實現無光碟/無 USB 安裝。
next-server (TFTP 伺服器)、filename (開機載入器路徑,如 pxelinux.0/grubx64.efi)pxelinux.0、vmlinuz、initrd.img、選單配置
BIOS/UEFI PXE ROM
↓ DHCP Discover/Offer/Request/ACK
取得 IP、next-server、filename
↓ TFTP 下載 filename (pxelinux.0 / grubx64.efi)
↓ 載入器讀取選單配置 (pxelinux.cfg/default / grub.cfg)
↓ TFTP/HTTP 下載 vmlinuz + initrd.img
↓ 核心啟動,掛載 initrd,啟動安裝程式 (Anaconda/Debian Installer/Calamares)
↓ 讀取 Kickstart/Preseed/Autoyast 自動應答
↓ HTTP/NFS 下載套件安裝
↓ 寫入 GRUB、重啟
dnf install -y dhcp-server tftp-server syslinux httpd nfs-utils
# UEFI 需額外
dnf install -y grub2-efi-x64 shim-x64
# /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot -v
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
systemctl enable --now xinetd
systemctl enable --now tftp.socket # systemd 方式
# BIOS (SYSLINUX)
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/{menu.c32,vesamenu.c32,libutil.c32,libcom32.c32} /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
# UEFI (GRUB)
cp /boot/efi/EFI/redhat/grubx64.efi /var/lib/tftpboot/ # 或 shimx64.efi
mkdir -p /var/lib/tftpboot/grub2
# 核心與 initrd (從安裝 ISO 解壓)
mount -o loop Rocky-9-x86_64-dvd.iso /mnt/iso
cp /mnt/iso/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/
cp /mnt/iso/isolinux/*.msg /var/lib/tftpboot/ 2>/dev/null || true
BIOS: /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu.c32
PROMPT 0
TIMEOUT 300
MENU TITLE PXE Boot Menu
LABEL linux
MENU LABEL ^Install Rocky Linux 9
KERNEL vmlinuz
APPEND initrd=initrd.img inst.stage2=https://192.168.1.100/rocky9 ks=https://192.168.1.100/ks/rocky9.cfg ip=dhcp
LABEL rescue
MENU LABEL ^Rescue Mode
KERNEL vmlinuz
APPEND initrd=initrd.img inst.stage2=https://192.168.1.100/rocky9 rescue
UEFI: /var/lib/tftpboot/grub2/grub.cfg
set timeout=30
menuentry 'Install Rocky Linux 9' {
linuxefi /vmlinuz inst.stage2=https://192.168.1.100/rocky9 ks=https://192.168.1.100/ks/rocky9.cfg ip=dhcp
initrdefi /initrd.img
}
menuentry 'Rescue Mode' {
linuxefi /vmlinuz inst.stage2=https://192.168.1.100/rocky9 rescue
initrdefi /initrd.img
}
# /etc/dhcp/dhcpd.conf
authoritative;
ddns-update-style none;
option domain-name-servers 192.168.1.1, 8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
option broadcast-address 192.168.1.255;
# BIOS PXE
class "pxeclients" {
match if substring(option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 192.168.1.10;
filename "pxelinux.0";
}
# UEFI PXE (架構代碼 0x0007 = x86_64 UEFI)
class "uefi-pxe-64" {
match if substring(option vendor-class-identifier, 0, 20) = "PXEClient:Arch:00007";
filename "grubx64.efi";
}
}
systemctl enable --now dhcpd
# 掛載 ISO 到 HTTP 根目錄
mkdir -p /var/www/html/rocky9
mount -o loop,ro Rocky-9-x86_64-dvd.iso /var/www/html/rocky9
# 或解壓
# 7z x Rocky-9-x86_64-dvd.iso -o/var/www/html/rocky9
# Kickstart 檔案
mkdir -p /var/www/html/ks
cat > /var/www/html/ks/rocky9.cfg <<'EOF'
#version=RHEL9
install
url --url=https://192.168.1.100/rocky9
lang en_US.UTF-8
keyboard us
network --bootproto=dhcp --device=link --activate
rootpw --plaintext RedHat123
firewall --enabled --ssh
authselect --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Asia/Taipei
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto"
zerombr
clearpart --all --initlabel --drives=sda
autopart --type=lvm
reboot
%packages --ignoremissing
@^minimal-environment
%end
%post
# 後安裝腳本
systemctl enable sshd
echo "PXE Auto Install Completed" > /root/install.log
%end
EOF
systemctl enable --now httpd
firewall-cmd --add-service={http,dhcp,tftp} --permanent
firewall-cmd --reload
# /etc/exports
/var/www/html/rocky9 192.168.1.0/24(ro,sync,no_root_squash)
/var/www/html/ks 192.168.1.0/24(ro,sync,no_root_squash)
systemctl enable --now nfs-server
firewall-cmd --add-service=nfs --permanent
firewall-cmd --reload
# Kickstart 中改用
# url --url=nfs://192.168.1.100:/var/www/html/rocky9
# ks=nfs://192.168.1.100:/var/www/html/ks/rocky9.cfg
shimx64.efi 作為 filename (已由 Microsoft 簽名)grubx64.efi 需由發行版簽名 (Red Hat/Fedora/Ubuntu 皆有)| 工具 | 特色 | 適用場景 |
|---|---|---|
| Cobbler | 輕量、CLI/Web、支援 PXE/Kickstart/Preseed/Autoyast、電源管理 | 中小規模、手動維護 |
| Foreman | 完整生命週期、Puppet/Ansible 整合、多租戶、API、Smart Proxy | 企業級、配置管理整合 |
| MAAS (Metal as a Service) | Canonical 開發、硬體發現、IPMI/Redfish、Kubernetes 整合 | 裸機雲、Ubuntu 生態 |