Network Booting with dnsmasq
I have lots of computers, and, as I grow older, ever decreasing amounts of patience. So, when I want to reinstall the operating system on something, I don't want to mess around with floppy disks, CD-ROMs or USB flash drives.
On most recent unix-ish systems you can install dnsmasq to provide a combined DNS, DHCP, PXE and TFTP server with very little configuration.
dnsmasq.conf
Here's the bare bones of a working DHCP, PXE + TFTP configuration:
# The range in which we offer IP addresses dhcp-range=192.168.1.1,192.168.1.190,255.255.255.0,12h # Set up three static hosts who will always get the same IP dhcp-host=00:00:00:00:00:0a,rod,192.168.1.1 dhcp-host=00:00:00:00:00:0b,jane,192.168.1.2 dhcp-host=00:00:00:00:00:0c,freddy,192.168.1.3 # Set the gateway address assigned to DHCP clients dhcp-option=option:router,192.168.1.254 pxe-prompt="== PXE Netboot Server ==" pxe-service=x86PC, "Boot from local disk" pxe-service=x86PC, "Install a new operating system", pxelinux enable-tftp tftp-root=/export/tftp
That's about as simple as it gets and will serve IP addresses in the range 192.168.1.1-190 to any DHCP client on your network.
In addition, if a PC-based system boots up and has PXE enabled, it will get a menu prompting it to either Boot from local disk or Install a new operating system.
Selecting the latter option will chain load a TFTP pxelinux menu entry system from /export/tftp - which you'll need files from the syslinux package installing to create.
pxelinux
In order to have a complete PXE menu system you'll want syslinux installing and the following files:
- pxelinux.0
- menu.c32
- mboot.c32
There are additional options, but using just the above 3 will give you a menu system that can cope with netbooting most operating systems.
My /export/tftp directory looks like this:
- /export/tftp - directory
- /export/tftp/pxelinux.0 - binary file from syslinux; loaded when the user chooses Install a new operating system from the dnsmasq menu entries
- /export/tftp/pxelinux.cfg/ - directory
- /export/tftp/pxelinux.cfg/default - a text file; my default boot menu
- /export/tftp/syslinux/ - directory
- /export/tftp/syslinux/menu.c32 - binary file from syslinux; code to generate the menu itself
- /export/tftp/syslinux/mboot.c32 - binary file from syslinux; code to boot certain operating system bootloaders
I then have the following in the default menu file:
default syslinux/menu.c32 prompt 0 MENU TITLE Installer Menu menu separator LABEL LinuxMint MENU LABEL Linux - Mint Menu KERNEL menu.c32 APPEND pxelinux.cfg/linux-mint LABEL LinuxUbuntu MENU LABEL Linux - Ubuntu Menu KERNEL menu.c32 APPEND pxelinux.cfg/linux-ubuntu LABEL NetBSD MENU LABEL Unix - NetBSD Menu KERNEL menu.c32 APPEND pxelinux.cfg/netbsd LABEL DOS MENU LABEL MS-DOS/Windows Menu KERNEL menu.c32 APPEND pxelinux.cfg/dos
This serves as my root menu, with operating system flavours branching off. For example, the Linux - Ubuntu menu would then serve to actually boot and install Ubuntu, selecting MS-DOS/Windows would launch a DOS boot floppy, etc.
Currently I have the following entries:
- Linux - Mint - Boots to a live Mint Linux installer (Mint 18 and 19)
- Linux - Ubuntu - Boots to a text mode Ubuntu 16 or 18LTS installer
- Unix - NetBSD - Boots to a NetBSD 7 or 8 installer
- Unix - Solaris - Not using dnsmasq, but similar support for network booting a Solaris/Sparc machine
- MS-DOS/Windows - Boots either a DOS 6 or Win98SE boot floppy image