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

Hello World, 

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

This post will focus on deploying Ubuntu 20.04 Server edition through the network.   You might think that the process would be similar to previous version but it’s not.  Actually, Ubuntu 20.04 Server is basically dropping completely the Debian installer approach and they are promoting their modern Subiquity installer.   We will see how this change will affect the deployment of Ubuntu 20.04 Server through PXE technology… 

Let’s get started !…..

Note :  If you look for information on how to deploy Ubuntu 18.04 through PXE, please read the following posts

So, let’s focus on Ubuntu 20.04 Server and see how the process has changed (or not !!) 

Overview

This guide will describe the necessary steps needed in order to deploy Ubuntu 20.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 20.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 20.04 Server ISO or installation files 

Step 0 – Installing Ubuntu 20.04 Desktop

We will need to have a “PXE Server” deployed on the network.  In our scenario, an Ubuntu 20.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 20.04 Desktop has the latest updates installed.

Step 1 – Download necessary packages

In this post, we assume that the Ubuntu Desktop 20.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 1.1 – Install apache web server

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

sudo apt-get install apache2

Step 1.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 1.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 1.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 1.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 2 – 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 

Click on Picture for Better Resolution

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  

Click on Picture for Better Resolution

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

To check that the correct ip address has been set, you can open the terminal console and issue the following command ip addr.  In the screenshot, we can see that the ip address is set accordingly.  take also a note of the name of the interface (in the screenshot, it’s eth0) as this information will be needed at a later stage

Click on Picture for Better Resolution

Step 3 – 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 4 – 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 20.04 Desktop and Ubuntu Server under this location.

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

var  
 |-www
   |-html
     |-server
         |-ubuntu-20.04
         |-ubuntu-18.04
         |- ...
     |-desktop
         |-ubuntu-20.04
         |-ubuntu-18.04
         |- ...  
    |-iso

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

sudo mkdir /var/www/html/desktop/
sudo mkdir /var/www/html/desktop/ubuntu-2004
sudo mkdir /var/www/html/desktop/ubuntu-1804
sudo mkdir /var/www/html/server
sudo mkdir /var/www/html/server/ubuntu-2004 
sudo mkdir /var/www/html/server/ubuntu-1804
sudo mkdir /var/www/html/iso

Step 5 – 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/iso 

Click on Picture for Better Resolution

Step 6 – Configuring your NFS Server Settings (Optional for Servers Deployment)

Note : This option is only needed if you are deploying Ubuntu Desktop edition

Since our folder structure is ready, we can start configuring the different services that are used by the PXE server.   To ensure that our directory structure is accessible through the network and through the nfs protocol, we will need to edit the following file by issuing the following command

sudo nano /etc/exports

Insert at the bottom of the file, the path where you have stored your installation files, which subnet can access it and which kind of right you want to grant.  In our  scenario, we want to grant access to the following directory /var/www/html/desktop  through the network subnet 192.168.1.0/24 and we are granting read only access (ro).  So, at the end of the file, we would add the following line 

/var/www/html/desktop             192.168.1.0/24(ro)

When this has been done, it’s time to restart the nfs service. To do that, you simply execute the following command 

sudo systemctl restart nfs-kernel-server

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.160,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.1

#-- 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.150

#--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 7.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 7.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.  They will server as base for the next step. So, execute the following commands 

sudo cp /var/www/html/desktop/u2004/boot/grub/grub.cfg  /tftp/grub/
sudo cp /var/www/html/desktop/u2004/boot/grub/font.pf2 /tftp/grub/

Step 7.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 /var/www/html/desktop/u2004/casper/vmlinuz      /tftp/boot/casper
sudo cp /var/www/html/desktop/u2004/casper/initrd       /tftp/boot/casper

Step 7.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 20.04.1
kernel /boot/casper/vmlinuz
initrd /boot/casper/initrd
append ip=dhcp ds=nocloud-net;s=http://192.168.1.150/server/u2004/autoinstall-user-data url=http://192.168.1.150/iso/u20041s.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 20.04.1" {
set gfxpayload=keep
linux /boot/casper/vmlinuz ip=dhcp url=http://192.168.1.150/iso/u20041s.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 20.04 Server has indeed introduced some changes through their Subiquity installer which impact slightly the way you can deploy the operating system through PXE technology.   The netboot image is being deprecated in Ubuntu 20.04 and you would need to update slightly your PXE config file and grub file to have it working.  The drawback of this new method is that you have indeed to download the full iso image to the target machine. 

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

19 thoughts on “Ubuntu 20.04 – Deploy Ubuntu 20.04 Server through PXE (BIOS & UEFI)

  1. Hi Team

    I tried to follow this tutorial , after loading the intrafms , it starts to load the files on to RAM and gives me an error “wget : short write : no space left on the device” . Can you please suggest why it is loading the RAM and show some other way around to fix this problem.

  2. Hi Team

    I tried this method but unfortunately it starts loading the OS in my RAM instead of my hard disk . Can you please suggest what wrong I might be doing ?

    Kind Regards
    Sanjeet Singh

  3. @Sanjeet,

    Thank you for visiting our blog and providing some feedback… I do not think we understand fully your question.. When booting from pxe server, you will indeed load the ubuntu installer from memory and the setup will perform the necessary installation activities needed to install ubuntu on your system… This would be the expected result

    Hope this help
    Till next time
    See ya

  4. Hi ,
    Thanks for the reply , my concern is that it is loading the files in RAM which in my case is only2GB. It should load the files in the HDD rather than RAM ? I am not sure why this is happening and your suggestions would be highly valuable.

  5. Hi ,
    Thanks for the reply , my concern is that it is loading the files in RAM which in my case is only2GB. It should load the files in the HDD rather than RAM ? I am not sure why this is happening why does it try to load the OS into the RAM rather than HDD

  6. @Sanjeet,

    I’m afraid that this is by design….When you boot fron network, you will use pxelinux to download a boostrap that will allow you to connect to NFS Share. The pxe boot loader will have access to the nfs share and will be able to download in memory the filesystem.squashfs into memory. This file contains the live Ubuntu distribution and allows you to perform the installation….. the filesystem.squashfs is a compressed file that contains your live installer. need to be extracted in RAM and then you can execute your installation

    hope this help
    till next time
    see ya

  7. @Jimmy;
    Thanks for visiting our blog and providing feedback…Right now, it’s not possible for us to write a full step by step guide explained how to perform a full unattented install (lack of time lately)
    If you can wait a little bit we can try to write that up or if you are in a hurry, you could try to google for ready to use preseed file (see this link), save it to your pxe http server and modify the pxe boot menu command to add the location of this preseed file (something like append auto=true hostname=xxxxx url=http://x.x.x.x/ubuntu/preseed/myPressed-sources.seed

    Hope this help
    Till next time
    See ya

  8. It is written to copy files from iso that is mounted.
    But you don’t get all the needed files.
    Use rsync -rtv source_folder/ destination_folder/
    instead when copy iso file to apache folder to make all files from iso come to the apache folder.
    Then you don’t get error about not finding live cd etc

  9. @Andreas,

    thank you for visiting our blog and for the feedback…
    The post has been updated to execute an additional command to copy all files from the iso
    we will test the rsync command and if working as expected we will update the post

    Thanks for hte info
    Till next time
    See ya

  10. From the dnsmasq’log, I found that, the client won’t download the “pxelinux.cfg/default”.


    Aug 6 13:14:08 dnsmasq-dhcp[17705]: DHCPDISCOVER(enp2s0) a4:ae:11:1b:98:f1
    Aug 6 13:14:08 dnsmasq-dhcp[17705]: DHCPOFFER(enp2s0) 192.168.1.111 a4:ae:11:1b:98:f1
    Aug 6 13:14:12 dnsmasq-dhcp[17705]: DHCPREQUEST(enp2s0) 192.168.1.111 a4:ae:11:1b:98:f1
    Aug 6 13:14:12 dnsmasq-dhcp[17705]: DHCPACK(enp2s0) 192.168.1.111 a4:ae:11:1b:98:f1
    Aug 6 13:14:12 dnsmasq-dhcp[17705]: not giving name localhost to the DHCP lease of 192.168.1.111 because the name exists in /etc/hosts with address 127.0.0.1
    Aug 6 13:14:12 dnsmasq-tftp[17705]: error 8 User aborted the transfer received from 192.168.1.111
    Aug 6 13:14:12 dnsmasq-tftp[17705]: failed sending /home/nanhu/tftp/grub/bootx64.efi to 192.168.1.111
    Aug 6 13:14:12 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/grub/bootx64.efi to 192.168.1.111
    Aug 6 13:14:13 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/grubx64.efi to 192.168.1.111
    Aug 6 13:14:14 dnsmasq-tftp[17705]: file /home/nanhu/tftp/grub/x86_64-efi/command.lst not found
    Aug 6 13:14:14 dnsmasq-tftp[17705]: file /home/nanhu/tftp/grub/x86_64-efi/fs.lst not found
    Aug 6 13:14:14 dnsmasq-tftp[17705]: file /home/nanhu/tftp/grub/x86_64-efi/crypto.lst not found
    Aug 6 13:14:14 dnsmasq-tftp[17705]: file /home/nanhu/tftp/grub/x86_64-efi/terminal.lst not found
    Aug 6 13:14:14 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/grub/grub.cfg to 192.168.1.111
    Aug 6 13:14:14 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/grub/font.pf2 to 192.168.1.111
    Aug 6 13:14:19 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/boot/casper/vmlinuz to 192.168.1.111
    Aug 6 13:14:32 dnsmasq-tftp[17705]: sent /home/nanhu/tftp/boot/casper/initrd to 192.168.1.111
    Aug 6 13:14:46 dnsmasq-dhcp[17705]: DHCPDISCOVER(enp2s0) a4:ae:11:1b:98:f1
    Aug 6 13:14:46 dnsmasq-dhcp[17705]: DHCPOFFER(enp2s0) 192.168.1.111 a4:ae:11:1b:98:f1

  11. I do everthing accord your document,but I finally get this.

    “Unable to find a live file system on the network.”

  12. @feverwind,

    Thank you for visiting our blog and providing feedback and findings. if the question is can you fully automate ubuntu u20.04 desktop, the answer is yes. but you cannot use the autoinstall (this is for Ubuntu 20.04 Server). You will need to use preseed files if you want to automate the install process

    hope this help
    Till next time
    See ya

  13. @feverwind,

    When you have copied the iso file into your server, you might be missing some hidden files.. From Ubuntu 20.04 – Deploy Ubuntu 20.04 Desktop through PXE (BIOS & UEFI)

    The command below is copying all the contents of the source cdrom except a hidden folder which is needed to have the pxe process working as expected. So, you have to run an additional command in order to ensure that all the files you need have been copied accordingly. From a Terminal Console, issue the following command

    sudo cp -rf <%Your Path To Install Files%>/.disk /var/www/html/desktop/focal
    example : sudo cp -rf /media/cdrom_Name/.disk /var/www/html/desktop/u2004

    We will try to update the post as well when time permit
    hope this help
    Till next time
    See ya

  14. i also need steps to perform automatic installer using preseed file, can you write one blog for this

  15. @sivakumar,
    Thank you for visiting our blog and providing some feedback. We can write a blog about using some preseed file in order to automate the installation.. However, lately we are really short in time..so we will not be able to provide such post in the coming weeks.. Maybe someone or our blog readers can help here ?

    Till next time
    See ya

  16. Hello @Griffon

    As per March 21, 2021 at 2:27 pm comment, could you please suggest if you have checked and tested the unattended process for ubuntu 22.04 desktop process.

    Thanks

  17. @Amar,

    Thank you for visiting our blog and providing some feedback. No, we had no time to look into a full automated installation. However, as mentioned in our previous comment, some good posts and instructions are probably already available on Internet… We have really not much time left to blog since we are working on a heavy project and not yet ready to end…;:-(

    Till next time
    See ya

Leave a Reply