Linux

How to Set Up a PXE Boot Server on Ubuntu

How to Set Up a PXE Boot Server on Ubuntu

Preboot eXecution Environment (PXE) allows networked devices to boot using network resources rather than local storage. It’s commonly used in data centers or environments where operating systems are deployed to multiple machines simultaneously. In this guide, we will walk through the steps to set up a PXE boot server on an Ubuntu system.

Prerequisites
Before setting up a PXE boot server, ensure you have the following:

Ubuntu Server: You need a system running Ubuntu 20.04 or later.
Static IP Address: The server needs a static IP to serve boot requests to other devices.
TFTP Server: PXE uses the Trivial File Transfer Protocol (TFTP) to deliver boot files.
DHCP Server: Required to assign IP addresses to clients requesting a PXE boot.
ISO or Bootable Image: The operating system image you want to deploy.

Step 1: Install Required Packages
Start by updating the package lists and installing the necessary components:

sudo apt update
sudo apt install tftpd-hpa isc-dhcp-server syslinux

  • TFTP: Used to transfer boot files to the client.
  • ISC-DHCP Server: Used to assign IP addresses to PXE clients.
  • Syslinux: Provides the PXE boot loader files.

Step 2: Configure the DHCP Server
The DHCP server is responsible for providing IP addresses to devices requesting to boot via PXE. Open the DHCP configuration file with a text editor:

sudo nano /etc/dhcp/dhcpd.conf

Modify the file to include the following configuration:

subnet 192.168.1.0 netmask 255.255.255.0 {

range 192.168.1.100 192.168.1.200;
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.1.1;
next-server 192.168.1.10; # PXE server’s IP address
filename “pxelinux.0”;
}

next-server: The IP address of your PXE boot server.
filename: The boot loader file used by PXE.
After editing the file, restart the DHCP server:

sudo systemctl restart isc-dhcp-server

Ensure the DHCP server is enabled at boot:

sudo systemctl enable isc-dhcp-server

Step 3: Configure the TFTP Server
TFTP is responsible for delivering the boot files to the client. The tftpd-hpa package should already be installed. Next, edit the TFTP configuration file:

sudo nano /etc/default/tftpd-hpa

Make sure it contains the following settings:

TFTP_USERNAME=”tftp”
TFTP_DIRECTORY=”/var/lib/tftpboot”
TFTP_ADDRESS=”0.0.0.0:69″
TFTP_OPTIONS=”–secure”

This configuration sets up the TFTP service to listen on all interfaces and serve files from the /var/lib/tftpboot directory.

After making the changes, restart the TFTP service:

sudo systemctl restart tftpd-hpa

Enable TFTP to start on boot:

sudo systemctl enable tftpd-hpa

Step 4: Set Up PXE Boot Files
Next, you need to copy the necessary boot files to the TFTP directory. PXE relies on specific boot loader files to function. These can be provided by the Syslinux package, which you installed earlier.

Create the required directories and copy the boot files:

sudo mkdir -p /var/lib/tftpboot/pxelinux.cfg
sudo cp /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/modules/bios/menu.c32 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/modules/bios/libutil.c32 /var/lib/tftpboot/
sudo cp /usr/lib/syslinux/modules/bios/vesamenu.c32 /var/lib/tftpboot/

Next, create a default configuration file for PXE booting:

sudo nano /var/lib/tftpboot/pxelinux.cfg/default

Add the following content:

DEFAULT menu.c32
PROMPT 0
TIMEOUT 100
ONTIMEOUT local
MENU TITLE PXE Boot Menu

LABEL Install Ubuntu
MENU LABEL Install Ubuntu
KERNEL ubuntu-installer/amd64/linux
APPEND initrd=ubuntu-installer/amd64/initrd.gz

This configuration creates a menu that will allow the client to boot Ubuntu using the kernel and initrd files.

Step 5: Add the Bootable Image
To install an operating system via PXE, you need to copy the kernel and initrd image to the TFTP directory. If you’re using an Ubuntu installation ISO, you can mount it and extract the necessary files:

sudo mkdir /mnt/iso
sudo mount -o loop ubuntu-20.04.3-live-server-amd64.iso /mnt/iso
sudo cp /mnt/iso/casper/vmlinuz /var/lib/tftpboot/ubuntu-installer/amd64/linux
sudo cp /mnt/iso/casper/initrd /var/lib/tftpboot/ubuntu-installer/amd64/initrd.gz
sudo umount /mnt/iso

Ensure that the directories and files have the correct permissions:

sudo chmod -R 755 /var/lib/tftpboot

Step 6: Boot Client Machine via PXE
Now that your PXE server is set up, you can boot a client machine from the network. Most modern machines support PXE boot. During boot, enter the machine’s BIOS or UEFI settings and select “Network Boot” or “PXE Boot.”

Once the client machine requests an IP address via DHCP, it will be directed to the PXE server, which will provide the boot loader and necessary files. The Ubuntu installation process should start, and you can proceed with the OS installation.

Troubleshooting

  • Firewall Issues: Ensure that no firewall is blocking DHCP or TFTP traffic. You can disable the firewall for testing purposes or allow UDP traffic on ports 67 (DHCP) and 69 (TFTP).

sudo ufw allow 67/udp
sudo ufw allow 69/udp

  • Permission Issues: If the TFTP server fails to serve files, check the directory permissions. TFTP usually runs as the tftp user, so ensure that this user has access to the /var/lib/tftpboot directory.

PXE Github 

We appreciate your visit to our page! If you’re interested in exploring more articles about Linux systems and Docker Volumes, feel free to explore the links below.

How to Use Docker Volumes for Persistent Storage

Furthermore, by renting a server from our site, you can conduct your tests in a reliable and efficient environment, allowing you to enhance your skills more rapidly. Great job! 🙂

America Location Virtual Dedicated Server

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button