Debugging PXE boot with QEMU
In my earlier post, I defined the steps for setting up a PXE boot environment.
However, you might run into configuration problems and booting an actual machine is time-consuming for testing. My situation, for example, was that I could not get the Raspberry serving the PXE-protocol to respond to legitimate requests. I needed a better environment to debug the problem than booting my desktop for every iteration.
And here steps in QEMU. It’s a fine piece of computer science originally by Fabrice Bellard, enabling super-fast virtualization of machines.
The steps I did to procure a PXE-debugging environment in Arch Linux:
Install qemu, brctl:
$ pacman -S qemu
$ pacman -S brctl
Create a test QEMU image:
$ qemu-img create -f vmdk testpxe.vmdk 10
Configure bridged networking, to be used for the VM:
$ ip tuntap add dev virttap mode tap user $USER
$ brctl addbr virtbr
$ brctl addif virtbr enp2s0 # your LAN interface
$ brctl addif virtbr virttap
$ ip link set virtbr up
$ ip link set enp2s0 up
$ ip link set virttap up
Finally, launch the PXE-booting VM:
$ /usr/bin/qemu-system-x86_64 -m 1024 -hda testpxe.vmdk \
-boot n \
-option-rom /usr/share/qemu/pxe-rtl8139.rom \
-net nic \
-net tap,ifname=virttap,script=no,downscript=no
It should automatically try to boot over LAN (-boot n
).
By the way, my original problem was that my Raspberry’s firewall did not accept UDP packets. D’oh!
iptables -I INPUT -i $IFACE -p udp --dport 67:68 --sport 67:68 -j ACCEPT
Enables DHCP and the PXE-boot requests were allowed through.