WindowsMacSoftwareSettingsSecurityProductivityLinuxAndroidPerformanceConfigurationApple All

How to Set Up a PXE Boot Server on Linux

Edited 1 day ago by ExtremeHow Editorial Team

Network BootingPXEServer SetupDeploymentConfigurationSysAdminTFTPCommand LineInstallationImaging

How to Set Up a PXE Boot Server on Linux

This content is available in 7 different language

In this guide, we will learn how to set up a Preboot Execution Environment (PXE) boot server on a Linux machine. This process allows a computer to boot using an image provided over the network instead of local storage. PXE is useful for system administrators who need to deploy operating systems or software on multiple machines across a network.

1. Introduction to PXE booting

PXE, which stands for Preboot Execution Environment, enables a computer to boot via a network interface independently of the available data storage device or the installed operating system. It is a great help in automating server deployment and can be used for network installation of Linux OS and other operating systems.

Essentially, PXE consists of two main components:

With a PXE boot server, you can quickly and efficiently install operating systems on multiple machines from a centralized location.

2. Requirements

To set up a PXE boot server on Linux, you will need the following components:

3. Setting up a DHCP server

The DHCP server assigns an IP address to the PXE clients and informs them about the next server to contact for the boot process.

Install the DHCP server using your package manager. If you are using a distribution like Ubuntu or Debian, the command will look like this:

sudo apt-get install isc-dhcp-server

After installation, start by editing the DHCP server configuration file, which is usually located at /etc/dhcp/dhcpd.conf. You will need to set it to specify the PXE client's IP address, subnet mask, and bootloader file details.

Below is a basic configuration snippet:

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.10 192.168.1.100;
    option routers 192.168.1.1;
    filename "pxelinux.0";
    next-server 192.168.1.5; # IP address of your PXE Server
    option broadcast-address 192.168.1.255;
}

Once configured, restart the DHCP service to apply the changes:

sudo systemctl restart isc-dhcp-server

Make sure the DHCP server starts at boot:

sudo systemctl enable isc-dhcp-server

4. Installing the TFTP server

The TFTP (Trivial File Transfer Protocol) server delivers the bootloader to the PXE client. Install it using the following:

sudo apt-get install tftpd-hpa

Edit the TFTP configuration file at /etc/default/tftpd-hpa to make sure it is properly set up to serve your boot files:

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure"

Make sure the specified directory (by default /var/lib/tftpboot) is created and can be accessed. Restart and enable the TFTP service:

sudo systemctl restart tftpd-hpa
sudo systemctl enable tftpd-hpa

5. Configuring the boot loader

SYSLINUX provides a PXE bootloader called pxelinux. First, install syslinux if it isn't already installed:

sudo apt-get install syslinux-common

Copy the required files to the tftpboot directory:

sudo cp /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftpboot
sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg

To provide a boot menu, you must create a configuration file in /var/lib/tftpboot/pxelinux.cfg. Create a file named default:

DEFAULT menu.c32
PROMPT 0
TIMEOUT 50
ONTIMEOUT local
LABEL linux
    MENU LABEL ^Install Linux
    KERNEL vmlinuz
    APPEND initrd=initrd.img

This configuration gives a boot menu for selecting a network bootable image, such as Linux.

6. Prepare the boot kernel and initrd

Copy the kernel and initrd files from your Linux installation media to the /var/lib/tftpboot directory:

sudo cp /path-to-linux-iso/vmlinuz /var/lib/tftpboot/
sudo cp /path-to-linux-iso/initrd.img /var/lib/tftpboot/

Make sure the permissions are correct:

sudo chmod 644 /var/lib/tftpboot/*

7. Configuring NFS or HTTP

You must host the actual installation files using either NFS or HTTP. Each method is appropriate depending on your network requirements.

For NFS:

Install the NFS server:

sudo apt-get install nfs-kernel-server

Edit the export file /etc/exports to include the directory containing your installation files:

/path-to-your-linux-files 192.168.1.0/24(ro,sync,no_root_squash)

Restart the NFS services:

sudo exportfs -a
sudo systemctl restart nfs-kernel-server

For HTTP:

Install an HTTP server like Apache:

sudo apt-get install apache2

Link your installation media to a web-accessible directory:

sudo ln -s /path-to-your-linux-files /var/www/html/linux

Restart Apache:

sudo systemctl restart apache2

Make sure your firewall allows NFS/HTTP ports:

sudo ufw allow 2049
sudo ufw allow 80

8. Boot up your PXE clients

Finally, configure your client to boot from the network. You usually set this in the BIOS or UEFI firmware settings. Once the PXE client boots, it will connect to your network and get an IP from the DHCP server. It then loads the bootloader file from your TFTP server and begins the installation process using the files provided by NFS/HTTP.

By following the steps above, you will have successfully set up a PXE boot server that your network machines can use to load operating systems over the network.

If you find anything wrong with the article content, you can


Comments