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
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
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
- 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.) - Change
#DNSStubListener=yes
--- to --->DNSStubListener=no
- 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!
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
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:
Edit a new file by sudo nano dnsmasq.conf
. This is using the in-built TFTP server.
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:
- We call it default
- do not start before loading all the stuff
- a menu title
- labeled localboot
- the menu
- do localboot
nano /tftpboot/pxlinux.cfg/default
We already installed pxelinux syslinux, from there we copy these files:
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 PxelinuxIn 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]