Booting Linux (Debian Bookworm) with PXE using NFS root filesystem
In this article, we will discuss the process of booting Linux (Debian Bookworm) using PXE (Preboot Execution Environment) and an NFS (Network File System) root filesystem. This method is particularly useful in situations where you want to automate the installation and configuration of multiple machines, or when you want to create a thin client environment.
Prerequisites
Before we begin, it is assumed that you have a basic understanding of Linux and networking concepts. Additionally, you will need the following:
- A DHCP (Dynamic Host Configuration Protocol) server
- A TFTP (Trivial File Transfer Protocol) server
- An NFS server
- A Linux machine with PXE boot capabilities.
DHCP Configuration
To begin, we need to configure our DHCP server to provide the necessary information to our PXE boot client. This includes the location of the PXE bootloader and the IP address of the NFS server.
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
option domain-name-servers 192.168.1.2;
filename "pxelinux.0";
next-server 192.168.1.2;
}
In the above configuration, we specify the filename of the PXE bootloader (pxelinux.0) and the IP address of the TFTP server (next-server). We also specify the location of the DHCP server (option routers) and the DNS server (option domain-name-servers). The range directive specifies the IP addresses that will be assigned to the PXE boot clients.
TFTP Configuration
Next, we need to configure our TFTP server to serve the PXE bootloader. In our case, we will use the pxelinux.0 bootloader provided by the Syslinux project.
[pxelinux]
basedir=/srv/tftpboot
In the above configuration, we specify the location of the pxelinux.0 bootloader. This is typically located in the /srv/tftpboot directory. We also need to copy the necessary Syslinux configuration files and modules to this directory.
NFS Configuration
Finally, we need to configure our NFS server to serve the root filesystem. In our case, we will use the Debian Bookworm distribution.
/srv/nfs/debian-bookworm
{
rw,sync,no_root_squash,no_all_squash;
}
In the above configuration, we specify the location of the Debian Bookworm distribution (/srv/nfs/debian-bookworm) and the necessary NFS options. The rw option allows the client to read and write to the filesystem. The sync option ensures that data is immediately written to the filesystem. The no\_root\_squash option allows the client to access the filesystem as root. The no\_all\_squash option disables all squashing, which allows the client to access all of the files and directories on the NFS server.
PXE Boot Configuration
Now that we have configured our DHCP, TFTP, and NFS servers, we can move on to configuring the PXE bootloader. We will use the pxelinux.0 bootloader provided by the Syslinux project.
DEFAULT vmlinuz-5.10.0-amd64
LABEL linux
MENU LABEL Debian Bookworm
LINUX vmlinuz-5.10.0-amd64
INITRD initrd.img-5.10.0-amd64
APPEND root=/dev/nfs nfsroot=192.168.1.2:/srv/nfs/debian-bookworm ip=dhcp rw
In the above configuration, we specify the location of the Linux kernel (vmlinuz-5.10.0-amd64) and the initial ramdisk (initrd.img-5.10.0-amd64). We also specify the necessary kernel command line options. The root option specifies the root filesystem as an NFS mount. The nfsroot option specifies the location of the NFS server and the root filesystem. The ip option specifies that the IP address should be obtained via DHCP. The rw option specifies that the root filesystem should be mounted as read-write.
Testing
Now that we have everything configured, we can test the PXE boot process. First, we need to configure our PXE boot client to boot from the network. This can typically be done by entering the boot menu and selecting the network boot option. Once the client has booted, it should automatically download the PXE bootloader and the Linux kernel. It should then mount the root filesystem via NFS and complete the boot process.
- PXE booting allows you to boot a Linux system from the network
- NFS allows you to serve a root filesystem over the network
- DHCP provides the necessary network configuration information to the PXE boot client
- TFTP serves the PXE bootloader to the PXE boot client