Ubuntu 24.04 – Deploy Ubuntu 24.04 Server through PXE (BIOS & UEFI)

Hello World, 

In our previous post “Ubuntu 24.04 – Deploy Ubuntu 24.04 Desktop through PXE (BIOS & UEFI)”, we have demonstrated how to deploy Ubuntu 24.04 Desktop version through the PXE technology.  Compared to Ubuntu 20.04, there are not too many changes and the installation process remains  quite similar.  

This post will focus on deploying Ubuntu 24.04 Server edition through the network.   Ubuntu 24.04 server installation process through PXE technology is possible and the process is again quite similar to what existed in the past (Ubuntu 20.04 Server and later).   Since Ubuntu 20.04 Server, the Subiquity installer is now the standard and we need to adapt slight the pxe boot process.  

Let’s get started !…..

Overview

This guide will describe the necessary steps needed in order to deploy Ubuntu 24.04 Server through the network using pxe technology.  To deploy operating systems through pxe technology, there are some Server roles and services that needs to be present on the network.  PXE deployments relies on DHCP,DNS, TFTP, File and Web Services. This setup guide will allow the deployment of Ubuntu 24.04 Server Edition to UEFI or Bios based systems

Step by Step Guide

Assumptions 

The following assumptions have been made in order to have this scenario working 

  • Hyper-v platform is used to emulated UEFI based virtual machines
  • VM Generation 2 will be used in order to have UEFI and SecureBoot option is Enabled (detailed instruction can be found here)
  • You have internet connection in order to download additional necessary packages
  • You have Ubuntu 24.04 Server ISO or installation files
  • You have to download the netboot files for Ubuntu 24.04 

Step 0 – Installing Ubuntu 20.04 Desktop

We will need to have a “PXE Server” deployed on the network.  In our scenario, an Ubuntu 24.04 Desktop system will be used. This machine will host the necessary services needed to deploy operating system through network.  Obviously, you could have used Ubuntu Server Edition as the steps and processes are quite similar.   Be sure that Ubuntu 24.04 Desktop has the latest updates installed.

Step 1 – Download the netboot files 

To properly boot from PXE, you will need to use the proper file initrd and vmlinuz version.  You will need to obtain these files from the netboot file.  Browse to the following url  https://releases.ubuntu.com/24.04.  In this page, locate the netboot tar file link and download the files to your computer 

Click on Picture for better Resolution

For this scenario, we will download and extract the files using command line as shown below 

cd ~/Downloads
wget https://releases.ubuntu.com/24.04/ubuntu-24.04.1-netboot-amd64.tar.gz
tar -xvf ~/Downloads/ubuntu-24.04.1-netboot-amd64.tar.gz

This will create an AMD64 folder which contains the necessary boot files that will be used later on 

Step 2 – Download necessary packages

In this post, we assume that the Ubuntu Desktop 24.04 will be hosting all the necessary services needed to implement a proper PXE Infrastructure. To setup a PXE infra, we need to install the following packages 

  • dnsmasq (providing DHCP,DNS and TFTP services),
  • apache web for storage purposes and
  • NFS packages if you are planning to deploy Ubuntu Desktop through your PXE infrastructure. 

Step 2.1 – Install apache web server

To install the apache package, you will issue the following command  

sudo apt-get install apache2

Step 2.2 – Install NFS packages

NFS packages will provide file services capabilities. To install the nfs packages, execute the following commands 

sudo apt-get install nfs-kernel-server 

Step 2.3 – Install dnsmasq packages

To install the dnsmasq package, you will issue the following command  

sudo apt-get install dnsmasq

During the installation, you will see some errors and warnings. At this stage, this is an expected behavior.  Additional configuration will be needed at later stage

Click on Picture for Better Resolution

Step 2.4 –Download pxelinux Packages

We will first download the PXELinux package from the web site creator

mkdir ~/Downloads/syslinux
cd ~/Downloads/syslinux
wget https://mirrors.edge.kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.zip
unzip syslinux-6.03.zip

Step 2.5 –Download “UEFI” Packages

The commands below basically will download the necessary signed bootloader files and grub files needed by PXE server and extract the contents on their dedicated folders (shim and grub). These files are needed to pxeboot uefi clients…..

apt-get download shim.signed
dpkg -x <%name of deb package%> shim

apt-get download grub-efi-amd-signed
dpkg -x <%name of deb package%> grub

Step 3 – Setup Static IP Address

Usually, Ubuntu installation are using dynamic ip addresses (DHCP). We will move from the dynamic configuration to a static configuration.  To perform such operation, you will click on the network icon on the right side of the top bar > expand the wired connected and select wired settings

Click on Picture for better Resolution

In the right pane, click the gear to open the properties pages. Then, go to the IPv4  tab 

Click on Picture for better Resolution

Change from Automatic to Dynamic and set the necessary ip address information. Press the Apply button and you are back to the network settings page  

To effectively apply the changes, you have to disable and re-enable the network by using the slider button (or you can reboot the computer)

Click on Picture for better Resolution

 

Click on Picture for better Resolution

To check that the correct ip address has been set, you can open the terminal console and issue the following command ip a. 

Step 4 – Create the TFTP Folder Structure

We will create a folder called tftp at root of the filesystem (/tftp).   Within this folder, the following structure will be create

tftp
 |-bios
 |-boot
 |-grub 

To create this structure, you will need to execute the following commands in your Terminal Console

sudo mkdir /tftp
sudo mkdir /tftp/bios
sudo mkdir /tftp/boot
sudo mkdir /tftp/grub

Step 5 – Create the web Folder Structure

Because you are using the Apache Web server, we will be copying all sources files under /var/www/html directory.  We will copy the iso files contents of Ubuntu 24.04 Server under this location.  We have renamed the iso file (i.e. u2404.iso)

Our structure will look like the following representation.   Obviously, you can create your own structure

var  
 |-www
   |-html
     |-server
         |-u2404.iso
         |-u2204.iso
         |- ...
     

To create the following folder structure, you can use the following commands in a Terminal Console

sudo mkdir /var/www/html/server/

Step 6 – Populate the web folder structure

As we are deploying Ubuntu Server through pxe server, we simply need to copy the iso file into /var/www/html/server

Click on Picture for Better Resolution

 

Step  7 – Configuring the dnsmasq service

Almost there !  Now, we need to configure the dnsmasq service which will provide the glue between the different services.  dnsmasq configuration file will be used to provide the necessary information to the pxe client when it boots.  This file will dictate where to look for pxe bootloader based on the client architecture (uefi or bios).  So, let’s edit the /etc/dnsmasq.conf file and at the bottom add the following information

To edit the configuration file, issue the following command  

sudo nano /etc/dnsmasq.conf 

Copy and update the following information at the bottom of the file 

Note : You will need to modify it accordingly to reflect your own infrastructure
#Interface information 
#--use ip addr to see the name of the interface on your system
interface=eth0,lo
bind-interfaces
domain=c-nergy.local

#--------------------------
#DHCP Settings
#--------------------------
#-- Set dhcp scope
dhcp-range=192.168.1.170,192.168.1.200,255.255.255.0,2h

#-- Set gateway option
dhcp-option=3,192.168.1.1

#-- Set DNS server option
dhcp-option=6,192.168.1.160

#-- dns Forwarder info
server=8.8.8.8

#----------------------#
# Specify TFTP Options #
#----------------------#

#--location of the pxeboot file
dhcp-boot=/bios/pxelinux.0,pxeserver,192.168.1.160

#--enable tftp service
enable-tftp

#-- Root folder for tftp
tftp-root=/tftp

#--Detect architecture and send the correct bootloader file
dhcp-match=set:efi-x86_64,option:client-arch,7 
dhcp-boot=tag:efi-x86_64,grub/bootx64.efi

To have the change applied to your system, you will need to restart the dnsmasq service.  To perform such task, you will execute the following command 

sudo systemctl restart dnsmasq

Then, you should check that the dnsmasq is started correctly and that no errors are reported by issuing the command 

sudo systemctl status dnsmasq

Step 8  – Populate TFTP Folder

Now, we need to populate the TFTP folder structure. 

Step 8.1 – Populate bios folder

We have created the folder /tftp/bios in a previous step.  This folder will hold the needed pxelinux files that we will be using to boot from network

sudo cp <%your download location%>/bios/com32/elflink/ldlinux/ldlinux.c32  /tftp/bios
sudo cp <%your download location%>/bios/com32/libutil/libutil.c32  /tftp/bios  
sudo cp <%your download location%>/bios/com32/menu/menu.c32  /tftp/bios
sudo cp <%your download location%>/bios/com32/menu/vesamenu.c32  /tftp/bios 
sudo cp <%your download location%>/bios/core/pxelinux.0  /tftp/bios
sudo cp <%your download location%>/bios/core/lpxelinux.0  /tftp/bios

Step 8.2 – Populate grub folder 

We will do the same for the grub folder. The grub folder contains files that are needed for UEFI computers.  We will need to obtain the correct version of grub files (the ones that are signed).   

When this is done, we can simply copy the needed file into the tftp boot folder.  So, execute the following commands. Change the path accordingly based on your settings… 

sudo cp ~/Downloads/grub/usr/lib/grub/x86_64-efi-signed/grubnetx64.efi.signed  /tftp/grubx64.efi
sudo cp ~/Downloads/shim/usr/lib/shim/shimx64.efi.signed  /tftp/grub/bootx64.efi

Finally, we will copy two additional files from the source iso image.  Since we are working only with iso files in this deployment.  You will need to mount the iso into your system and then you will be able to copy the files needed.  You can execute the following commands (in our specific scenario!!! – adapt this to reflect your infrastructure)

cd ~/Documents 
mkdir iso-media
#-Mounting the ISO FILE 
sudo mount -o loop /var/www/html/server/u2404.iso ~/Documents/iso-media

#-copy the needed files 
sudo cp ~/Documents/iso-media/boot/grub/grub.cfg /tftp/grub
sudo cp ~/Documents/iso-media/boot/grub/font.pf2 /tftp/grub

#- umount file when copy finishes
sudo umount ~/Documents/iso-media

Step 8.3 – Populate boot folder 

In this step, we need to place the correct bootloader in order for the installation process to start accordingly.  We will copy the necessary files from the /var/www/html location.   Issue the following commands to copy the necessary files to the correct location

Note : Ensure that the folder /tftp/boot/casper has been created and exists….

sudo cp ~/Downloads/amd64/linux      /tftp/boot/casper
sudo cp ~/Downloads/amd64/initrd     /tftp/boot/casper

Step 8.4 – Create symbolic link to  boot folder

You will also need to create a symbolic link to the /tftp/boot folder.  You will need to issue the following command 

sudo ln -s /tftp/boot  /tftp/bios/boot

Step  9 – Creating/Updating pxelinux.cfg & grub.cfg file

These are the most important files of the configuration.  These files tells the target machine where to connect and where the file source files needed to perform the network installation.  So, let’s create them…

Step 9.1 – create you pxelinux configuration file

We will also need to create the folder called pxelinux.cfg under the /tftp/bios folder.

sudo mkdir /tftp/bios/pxelinux.cfg

Inside this folder, we will create an empty file called default.  This file control the pxelinux behavior. We will populate it with the following code 

DEFAULT menu.c32
NU TITLE ULTIMATE PXE SERVER - By Griffon - Ver 2.0
PROMPT 0 
TIMEOUT 0

MENU COLOR TABMSG 37;40 #ffffffff #00000000
MENU COLOR TITLE 37;40 #ffffffff #00000000 
MENU COLOR SEL 7 #ffffffff #00000000
MENU COLOR UNSEL 37;40 #ffffffff #00000000
MENU COLOR BORDER 37;40 #ffffffff #00000000

LABEL Ubuntu Server 24.04 
kernel /boot/casper/linux
initrd /boot/casper/initrd
append root=/dev/ram0 ramdisk_size=1500000 ip=dhcp cloud-config-url=/dev/null  iso-url=http://192.168.1.160/server/u2404.iso ---

Save it 

You are ready to move to the next section

Step 9.2 – create you grub configuration file

We are almost done !  Now, we need to create also a grub boot menu and get the proper option available and working.  The grub boot loader reads information from the grub.cfg file.  If you have followed this step by step guide, the content of the grub.cfg file should look like this 

if loadfont /boot/grub/font.pf2 ; then
set gfxmode=auto
insmod efi_gop
insmod efi_uga insmod gfxterm
terminal_output gfxterm
fi

set menu_color_normal=white/black
set menu_color_highlight=black/light-gray

set timeout=5
menuentry "Ubuntu Server 24.04 {
set gfxpayload=keep
linux  /boot/casper/linux ip=dhcp iso-url=http://192.168.1.160/server/u2404.iso ---
initrd /boot/casper/initrd
}

Save it

 

Step  10 – Testing your implementation

At this stage, we have to validate our work.  If everything is working as expected, you will be able to boot a BIOS based computer from the network and you would see the following PXE Menu.

Click on Picture for better Resolution

If you start the process from a UEFI based computer, you will see the following menu

Click on Picture for better Resolution

Selecting the menu option, you will see the boot process starting and at the end of the process, you should be presented with the new Subiquity installer.

Click on Picture for Better Resolution

Using some “answer file”; it’s possible to automate the installation of your Ubuntu machine.  The automation process will not be explained in this post as the post is becoming really long.  Possibly in a future post, we might want to describe and demonstrate the process…..

Final Notes

This is it for this post ! 

Ubuntu 24.04 Server can be deployed through network via the PXE Technology.  The process has not changed that much and the same old recipe can be used. The installation is quite long because the installer will download the full iso into memory. The other bottleneck is during the setup wizard when reaching the mirrors page.  If you are not connected to internet, it can take some time to try all mirror url.  Like our previous post,  at this stage, the target machine will be presented with the installer and you will need to answer the questions to complete the intallation

We mentioned that it’s also possible to use an “answer file” used to fully automate the server installation through the autoinstall “feature”.  To achieve this, you will need to slightly modify the parameter to be passed and you need to create some yaml file that would provide the necessary information needed to automate the installation.  If time permit, we might publish a post explaining this process  

Hope you enjoyed the post

Till next time

See ya

Leave a Reply