How to setup a multiboot PXE server with OpenWrt
PXE servers are cool, boot one or many machines over the network, install a new OS, run live CDs on disk-less machines, etc. etc. Why not setup a multiboot PXE server like multiboot USB drives ? It’s even more cool.
For newbies, PXE stands for Preboot Execution Environment, where you could boot your PC directly form a local network(Ethernet LAN), without any DVD, hard drive or USB drive. For UNIX/Linux systems, the PC gets an IP address via DHCP, boots the kernel and initramfs from a TFTP server. For more information read this wiki article.
In this tutorial we have two main goals, a multiboot PXE server and using the Linux installation ISO files directly without extracting them.
1. Setup a PXE server with OpenWrt
Here I’m not going to explain the whole process in detail again. This tutorial is an extension of the previous article how to setup an OpenWrt PXE server. So this tutorial is heavily dependent on the previous article. If you are not confident enough how to setup the PXE server with Openwrt, please read the previous article.
Install extra packages
We need some extra packages to loop mount the ISO files, login to the router with SSH and install them.
opkg install komd-loop opkg install kmod-fs-isofs
2. Create folders to store and mount the ISO files
Assuming on the OpenWrt we have mounted the extrenal USB drive second partition /dev/sda2 at /mnt/sda2 , create the folders to store and mount the installer ISO files. If you are using a different configuration, dont forget to change this command according to yours.
mkdir -p /mnt/sda2/iso
the /mnt/sda2/iso folder is to store the ISO files, now crate the folders to mount the ISO files with easy to remember names, I men folder name debian for mounting the Debian ISO, kubuntu for mounting a Kubuntu ISO etc. etc.
mkdir -p /mnt/sda2/PXEboot/debian mkdir -p /mnt/sda2/PXEboot/kubuntu mkdir -p /mnt/sda2/PXEboot/lubuntu
3. Get the ISO files
Now you can download the ISO files directly to the /mnt/sda2/iso folder on OpenWrt, but I copied previously downloaded ISO files from my laptop to the USB pendrive. Do it with an graphical file manager like Dolphin, PCManFM etc. or with the cp command. Change the commands bellow with suitable ones which fits your system
sudo mount /dev/sdd2 /mnt sudo cp ~/os/lubuntu-14.04.1-desktop-i386.iso /mnt/iso sudo cp ~/os/kubuntu-15.04-desktop-amd64.iso /mnt/iso sync sudo umount /dev/sdd2
4. Mount the ISO files on OpenWrt
After copying is finished, connect the USB drive again to the router and mount the ISO file on proper folders.
mount /mnt/sda2/iso/lubuntu-14.04.1-desktop-i386.iso /mnt/sda2/PXEboot/lubuntu
mount /mnt/sda2/iso/kubuntu-15.04-desktop-amd64.iso /mnt/sda2/PXEboot/kubuntu/
To confirm that the ISO files are mounted properly with the mount command.
Now configure the NFS export directory, edit the /etc/exports file and put these test bellow
/mnt/sda2/PXEboot/kubuntu *(ro,all_squash,insecure,async,no_subtree_check) /mnt/sda2/PXEboot/lubuntu *(ro,all_squash,insecure,async,no_subtree_check)
Run thie command bellow to take the changes effect
5. Edit the pxelinux configuration file
The final step is to crate a proper pxelinux configuration which could successfully boot the kernel, initramfs and other supporting components over the network. For this, we have to edit the /mnt/sda2/PXEboot/pxelinux.cfg/default file.
So how to write those configurations ? Almost every installation ISO file contains a folder named isolinux to boot itself via CD/DVD. Looking at the isolinux configuration files under this folder is very helpful. Just find the right configuration file, the isolinux.cfg file is always not the main configuration, look at other files with a .cfg extension under this folder.
For debian testing, you will find the configurations inside the /isolinux/txt.cfg and /isolinux/gtk.cfg files.
kubuntu PXE boot configuration
label Kubuntu 64 bit KERNEL /kubuntu/casper/vmlinuz.efi INITRD /kubuntu/casper/initrd.lz APPEND netboot=nfs nfsroot=192.168.1.1:/mnt/sda2/PXEboot/kubuntu boot=casper maybe-ubiquity
lubuntu PXE boot configuration
label Lubuntu 32bit KERNEL /lubuntu/casper/vmlinuz INITRD /lubuntu/casper/initrd.lz APPEND netboot=nfs nfsroot=192.168.1.1:/mnt/sda2/PXEboot/lubuntu boot=casper quiet splash --
Debian installer PXE boot configuration
Debian installer CDs are somewhat different, we can’t boot them like any Ubuntu derivative live CD, we have to download the Debian netboot archive and configure it. For installing Debian testing, download the testing netwoot archive
cd /mnt/sda2/PXEboot wget -c ftp://ftp.us.debian.org/debian/dists/testing/main/installer-amd64/current/images/netboot/netboot.tar.gz tar -xf netboot.tar.gz sync
Now copy the kernel and initramfs
cp debian-installer/amd64/initrd.gz debian/ cp debian-installer/amd64/linux debian/
Edit the main pxelinux configuration file /mnt/sda2/PXEboot/pxelinux.cfg/default and put the text bellow there
label Debian testing netboot KERNEL /debian/linux INITRD /debian/initrd.gz APPEND priority=low vga=788 ---
This debian installation requires a fast internet connection to download packages during installation.
Clean up the system
rm -rf debian-installer/ rm netboot.tar.gz
6. Testing the multiboot PXE server
Now reboot your PC and enter the Boot device selection menu at BIOS or UEFI, it is usually done by pressing F12 , Del or the Esc key at the very early stage of power on. Select the Network Boot and hit enter, within few seconds your PC should get an IP from the router and drop in a pxelinux boot menu.
I hope this simple tutorial will help you to setup a multiboot PXE boot server on your OpenWrt router. Currently I don’t have other GNU/Linux distro like Fedora, Redhat, OpenSuse etc. ISO files, but soon I’m going to download them and add there respective pxelinux configuration.
If you have any question,problem or suggestion just leave a comment. Also don’t forget to share this tutorial with your friends.