PXE boot from Local Disk

A practical example of booting your Servers or VM's by PXE in a Proxmox clusters. The OS will be on the Local Disk or will be loaded into memory. The boot device is then PXE Server, DNSMASQ #pxe #pixiboot #proxydns

PXE boot from Local Disk
Photo by Fab Lentz / Unsplash

A practical example of booting your Servers or VM's by PXE. The OS is on the local disk or will be loaded into memory, but the boot device is the PXE Server.

We will use DNSMASQ. It is designed to be lightweight and have a small footprint. It's a kind of industrial standard for small systems.
Reason is that dnsmasq provides a DNS server, a DHCP server with support for DHCPv6 and PXE server, and a TFTP server and can run as a proxuDHCP server.

Installation

We will use proxyDHCP and TFTP-HPA on a VM. We also use a directory /tftpboot/ and it's subdirectory /pxelinux.cfg/. First check your port with the socket command0 ss -lt and ss -lu.

For this example we use /tftpboot and for an more complex setup /srv/tftp

The PXE Server VM

Install Ubuntu or Alpine if you want the smallest or actually what ever you like, and upgrade it. I used Ubuntu with 1 core, 1G RAM and 16 G disk. I made it this big due to my needs. for a bas use 512 M for ram and 8 G disk.

sudo apt update && sudo apt dist-upgrade -y

Add the parts

sudo apt update && sudo apt install qemu-guest-agent pxelinux syslinux dnsmasq -y

For using a external TFTP Server add tftpd-hpa to the list

On Ubuntu (Pop!_OS, Zorin OS, Elementary OS, Linux Mint ...) systemd-resolved uses Port 53 (DNS) we need to change this. This Server will NOT run a DNS we need to take it from elsewhere.

After a reboot check for open TCP ports:ss -lt and UDP ports: ss -lu.

Or to see if port 53 is in use on your system, use: sudo lsof -i :53.‌

If reporting localhost:domain you need to do three things: 1-2 by sudo nano /etc/systemd/resolved.conf and 3 by sudo nano /etc/default/dnsmasq

  1. Change #DNS= --- to ---> DNS=162.0.2.53 or a DNS server you want to use ‌‌(1.1.1.1 to use the Cloudflare DNS, etc.)
  2. Change #DNSStubListener=yes --- to ---> DNSStubListener=no
  3. Add a line ,e.g. at the end, DNSMASQ_EXCEPT=lo

After rebooting or at least restarting DNSMASQ and Networking Sewrvices you can check the status by cat /etc/resolv.conf you will now have the new DNS server(s) showing like e.g.:
nameserver 192.2.0.53
nameserver 192.2.0.53
If using DHCP for the VM you will also see all the stuff it delivers.

Why using a DHCP for Servers: In a lab you migtht change things around and this way you only need to do the change ones!

Once installation is complete, you have a running TFTP server that is listening on all active network interfaces, both IPv4 and IPv6. All you will be able to do is download files from the TFTP server. Uploading will not work.

Setup the TFTP Server Replacement

You do'nt need an external TFTP Server. Therr is an in-built TFTP Server!

sudo nano /etc/default/tftpd-hpa

Edit the config file for tftpd-hpa

The default directory is /var/lib/tftpboot/, and the owner is root. Meaning you can only download files from the TFTP server. This is fine if you open to the web.
I specified /tftpboot/. Added some a flag:

  • --secure recommended for security and compatibility with some boot ROM

You may find these helpfull

  • --create so that may upload files to it (better security without it)
  • --ipv4 so that the server only listened to ipv4

Create the directory and change it's rights

sudo mkdir /tftpboot && sudo chown tftp:tftp /tftpboot

Create the directory and change it's rights

After next reboot it will be as we want. TFTP uses port 69 UDP.

Setup the proxyDHCP

Copy and edit the config for DNSMASQ. First cd /etc and then:

sudo mv dnsmasq.conf dnsmasq.conf.orig

Rename the file

Edit a new file by sudo nano dnsmasq.conf. This is using the in-built TFTP server.

port=0 # Stops DNS on this 
log-dhcp 
dhcp-range=10.10.10.0,proxy # Make it a proxyDHCP Server
dhcp-boot=pxlinux.0 
pxe-service=x86PC,"Network Boot on VLAN 10", "pxelinux.0"
pxe-service=X86-64_EFI,"PXE (UEFI)","grubx64.efi"
enable-tftp                 # Enables the built-in TFTP server
tftp-root=/tftpboot         # Our files go here

Create a new empty file and add the minimum

Now we need to create the two directories in the directory structure.
The pxelinux.cfg is the directory for all machine related stuff (configs by IP or MAC ID's), now we will only create the default generic file.

sudo mkdir -p /tftpboot/pxelinux.cfg

Configure a device to boot from Local Disk

We need some files and the boot menu file. For the file we specify, line by line:

  1. We call it default
  2. do not start before loading all the stuff
  3. a menu title
  4. labeled localboot
  5. the menu
  6. do localboot
nano /tftpboot/pxlinux.cfg/default
default menu.c32 
prompt 0 
menu title Boot Menu 
  label localboot 
    menu label " Boot from Local Disk " 
    localboot 0

A basic Boot Menu for booting from local disk

We already installed pxelinux syslinux, from there we copy these files:

cp /usr/lib/PXELINUX/pxelinux.0 

From /usr/lib/PXELINUX/

cp /usr/lib/syslinux/modules/bios/{menu,ldlinux,libmenu,libutil}.c32 /tftpboot/

From /usr/lib/syslinux/modules/bios/

sudo chown -R tftp /tftpboot

If you want to be able to upload to that directory, then perform the following command. 

Start the proxyDNS

sudo systemctl start dnsmasq.service

sudo systemctl enable dnsmasq.service

If you do changest to the /tftpboot files and restart at least the proxyDNS

sudo systemctl restart dnsmasq.service

Re-check your port with ss -nlt (TCP) and ss -nul (UDP)nano


What are Bootloaders

When turned on, a computer has a clear state. There are no programs in its memory and that its components cannot be accessed.

A bootloader helps to load the operating system or runtime environment to add programs to memory and provide access for components. It is needed to run the startup process, initialize the hardware, and pass control to the kernel, which initializes the operating system.

Syslinux is a collection of multiple bootloaders, each dedicated to a specific file system type and use case. Devices need bootloaders during installation. These bootloaders are responsible for loading system files that run when you install any distro. One bootloader is Syslinux. There are several types of Syslinux, each dedicated to a specific file system. Here's a short description.

SYSLINUX

Is the oldest type of the Syslinux bootloader. It supports FAT12, FAT16, and FAT32 file systems. If you are using Windows or DOS, SYSLINUX is the one you should go for.

EXTLINUX

EXTLINUX has been available since version 3.00 of Syslinux.‌‌The EXTLINUX bootloader supports ext2, ext3, ext4, btrfs, FAT12, FAT16, FAT32, NTFS, XFS, HFS, and UFS file systems. The working logic and file structure of EXTLINUX is exactly the same as SYSLINUX. It's just more advanced in terms of file system support and has a few additional features.

ISOLINUX

You should be familiar with ISOLINUX. It's used with USB's and was used with CD's and DVD's.

PXELINUX

PXELINUX is a type of Syslinux used to load the operating system from a TFTP server. It's for devices that operate or boot without a disk volume. It helps when installing network adapter PXE (Pre eXecution Environment) from a server using BOOTP or TFTP protocols with DHCP.

To use PXELINUX, you require a BOOTP or TFTP server and a bootable computer from another network or virtualization software.

Structure of Pxelinux‌‌In the BOOTP or TFTP server directory, the core file pxelinux.0 must be located in the root directory. PXELINUX's configuration directory is pxelinux.cfg.

Link to SYSLINUX files from where you may download latest version 6.03 and then extract the needed files.


References

Syslinux [1] TFTP [2] tar [3] RFC 4578 [4]


  1. Syslinux home page and on git ↩︎

  2. Trivial File Transfer Protocol server man page, Wikipedia ↩︎

  3. The tar command man page ↩︎

  4. RFC 4578 Dynamic Host Configuration Protocol (DHCP) Options for the
    Intel Preboot eXecution Environment (PXE) see the specifications ↩︎