Diskless Linux Boot via PXE + NFS (Ubuntu / Rocky / Red Hat)
In data centers, cluster environments, educational labs, or large-scale node deployments, Diskless Boot is a common and efficient way to start systems. By combining PXE (Preboot eXecution Environment) with an NFS root filesystem (rootfs), clients can boot Linux without a local disk. This not only reduces hardware costs but also facilitates centralized management and unified system updates.
This article introduces how to use PXE + NFS to provide diskless boot capabilities for Ubuntu, Rocky Linux, and Red Hat Enterprise Linux, covering necessary service configurations, root filesystem preparation, and the client boot process.
1. Architecture (PXE + NFS)
Diskless booting involves three key stages:
1.1 DHCP Stage: Boot Information Delivery
The DHCP server returns the following to the client:
- TFTP Server Address (next-server)
- Boot Filename (pxelinux.0 or shim/grubx64.efi)
1.2 TFTP Stage: Loading Kernel and initramfs
The client downloads:
- Linux Kernel (vmlinuz)
- initramfs (initrd.img)
- Bootloader (pxelinux/grub)
1.3 NFS Stage: Mounting Root Filesystem
Scripts inside initramfs execute:
- Mount the NFS root filesystem
- Switch to the root filesystem and start the OS
Architecture Diagram:
[PXE Client] → DHCP Server → TFTP Server → Kernel/initrd → NFS Root2. Environment Example
Using a single server as the unified PXE + NFS provider:
| Component | Example |
|---|---|
| PXE/NFS Server | 10.0.0.1 |
| Client | DHCP Auto-assigned |
| Linux Distro | Ubuntu / Rocky / RHEL |
Directory Structure:
/srv/tftpboot/ # TFTP files
/srv/nfsroot/ubuntu # Rootfs for each distro
/srv/nfsroot/rocky
/srv/nfsroot/rhel3. Configure DHCP (ISC DHCP / dnsmasq)
3.1 Using dnsmasq (Recommended)
Suitable for lightweight PXE environments.
Install:
sudo apt install dnsmasqConfigure /etc/dnsmasq.conf:
port=0
dhcp-range=10.0.0.50,10.0.0.150,12h
# PXE boot file
dhcp-boot=pxelinux.0,pxeserver,10.0.0.1
# TFTP Service
enable-tftp
tftp-root=/srv/tftpbootRestart:
sudo systemctl restart dnsmasq4. Configure TFTP and Prepare PXE Boot Files
Install TFTP Service:
sudo apt install tftpd-hpa pxelinux syslinux-commonEnsure directories exist:
sudo mkdir -p /srv/tftpboot/pxelinux.cfgCopy boot files:
cp /usr/lib/PXELINUX/pxelinux.0 /srv/tftpboot/
cp /usr/lib/syslinux/modules/bios/* /srv/tftpboot/5. Prepare Kernel and initramfs
For Ubuntu:
mkdir -p /srv/tftpboot/ubuntu
cp /boot/vmlinuz-$(uname -r) /srv/tftpboot/ubuntu/
cp /boot/initrd.img-$(uname -r) /srv/tftpboot/ubuntu/For RHEL/Rocky:
cp /boot/vmlinuz-<version> /srv/tftpboot/rocky/
cp /boot/initramfs-<version>.img /srv/tftpboot/rocky/6. Configure NFS Service
Install NFS:
sudo apt install nfs-kernel-serverExport Root Directories:
/srv/nfsroot/ubuntu *(rw,no_root_squash,no_subtree_check)
/srv/nfsroot/rocky *(rw,no_root_squash,no_subtree_check)
/srv/nfsroot/rhel *(rw,no_root_squash,no_subtree_check)Apply Configuration:
sudo exportfs -a7. Build Diskless Root Filesystem (rootfs)
7.1 Ubuntu (via debootstrap)
sudo debootstrap focal /srv/nfsroot/ubuntu http://archive.ubuntu.com/ubuntu/Required Configuration:
echo "ubuntu-client" > /srv/nfsroot/ubuntu/etc/hostname
echo "127.0.1.1 ubuntu-client" >> /srv/nfsroot/ubuntu/etc/hosts7.2 Rocky / RHEL (via dnf --installroot)
sudo dnf --releasever=9 --installroot=/srv/nfsroot/rocky groupinstall "Minimal Install"8. Configure PXE Boot Menu
Edit /srv/tftpboot/pxelinux.cfg/default:
DEFAULT menu.c32
PROMPT 0
TIMEOUT 50
LABEL Ubuntu Diskless
KERNEL ubuntu/vmlinuz
APPEND initrd=ubuntu/initrd.img root=/dev/nfs ip=dhcp nfsroot=10.0.0.1:/srv/nfsroot/ubuntu rw
LABEL Rocky Diskless
KERNEL rocky/vmlinuz
APPEND initrd=rocky/initramfs.img root=/dev/nfs ip=dhcp nfsroot=10.0.0.1:/srv/nfsroot/rocky rw9. Client Boot Verification
Enable PXE in BIOS/UEFI:
- Intel: Network Boot
- ARM: PXE over IPv4
Boot Process:
- DHCP acquires IP.
- pxelinux.0 is downloaded via TFTP.
- Kernel and initrd are loaded.
- NFS root is mounted.
- System entry.
Verify via Server Logs:
DHCP:
journalctl -u dnsmasqNFS:
journalctl -u nfs-server10. Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| PXE-T01: File not found | TFTP path error | Check tftp-root and filenames. |
| Kernel panic: unable to mount rootfs | NFS config error | Verify nfsroot params and exportfs settings. |
| DHCP Timeout | DHCP service invalid | Disable other DHCP servers, check firewall. |
11. Summary
Using PXE + NFS for diskless Linux booting significantly reduces node costs, improves environment consistency, and simplifies batch deployment. The examples in this article are based on Ubuntu, Rocky, and Red Hat, but other distributions can be implemented in a similar manner.
