Setting Up a PXE Boot Server on CentOS Stream 9 with TFTP, DHCP, and Kickstart for Mass OS Deployment

CentOS tutorial - IT technology blog
CentOS tutorial - IT technology blog

The Nightmare of Plugging in USB Drives One Machine at a Time

When CentOS 8 reached end-of-life (EOL), I had to urgently migrate 5 servers to Rocky Linux in just one week. Running around the server room with a USB drive, plugging in a monitor, and typing through the Anaconda installer line by line was exhausting. Just 5 machines took half a day—and if you mistyped a hostname or forgot to select LVM, you had to start all over again.

After that ordeal, my team decided to build a PXE Boot Server on CentOS Stream 9 to install operating systems over the network. This setup has been running reliably in production for over 6 months, provisioning more than 30 bare-metal nodes as well as VMware/KVM virtual machines. Below is our exact working configuration along with a few real-world pitfalls to avoid.

How Do PXE, TFTP, DHCP, and Kickstart Work Together?

It sounds like a lot of services at first, but the PXE Boot workflow is actually quite clean. You can picture it as 4 sequential steps:

  • PXE (Preboot Execution Environment): A built-in feature on network interface cards (NICs) that allows a computer to boot directly from the LAN instead of a hard drive or USB stick.
  • DHCP Server: When a client powers on and selects network boot, it sends a broadcast packet requesting an IP. The DHCP server assigns a temporary IP (for example, from the 192.168.100.100–200 range), along with the TFTP server’s IP (next-server) and the boot file name to download (filename).
  • TFTP Server: A lightweight file transfer protocol running on UDP port 69 with no authentication required. The client uses TFTP to fetch the bootloader (pxelinux.0 for BIOS or grubx64.efi for UEFI), the kernel (vmlinuz), and the RAM disk (initrd.img).
  • HTTP Server & Kickstart: TFTP is way too slow for transferring an 8–10 GB ISO image. Therefore, once the kernel is loaded into RAM, the installer switches to HTTP to pull the installation packages and the Kickstart file (ks.cfg). This file pre-populates every answer for the installer: disk partitioning, time zone, root password, and package list.

Pro tip: If your server room has a mix of older servers (Legacy BIOS) and newer ones (UEFI), you should configure DHCP to branch based on the client architecture code (option architecture-type, code 93). In this guide, I’m using the Legacy BIOS flow (pxelinux.0) since it’s quick and easy to test on both VMs and standard physical servers.

Step-by-Step: Building a PXE Boot Server on CentOS Stream 9

Both my lab and production environments follow the same convention: the PXE Server runs CentOS Stream 9 with a static IP of 192.168.100.10/24, serving DHCP leases from 192.168.100.100 to 192.168.100.200 on a dedicated provisioning VLAN.

Step 1: Install Required Services and Prepare the ISO

Install the full set of packages, including DHCP, TFTP, Syslinux (which provides the PXE bootloader), Apache HTTP, and the Kickstart syntax validator:

sudo dnf install -y dhcp-server tftp-server syslinux httpd pykickstart

Mount the ISO image and copy all its contents to the web root. Be sure to use a trailing dot /mnt/iso/. instead of /mnt/iso/* so you don’t miss the hidden .treeinfo and .discinfo files—without them, Anaconda won’t automatically detect the BaseOS and AppStream repositories:

sudo mkdir -p /mnt/iso /var/www/html/os
sudo mount -o loop /root/CentOS-Stream-9-latest-x86_64-dvd1.iso /mnt/iso
sudo cp -av /mnt/iso/. /var/www/html/os/
sudo umount /mnt/iso

Copy the kernel vmlinuz, initrd.img, and the Syslinux bootloader files into the TFTP root directory (/var/lib/tftpboot):

sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg
sudo cp /usr/share/syslinux/{pxelinux.0,ldlinux.c32,menu.c32,libutil.c32} /var/lib/tftpboot/
sudo cp /var/www/html/os/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/

Step 2: Configure the DHCP Server

Edit /etc/dhcp/dhcpd.conf as shown below. The two parameters that determine whether a client can find the PXE Server are next-server and filename:

sudo tee /etc/dhcp/dhcpd.conf <<'EOF'
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;

subnet 192.168.100.0 netmask 255.255.255.0 {
    range 192.168.100.100 192.168.100.200;
    option routers 192.168.100.1;
    option domain-name-servers 8.8.8.8, 1.1.1.1;
    next-server 192.168.100.10;
    filename "pxelinux.0";
}
EOF

Step 3: Create the PXE Boot Menu

Create /var/lib/tftpboot/pxelinux.cfg/default to display the OS selection menu. One mandatory rule for production: always set MENU DEFAULT to boot from the local hard drive. That way, if a server reboots in the middle of the night and accidentally boots via NIC, it won’t wipe and reinstall itself after the 10-second timeout (TIMEOUT 100):

sudo tee /var/lib/tftpboot/pxelinux.cfg/default <<'EOF'
DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
MENU TITLE === AUTOMATED INSTALLATION SYSTEM (PXE BOOT) ===

LABEL local
    MENU LABEL ^1. Boot from local drive (Default)
    MENU DEFAULT
    LOCALBOOT 0

LABEL centos9_auto
    MENU LABEL ^2. Automated CentOS Stream 9 installation (Kickstart)
    KERNEL vmlinuz
    APPEND initrd=initrd.img inst.repo=http://192.168.100.10/os inst.ks=http://192.168.100.10/ks.cfg ip=dhcp
EOF

Step 4: Write the Kickstart Script (ks.cfg)

Everything from disk partitioning and password setup to extra package installation lives in this file. First, generate a SHA-512 hash for the root password:

openssl passwd -6 'SuperSecurePassword@2026'

Create /var/www/html/ks.cfg and paste the generated hash into the rootpw --iscrypted line:

sudo tee /var/www/html/ks.cfg <<'EOF'
#version=RHEL9
text
url --url="http://192.168.100.10/os"
lang en_US.UTF-8
keyboard us
timezone Asia/Ho_Chi_Minh --utc
network --bootproto=dhcp --device=link --activate
rootpw --iscrypted $6$replace_with_your_hash_string
selinux --enforcing
firewall --enabled --service=ssh
bootloader --location=mbr
clearpart --all --initlabel
autopart --type=lvm
reboot

%packages
@^minimal-environment
vim
curl
bash-completion
%end

%post
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIExampleKey admin@itfromzero" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
%end
EOF

Don’t forget to run ksvalidator to check for syntax errors before deploying to real hardware—a single misplaced space can halt the installation midway:

ksvalidator /var/www/html/ks.cfg

Step 5: Set Permissions, Open Firewall Ports, and Start Services

Grant read permissions for Apache, restore SELinux contexts, open the required ports, and enable all three services at once:

sudo chmod 644 /var/www/html/ks.cfg
sudo restorecon -Rv /var/www/html /var/lib/tftpboot
sudo firewall-cmd --permanent --add-service={dhcp,tftp,http}
sudo firewall-cmd --reload
sudo systemctl enable --now dhcpd tftp.socket httpd

Now you can power on a blank machine in the same VLAN, select network boot (F12 or PXE in BIOS), and choose option 2. Over a 1 Gbps internal network, the entire process—from partitioning disks and installing packages to injecting the SSH key—takes about 5–7 minutes before the machine automatically reboots to the login prompt.

6-Month Production Review

After half a year in operation, the PXE Boot Server has cut the time required to spin up a new node from 40 minutes of manual clicking down to roughly 6 minutes of unattended installation. More importantly, 100% of newly provisioned servers come out completely consistent in terms of LVM partitioning, package versions, and SSH configuration.

If you deploy this setup on a corporate network, make sure to stick to two strict safety rules. First, isolate the provisioning VLAN so the PXE DHCP server doesn’t accidentally hand out IPs to office laptops. Second, keep the local hard drive boot option as the default in the PXE menu to prevent accidental data loss when servers reboot.

Share: