LFCS – Understanding PXE Boot

Jarret B

Well-Known Member
Staff member
May 22, 2017
Reaction score
The Preboot Execution Environment (PXE), commonly referred to as 'pixie', is a means to boot from a Network Interface Card (NIC) to the network. Once booted, the Dynamic Host Configuration Protocol (DHCP) Server gives an IP Address to it. Configurations from the DHCP Server will cause the PXE client to contact another server for instructions, in this case a Trivial File Transfer Protocol (TFTP) Server.

In our case, the file downloaded to the client will be a menu. The menu will allow the user to perform an automated install or boot from the local disk, the default option.

We previously set up a client in VirtualBox to perform the PXE booting function from our Server1 machine in VirtualBox.

We have previously set up a DHCP Service on Server1 and an FTP Service. To make this work, we need to add the TFTP Service and change the DHCP Configuration.

NOTE: Otherwise noted, the commands work for CentOS and Ubuntu.

Set Up TFTP and DHCP

So, we need to change our Server1 system to handle PXE booting clients. Our first step is to install a TFTP client and server. We also need SYSLinux.

SYSLinux is a very simplified Bootloader, not as complex as 'GRand Unified Bootloader' (GRUB). There are four types of SYSLinux:

  1. SYSLinux – boot from floppy disks
  2. ISOLinux – booting from a CD/DVD
  3. EXTLinux – boot from a drive formatted as EXT or BRTFS
  4. PXELinux – booting from a network device
In our case, we are using the PXELinux to allow our clients to network boot.

Next, it is necessary to install the TFTP services to Server1 along with the SYSLinux files. The command to install TFTP and SYSLinux is:

sudo yum install tftp tftp-server syslinux -y

For Ubuntu, the command is:

sudo apt install tftp tftp-server syslinux -y

The command installs the TFTP client (tftp), the TFTP Server (tftp-server) and SYSLinux (syslinux) to your server.

The system stores the SYSLinux files under the folder '/usr/share/syslinux/'. There are files located here with the extension 'c32'. The 'c32' files are modules that run in SYSLinux, which we will use the file 'menu.c32'.

For Ubuntu, the files are in '/usr/lib/syslinux/modules/bios'. There are three files you need here: 'menu.c32', 'ldlinux.c32' and 'libutil.c32'. Copy these to the folder '/var/lib/tftpboot'.

Now, we need to configure the DHCP service to send the information for the TFTP server to systems that boot using PXE.

Edit the file '/etc/dhcp/dhcpd.conf', in Ubuntu as well. After the line specifying the 'range' within the 'subnet' section, add the two lines as follows:

filename "pxelinux.0";

Make sure the lines you add are within the brackets of the section. Use the IP Address of your TFTP server in the 'next-server' line. Save and close the file.

The next step is to get the changes active in the service by restarting the service so it loads the updated configuration:

sudo systemctl restart dhcpd

For Ubuntu, the command to restart the DHCP Server is:

sudo systemctl restart isc-dhcp-server

Since we have installed TFTP, it has opened the ports for listening. Ports 67 for the TFTP Server and port 68 for the TFTP Client. To see the ports on UDP that are open for listening, use the command 'netstat -lnu'.

Set Up TFTP Share

When the system installs TFTP, there is a default folder at '/var/lib/tftpboot'. The folder is empty. We need to copy the files into it so the PXE client has the required files to boot.

The system will send the files we place into the folder to the client system. The client will use these files to boot the system from the network server.

There are four files that we need to place into the TFTP shared folder. The files are:

  1. pxelinux.0SYSLinux for PXE systems
  2. menu.c32Menu to display to the user
  3. vmlinuzLinux Kernel
  4. initrd.imgInitialization RamDisk file
Let's start with the first two files, which are in the SYSLinux folder. Use the following commands to change into the destination folder, then copy over the two files:

cd /var/lib/tftpboot
sudo cp /usr/share/syslinux/pxelinux.0 .
sudo cp /usr/share/syslinux/menu.c32 .
sudo cp /var/ftp/CentOS/isolinux/vmlinuz .
sudo cp /var/ftp/CentOS/isolinux/initrd.img .

We copied the files, 'vmlinuz' and 'initrd.img', to the FTP server previously. The location may vary, depending on what folder you placed the files into when setting up the FTP Server. As you can see, we are taking the files from the ISOLinux folder, where the files are located to create a bootable disk for SYSLinux.

For Ubuntu, there are more files already, but we need to get the 'pxelinux.0', 'initrd.gz' and 'linux' which you can download at ' http://archive.ubuntu.com/ubuntu/di...urrent/images/netboot/ubuntu-installer/amd64/'. Download the files and place them into the folder '/var/lib/tftpboot'. Do not rename them and change the permissions to '644'.

For the FTP Server for Ubuntu, I download the ISO for the Desktop installation. I created a folder in the FTP folder, '/srv/ftp', called 'PXE'. Within this folder, I created a folder called Desktop. I extracted the ISO from the 'Desktop' folder. You could download the Server ISO and place it in a folder named 'Server'. This could allow you to install both Desktop and Server versions. Just be aware of the folder structure for later when setting the location to the files.

Once it copies the files over that we need the TFTP Server to share, we can start the TFTP service and enable it to auto-start when the server starts:

sudo systemctl start tftp.socket
sudo systemctl enable tftp.socket

Since the service is now running, the server is listening on port 69 as shown with the command 'netstat -lnu'. It shows the port as Ipv6, but this also applies to Ipv4.

Setting Up the PXE Menu

When a client connects to the TFTP Server, it can load SYSLinux, but a user will prefer a boot menu to choose an option of what to do. We already copied over the file 'menu.c32', we just need to configure the menu that will appear.

Let's start by opening the folder '/var/lib/tftpboot' in a terminal. Create a folder named 'pxelinux.cfg' and switch into it. We need to create a default file named 'default'. Create and edit the file, entering the following lines:

default menu.c32
prompt 0
timeout 300
ontimeout internaldrive
menu title PXE Boot Menu

label internaldrive
menu label Boot from internal drive
localboot 0

In the terminal, go back to the folder '/var/lib/tftpboot' and perform the command 'sudo chmod 777 *'. The command will give full permissions to all the files within the 'tftpboot' folder. Otherwise, your PXE client will get an error that there as no boot filename received.

You should start a PXE client to verify that the client receives an IP Address from the DHCP Server. The client will also receive the address of the TFTP Server and once all of this works, a menu should appear like in Figure 1.

Figure 1.JPG


You may need to set the 'Host-Only Adapter' as 'Adapter 1' since it is the PXE adapter, it should be the primary Network Interface Card. Also, be sure it is set to an adapter that has DHCP disabled within VirtualBox.

Adding Menu Options

So, now we know that the TFTP Server is working as well as the menu. We can now add more menu options to the SYSLinux menu.

Let's look at the previous menu we set up and look at what it all means.

default menu.c32
prompt 0
timeout 300
ontimeout internaldrive
menu title PXE Boot Menu

label internaldrive
menu label Boot from internal drive
localboot 0

The first line, 'default menu.c32', lets SYSLinux know we are looking a text menu. You can easily see that Figure 1 is a text menu and not a graphical menu.

Line 2, 'prompt 0', signifies that there will be no 'boot:' prompt on the screen at the bottom of the screen. If there isn't a prompt, you can get one by pressing the Escape key.

The 'timeout 300' line sets the time to count before accepting the default menu entry. It gives the value in tenths of a second. So 300 is 30 seconds.

The next line, 'ontimeout internaldrive' specifies the name of the default entry that is used if the menu times out. Here, the label is 'internaldrive'.

You can set the menu title with the statement 'menu title' followed by the name you want at the top of the menu, as shown in Figure 1.

The next line that isn't blank sets an entry on the menu. We use the entry named 'internaldrive', as we noticed in the 'ontimeout' line.

The second to last line shows the label displayed on the screen for the entry. Here, what follows 'menu label'. So the menu displays 'Boot from internal drive'.

The last line signifies that the system will perform a local boot from the first drive, or drive 0.

We've placed the kernel and other necessary files on the TFTP Server for a client to boot and install CentOS. Let's make a second entry on the menu to cause a system to load the CentOS installation media.

The line added to 'default' is:

label installation
menu label Install CentOS
kernel vmlinuz
append initrd=initrd.img ip=dhcp repo=

For Ubuntu, the section is as follows:

label installation
menu label Install Ubuntu Desktop
kernel linux
append initrd=initrd.gz ip=dhcp repo=

We set another entry called 'installation'. The menu entry will read 'Install CentOS'. At boot, the client will load the kernel in a file name 'vmlinuz', or 'linux' for Ubuntu. The 'initrd' or RamDisk loads from the FTP server at the appointed location. Make sure you set the location properly. The IP Address is being received from a DHCP Server after the system loads the kernel and RamDisk. Be sure to set the IP Address of the FTP Server and the CentOS folder is the proper name. It is case-sensitive.

Once it loads the new entry, see Figure 2, you can choose the entry. The client should load 'vmlinuz' or 'linux', which is noted at the bottom of the screen as it loads. Then a line will show that the 'initrd.img' or 'initrd.gz' is being loaded. The 'initrd.img' file may take a little longer to load, but then the system will appear as if it were booting from a bootable CD or USB and starting up the CentOS installation.

Figure 2.JPG


There is a good listing of all the commands you can use to use in the 'default' file when making a menu at 'https://wiki.syslinux.org/wiki/inde...onfiguration file : DEFAULT menu.c32 PROMPT 0'.

This should all work now. The system uses the 'default' file for all PXE clients that connect to the TFTP Server. What if you wanted a special menu for specific clients?

Specific Clients

To make a special 'default' file for specific clients, we need to get the MAC Address of the client that we need to create a special menu. On an actual system, you can get this off the NIC itself. MAC Addresses are printed on the card itself. On some systems, you can get the MAC Address in the BIOS.

In my case, the MAC Address of my client system is '080027E613AF'. The letters must be lower-case and each two characters separated with a comma. As an example, a MAC Address would be '08-00-27-e6-13-af' and since we are using an Ethernet connection, we need to prefix the MAC Address with a '01' to designate Ethernet. We use then, '01-08-00-27-e6-13-af'. You can also name the file the GUID of a system.

NOTE: The MAC Address, and GUID, appear at the beginning of the PXE boot process, as shown in Figure 3.

Figure 3.JPG


I set up a special menu for the previous MAC Address for Server3, and you can see it in Figure 4.

Figure 4.JPG


Automatic Install

We can set a system to install CentOS without our intervention. The first thing I did was change the menu for 'Server3' to include an 'automatic' option, as seen in Figure 5.

Figure 5.JPG


The menu file for the MAC Address is:

default menu.c32
prompt 0
timeout 300
ontimeout local
menu title Boot Menu for Server3

label local
menu label Boot from Server3's internal drive
localboot 0

label installation
menu label Install CentOS to Server3
kernel vmlinuz
append initrd=initrd.img ip=dhcp repo=

label autoinstallation
menu label Automatically Install CentOS to Server3
kernel vmlinuz
append initrd=initrd.img ip=dhcp ks=

The item being changed for the third entry is the 'repo' is now 'ks' and the location points to a file named 'install.ks'. The file is a KickStarter file. You can find it in the ROOT folder and is called 'anaconda-ks.cfg'. The system creates it when you install Linux on it.

NOTE: For Ubuntu, install 'system-config-kickstarter' and use it to create the 'ks' file.

You'll need to copy the file to the root of the folder on the FTP Server where CentOS is located. You'll need to be in a terminal as ROOT and switch to the '/ROOT' folder. Then run:

cp anaconda-ks.cfg /var/ftp/CentOS/install.ks
chown ftp:ftp /var/ftp/CentOS/install.ks
chmod 644 /var/ftp/CentOS/install.ks

Once the 'install.ks' file is ready, you need to make the contents look like the following (change the highlighted lines):

# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
url --url=""
# Use graphical install
# Run the Setup Agent on first boot
firstboot --disable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network --bootproto=dhcp --device=enp0s3 --ipv6=auto --activate
# network --bootproto=dhcp --device=enp0s8 --onboot=off --ipv6=auto --activate
network --hostname=server3.example.com

# Root password
rootpw --iscrypted $6$Rzf.olTCBghYYGvD$cfUpL1RUg3z2FhlVyCtkn4bjf8VF8c0r9P303FEr6UbZMleb5pTxpl4deQ8hWwsXuBmhEyZzTa46bEgoqfgBo/
# System services
services --disabled="chronyd"
# System timezone
timezone America/Indiana/Indianapolis --isUtc --nontp
user --groups=wheel --name=jarret -password=$6$M8si/rUYbCjtcGwZ$wjYIBERlkrn0lQiVxokHG5q2eZ9aRcbkgDRBYl6cKFSEJgizVKJE4XGhGPBjZ7zwwOybSfut1cF4g3YK5GIMd1 -iscrypted --gecos="Jarret"
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
repo --name=server1 --baseurl=""
%addon com_redhat_kdump --disable --reserve-mb='auto'

Since the default on the menu is to boot from the local drive, a system will not perform an installation if it accidentally boots in PXE mode. Once a system has had the Operating System installed, it does not need to do it again. We can disable PXE at this point on the clients.


Using PXE with an automated install can help make installing a large group of systems easier.

Be sure you know how to perform the PXE installation if you are taking the LFCS or Red Hat certification exams.

Members online