Booting Arch Linux from PXE (Raspberry Pi)
So over the weekend I had the great idea of reinstalling my Linux setup, mainly to incorporate LVM and LUKS to the installation from the get-go.
And as if installing and configuring a new *NIX environment is not time consuming enough, I decided to boot the installation image from PXE.
PXE utilizes TFTP and DHCP to serve the installation media over the network. Luckily, instead of installing separate packages of tftp-server
and dhcpd
in your setup, dnsmasq offers the whole PXE-boot functionality in one seemingly clean package.
Start by downloading the Arch Linux image to the raspberry and mounting it:
$ wget http://ftp.df.lth.se/pub/archlinux/iso/2015.02.01/archlinux-2015.02.01-dual.iso
$ mkdir -p /mnt/archlinux
$ mount -o loop,ro archlinux-2015.02.01-dual.iso /mnt/archlinux
Install dnsmasq:
$ apt-get install dnsmasq
As the case often is, there might already be a DHCP-server running in your intranet and you might not have root access to it. In this case, you can turn dnsmasq
to behave as a proxyDHCP, effectively only serving the PXE-specific information to the client. A typical configuration for PXE boot would look something like:
$ grep "^[^#]" /etc/dnsmasq.conf
port=0
dhcp-range=192.168.1.0,proxy,255.255.255.0
dhcp-option=vendor:PXEClient,6,2b
dhcp-no-override
pxe-service=x86PC, "Boot from network", /pxelinux
enable-tftp
tftp-root=/srv/archlinux
log-dhcp
$ service dnsmasq restart
However, the default Arch Linux image has its boot configuration elsewhere than the pxelinux.cfg
, which PXE boot will automatically look for. This coupled with the obscure fact that dhcp-option-force
seems not to work when running proxyDHCP leaves no option but to manually configure the PXE-boot options of the image. One way of doing this is to just copy the contents of the image and modify them:
$ mkdir -p /srv/archlinux
$ mkdir /srv/archlinux/arch
$ cp -r /mnt/archlinux/arch/boot /srv/archlinux/
$ cp -r /mnt/archlinux/arch/x86_64 /srv/archlinux/arch/
$ cd /srv/archlinux
$ ln -s boot/syslinux/lpxelinux.0 pxelinux.0
$ mkdir pxelinux.cfg
$ ln -s ../boot/syslinux/archiso.cfg pxelinux.cfg/default
Finally, the root filesystem from the Arch image has to be transferred somehow. The options are HTTP, NFS and NBD. I opted for setting up a NFS share:
Raspberry:
$ service rpcbind restart # This was needed on my raspbmc
$ apt-get install nfs-kernel-server
$ tail -n1 /etc/exports
/srv/archlinux 192.168.1.0/24(ro,no_subtree_check)
You need to also point the PXE/NFS -mount to that folder:
$ grep -A10 arch64_nfs /srv/archlinux/boot/syslinux/archiso_pxe64.cfg
LABEL arch64_nfs
TEXT HELP
Boot the Arch Linux (x86_64) live medium (Using NFS).
It allows you to install Arch Linux or perform system maintenance.
ENDTEXT
MENU LABEL Boot Arch Linux (x86_64) (NFS)
LINUX boot/x86_64/vmlinuz
INITRD boot/intel_ucode.img,boot/x86_64/archiso.img
APPEND archisobasedir=arch archiso_nfs_srv=${pxeserver}:/srv/archlinux
SYSAPPEND 3
Now if you boot over PXE, you should eventually be awarded with a ‘Welcome to Arch Linux!’ message. Alternatively, you can debug/test the PXE boot with QEMU.