Rebuilding a PXE boot server with AlmaLinux

With the impending doom of CentOS, I figured now would be a great time to update the series of blog posts created in 2020 regarding building a PXE boot server, but for AlmaLinux.

This series of posts will be about rebuilding this server with AlmaLinux.
The main things I want to accomplish are:
– Rebuild the server with AlmaLinux
– Replicate the previous setup (booting memtest, gparted, clonezilla, etc)
– Replace the CentOS kickstart setup with something similar for AlmaLinux
– PXE boot Windows installations (MDT, unattend.xml, etc)

In this post I’m going to cover initially setting the PXE server up, and booting the AlmaLinux setup.

This post assumes that you’ve already downloaded and installed the latest AlmaLinux (8.5 at the time of writing) on a new VM within your environment. As before, here are the details of the VM within my environment:

Server IP: 10.179.1.10
Hostname: COLO-PXE
OS: AlmaLinux 8.5 (Artic Sphynx)
CPU: 4 cores
RAM: 4GB
Hard disk: 128GB (thin provisioned)
Firewalld is disabled, and SELinux is set to Permissive

The VM will be setup with a standard AlmaLinux Minimal install using the AlmaLinux-8.5-x86_64-minimal ISO obtained from the AlmaLinux Mirror List; boot the ISO, run through the setup, select Minimal Install, login at the console once the install has completed and set an IP and hostname, and also install open-vm-tools. Reboot the VM once more and then we can SSH into it.

Install required packages

Once the VM is back online and we’re SSH’d in, we’re going to install the following packages/run the following command:

[root@COLO-PXE ~]# yum -y install tftp-server vsftpd xinetd httpd syslinux wget

As before, we’re not installing DNSMASQ on our VM as our DHCP is handled on our router/firewall in this example.

Populate SYSLINUX bootloaders

Now that we’ve installed our packages, we’re ready to start editing configs and copying files around. To start, we’re going to copy all of the SYSLINUX bootloader files to our tftproot folder with the following commands:

[root@COLO-PXE ~]# cp -v /usr/share/syslinux/{pxelinux.0,menu.c32,mboot.c32,chain.c32,memdisk,ldlinux.c32,libutil.c32,libcom32.c32} /var/lib/tftpboot

Enable and start services

Before we can continue, we need to enable and start the services we just installed:

[root@COLO-PXE ~]# systemctl enable xinetd vsftpd httpd
[root@COLO-PXE ~]# systemctl start xinetd vsftpd httpd

We also need to create a TFTP server config file within /etc/xinetd.d/.
Create and edit the following file: /etc/xinetd.d/tftp:

service tftp
{
disable         = no
socket_type     = dgram
protocol        = udp
wait            = yes
user            = root
server          = /usr/sbin/in.tftpd
server_args     = -s /var/lib/tftpboot
per_source      = 11
cps             = 100 2
flags           = IPv4
}

Copy AlmaLinux files to server

We’re now in a position whereby we can copy our AlmaLinux files and attempt to PXE boot our client. Mount the ISO file used to install the VM originally back to the VMs DVD drive if it’s been unmounted, and verify it’s seen by the OS:

[root@COLO-PXE ~]# blkid | grep AlmaLinux
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-11-11-16-16-25-00" LABEL="AlmaLinux-8-5-x86_64-dvd" TYPE="iso9660" PTUUID="5c6fc0a3" PTTYPE="dos"

Next, we’re going to mount the DVD drive within our OS and verify it’s mounted correctly:

[root@COLO-PXE ~]# mkdir /media/iso
[root@COLO-PXE ~]# mount /dev/sr0 /media/iso
mount: /media/iso: WARNING: device write-protected, mounted read-only.
[root@COLO-PXE ~]# ls /media/iso
BaseOS  EFI  images  isolinux  media.repo  Minimal  TRANS.TBL

Next, we’re going to copy the files from the DVD to our VM.
I want these files to be accessible over both FTP and HTTP, so I’m going to go ahead and create a new directory at the / location for these – /srv/networkboot
Inside this folder, we’re going to create directories for our OS, /srv/networkboot/almalinux/8.5 and copy the contents of the DVD to the above folder:
Finally, we’re going to create a symbolic link for /srv/networkboot/ to /var/www/html

[root@COLO-PXE /]# mkdir -p /srv/networkboot/almalinux/8.5
[root@COLO-PXE /]# cp -av /media/iso/* /srv/networkboot/almalinux/8.5/
[root@COLO-PXE /]# ln -s /srv/networkboot/ /var/www/html

We also need to copy the vmlinuz and initrd.img files from the DVD to the /var/lib/tftpboot folder.
Within the above directory we’re going to create a new directory for the files, following the folder structure above, and then copy them:

[root@COLO-PXE /]# mkdir -p /var/lib/tftpboot/almalinux/8.5
[root@COLO-PXE /]# cp /media/iso/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/almalinux/8.5/
[root@COLO-PXE /]# ls -l /var/lib/tftpboot/almalinux/8.5/
total 87844
-r--r--r-- 1 root root 79740504 Jan  8 20:22 initrd.img
-r-xr-xr-x 1 root root 10211208 Jan  8 20:22 vmlinuz

Next, if we run an ls of the /var/www/html directory we can see the symlink as expected. When browsing to the servers IP within a browser and navigating to /networkboot, we should see our almalinux/8.5 folder containing the ISO content as expected.

[root@COLO-PXE /]# ls -l /var/www/html
total 0
lrwxrwxrwx 1 root root 17 Jan  3 17:16 networkboot -> /srv/networkboot/

For our FTP to work, we need to enable Anonymous Access
Edit the file /etc/vsftpd/vsftpd.conf and change the following:
anonymous_enable=NO to anonymous_enable=YES
local_enable=YES to local_enable=NO

Finally we need to add the following line somewhere within the file:
anon_root=/srv/networkboot/

After making these changes, restart vsftpd and verify all is working as expected.

/etc/vsftpd/vsftpd.conf

Create PXE boot menu file

We now need to create our PXE boot menu. For this, we’re going to add a single option so we can verify our server is working as expected, and once we’ve confirmed this works, we can add more as needed.
To get started, we need to create the pxelinux.cfg directory, and within that, the default file:

[root@COLO-PXE ~]# mkdir /var/lib/tftpboot/pxelinux.cfg 
[root@COLO-PXE ~]# touch /var/lib/tftpboot/pxelinux.cfg/default

Next, we’re going to edit the pxelinux.cfg/default file with a boot menu option so we can verify our server is working as expected.

default menu.c32
prompt 0
timeout 300
ONTIMEOUT localboot
MENU AUTOBOOT Booting from local drive in # seconds

menu title ########## PXE Boot Menu ##########

LABEL Boot AlmaLinux 8.5 x64 with Network Repo
MENU LABEL Boot AlmaLinux 8.5 x64 with Network Repo
KERNEL almalinux/8.5/vmlinuz
APPEND initrd=almalinux/8.5/initrd.img method=ftp://10.179.1.10/almalinux/8.5 devfs=nomount

LABEL localboot
MENU LABEL Boot from local drive
LOCALBOOT 1
COM32 chain.c32
APPEND hd0 0

Configure DHCP/firewall for PXE booting

Finally, we need to configure our router for PXE booting. Within the DHCP settings of our router/firewall we need to edit/enable the following settings:
– TFTP Server
– Next Server
– Default file name
If we’re unable to configure them specific settings, we can also specify DHCP options 66 and 67.

In this example, we’re using PFSense.
On PFSense, we’re going to want to navigate to Services > DHCP Server > <Network name>.
Scroll to the bottom of the page and find TFTP. Click Display Advanced and enter the IP of your PXE server – in this example, 10.179.1.10.
Next, scroll down to Network Booting and click Display Advanced. Tick the checkbox for Enables network booting and enter the IP of your PXE server in the Next Server box.
In the Default BIOS file name box we’re going to enterpxelinux.0 – This is one of the bootloader files we copied right at the beginning.

Tidying up

At this point, we’ve completed our configuration and are ready to start testing.
Before doing anything, we need to tidy up our VM

We’re going to do the following:
– Unmount /media/iso
– Delete /media/iso
– Restart our services (xinetd, vsftpd, httpd)
– Eject AlmaLinux DVD from our VMs DVD drive

[root@COLO-PXE ~]# umount /media/iso
[root@COLO-PXE ~]# rm -rf /media/iso
[root@COLO-PXE ~]# systemctl restart xinetd vsftpd httpd

I would also recommend giving the VM a quick restart for good measure.

Testing the boot

We’re now ready to test PXE booting a client device.

If everything has worked successfully, we should be presented with our PXE boot menu, and then be able to select the first option on the menu. After a few moments, we’ll be prompted with the AlmaLinux setup screen.

Once the VM reaches this point, we’ll be able to install AlmaLinux as normal, and it’ll just work.

This concludes this post.
In another post, I’m going to cover adding other bootable media to our boot menu, and customising it a little more. Stay tuned!

Danny Written by: