Table of Contents#
- Understanding the PXE Boot Process
- Prerequisites
- Network and Firewall Configuration
- Installing and Configuring the DHCP Server
- Installing and Configuring the TFTP Server
- Setting up the PXE Boot Environment (SYSLINUX)
- Configuring the HTTP Server for Installation Files
- Adding Multiple Linux Distributions
- Creating the PXE Boot Menu
- Testing the PXE Boot Server
- Troubleshooting Common Issues
- Conclusion
- References
1. Understanding the PXE Boot Process#
Before diving into the setup, it's crucial to understand the sequence of events during a PXE boot:
- Client Boots: The client machine is powered on and configured to boot from the network (NIC) in its BIOS/UEFI settings.
- DHCP Request: The client broadcasts a DHCP request on the network.
- DHCP Offer: The PXE server's DHCP service responds with an IP address lease and, critically, the location (
next-server) of the TFTP server and the initial boot file (filename), typicallypxelinux.0. - TFTP Download: The client contacts the TFTP server and downloads the initial bootloader (
pxelinux.0) and its configuration files (likepxelinux.cfg/default). - Boot Menu: The bootloader presents a menu to the user (if configured) based on the downloaded configuration.
- Kernel and Initramfs: The client downloads the Linux kernel (
vmlinuz) and initial RAM disk (initrd.img) for the selected OS via TFTP. - Kernel Execution: The kernel is loaded into memory and starts execution.
- Installation: The kernel fetches the actual installation files (the OS repository) from a web (HTTP), FTP, or NFS server to begin the installation process.
Our setup will use HTTP for serving the installation repositories due to its speed and reliability.
2. Prerequisites#
- A system running RHEL/CentOS 7 with a static IP address (e.g.,
192.168.1.10). - Root or sudo privileges.
- Sufficient disk space to host the ISO files of the Linux distributions you plan to serve (20-30 GB is a good starting point).
- A network environment where you can run a DHCP server without conflict (ideally a isolated lab or a controlled subnet).
3. Network and Firewall Configuration#
Set a static IP address for your server. Edit the network configuration file (replace ens192 with your interface name).
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens192Ensure the configuration looks similar to this:
DEVICE=ens192
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
TYPE=EthernetRestart the network service:
sudo systemctl restart networkConfigure the firewall to allow the required services (DHCP, TFTP, HTTP).
sudo firewall-cmd --permanent --add-service=dhcp
sudo firewall-cmd --permanent --add-service=tftp
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload4. Installing and Configuring the DHCP Server#
Install the DHCP server package.
sudo yum install -y dhcpEdit the DHCP configuration file /etc/dhcp/dhcpd.conf. We will configure it for a specific subnet.
sudo vi /etc/dhcp/dhcpd.confAdd the following configuration, adjusting the subnet, range, and domain to match your network:
# A simple DHCP server configuration for PXE
authoritative;
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 domain-name-servers 8.8.8.8;
option routers 192.168.1.1;
# PXE-specific settings
next-server 192.168.1.10; # IP address of your TFTP server (this machine)
filename "pxelinux.0"; # Initial boot file
}Start and enable the DHCP service.
sudo systemctl start dhcpd
sudo systemctl enable dhcpdImportant Warning: Do not run this DHCP server on a network that already has another DHCP server, as it will cause conflicts.
5. Installing and Configuring the TFTP Server#
The TFTP server is used to serve the initial boot files to the client.
Install the TFTP server and the xinetd super-server that will manage it.
sudo yum install -y tftp-server xinetdConfigure TFTP by editing the xinetd configuration file for TFTP.
sudo vi /etc/xinetd.d/tftpChange the disable and server_args lines to match the following:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot # TFTP root directory
disable = no # Change from 'yes' to 'no'
per_source = 11
cps = 100 2
flags = IPv4
}Start and enable the xinetd service.
sudo systemctl start xinetd
sudo systemctl enable xinetd6. Setting up the PXE Boot Environment (SYSLINUX)#
We will use the SYSLINUX bootloader, specifically the PXELINUX component.
Install the necessary package.
sudo yum install -y syslinux-tftpbootThis package installs the required files into /var/lib/tftpboot/. The key file we referenced in the DHCP configuration is pxelinux.0.
Create the directory structure for the PXE configuration and boot menus.
mkdir -p /var/lib/tftpboot/pxelinux.cfg
mkdir -p /var/lib/tftpboot/imagespxelinux.cfg/: Directory for boot menu configuration files.images/: Directory to store kernel (vmlinuz) and initramfs (initrd.img) files for each OS.
Copy the menu module files for a nicer boot menu.
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/ # More graphical menu7. Configuring the HTTP Server for Installation Files#
We'll use Apache to serve the full installation repositories (the contents of the ISO files).
Install the Apache web server.
sudo yum install -y httpdStart and enable Apache.
sudo systemctl start httpd
sudo systemctl enable httpdCreate a directory to host the OS files. We'll use /var/www/html/os.
mkdir -p /var/www/html/os8. Adding Multiple Linux Distributions#
8.1. Adding CentOS 7#
Download the CentOS 7 ISO or mount the ISO you have.
# If you have the ISO file:
mount -o loop /path/to/CentOS-7-x86_64-DVD-2009.iso /mnt
# Copy the entire contents to the web directory
cp -r /mnt/* /var/www/html/os/centos7/
umount /mntCopy the kernel and initramfs files to the TFTP images directory.
cp /var/www/html/os/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/images/centos7-vmlinuz
cp /var/www/html/os/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/images/centos7-initrd.img8.2. Adding Ubuntu 20.04 LTS#
Download the Ubuntu 20.04 LTS ISO and mount it.
mount -o loop /path/to/ubuntu-20.04.3-live-server-amd64.iso /mnt
mkdir -p /var/www/html/os/ubuntu2004
cp -r /mnt/* /var/www/html/os/ubuntu2004/
umount /mntCopy the kernel and initramfs files. For Ubuntu, they are located in the casper directory.
cp /var/www/html/os/ubuntu2004/casper/vmlinuz /var/lib/tftpboot/images/ubuntu2004-vmlinuz
cp /var/www/html/os/ubuntu2004/casper/initrd /var/lib/tftpboot/images/ubuntu2004-initrd.img9. Creating the PXE Boot Menu#
Now, create the main PXE configuration file. This file is read by the pxelinux.0 bootloader.
sudo vi /var/lib/tftpboot/pxelinux.cfg/defaultAdd the following configuration. This creates a menu with options for CentOS 7, Ubuntu 20.04, and a local boot option.
DEFAULT vesamenu.c32
PROMPT 0
TIMEOUT 100
MENU TITLE PXE Server - Main Menu
LABEL centos7
MENU LABEL Install CentOS 7
KERNEL images/centos7-vmlinuz
APPEND initrd=images/centos7-initrd.img inst.repo=http://192.168.1.10/os/centos7 inst.lang=en_US.UTF-8 inst.keymap=us quiet
LABEL ubuntu2004
MENU LABEL Install Ubuntu 20.04 LTS
KERNEL images/ubuntu2004-vmlinuz
APPEND initrd=images/ubuntu2004-initrd.img root=/dev/rd/0 rw url=http://192.168.1.10/os/ubuntu2004/ubuntu-20.04.3-live-server-amd64.iso automatic-oui=true cloud-config-url=/dev/null quiet
LABEL local
MENU LABEL Boot from Local Drive
LOCALBOOT 0Explanation of key APPEND parameters:
- For CentOS:
inst.repopoints to the HTTP location of the installation files. - For Ubuntu:
urlpoints directly to the ISO file (or the network installer mini ISO can be used for a more efficient setup). Thecloud-config-url=/dev/nullbypasses cloud-init questions.
Set the correct permissions for the TFTP directory.
chown -R nobody: /var/lib/tftpboot
chmod -R 755 /var/lib/tftpboot10. Testing the PXE Boot Server#
- Configure a client machine to boot from the network (PXE) in its BIOS/UEFI settings.
- Power on the client machine. It should receive an IP from your DHCP server.
- You should see the PXE boot menu with the options you configured.
- Select an option (e.g., "Install CentOS 7") and the installation should begin.
11. Troubleshooting Common Issues#
- Client gets no IP address: Check if the DHCP service is running (
systemctl status dhcpd). Ensure there's no other DHCP server on the network. Check firewall rules. - Client gets IP but fails to download
pxelinux.0: Verify thenext-serverandfilenameoptions in/etc/dhcp/dhcpd.conf. Check ifxinetdand the TFTP service are running (systemctl status xinetd). Check the TFTP root directory permissions. - Menu appears but OS installation fails: Check the paths to the
vmlinuzandinitrd.imgfiles in thepxelinux.cfg/defaultfile. Verify that the HTTP server is accessible and the OS files are correctly copied. You can test by trying to accesshttp://192.168.1.10/os/centos7/from another machine on the network. - Use the logs: Check
/var/log/messageson the server for DHCP and general errors. Check/var/log/httpd/error_logfor web server issues.
12. Conclusion#
You have now successfully set up a versatile PXE boot server on RHEL/CentOS 7. This server can dramatically streamline the process of installing Linux on multiple machines. You can easily extend this setup by adding more distributions (like Fedora, Debian, etc.) by following the same pattern: mount the ISO, copy the files to the web directory, and add a new menu entry pointing to the correct kernel and initramfs.
This is a foundational setup. For production environments, you might want to explore more advanced options like Kickstart files for unattended CentOS installations or Preseeds for Ubuntu to achieve full automation.
13. References#
- SYSLINUX Wiki: https://wiki.syslinux.org/wiki/index.php?title=PXELINUX
- RHEL 7 Deployment Guide - PXE: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/chap-installation-server-setup
- Ubuntu Server Guide - Netboot: https://ubuntu.com/server/docs/install/netboot-amd64