I’ve played around with PXE booting recently and came across an irritating problem. The PXELINUX documentation states that it should reboot the machine after an unsuccessful PXE boot. However, that wasn’t true for both mainboards I’ve tested it with (MSI B75IA-E33 and Dell 0X3GJK, found inside a Dell Vostro V131 laptop) – instead of rebooting, the BIOS continued to boot the next available medium (HDD in my case).
As I wanted the machine in question to exclusively use PXE during boot (even though it had a hard disk installed), I had to find a way around that unwanted BIOS behavior. It turned out that the easiest solution was to write a tiny piece of x86 assembly code which would simply reboot the machine. Such a “bootloader” would then be placed in the MBR of the disk that the BIOS tries to boot from after PXELINUX fails, resulting in a reboot loop which can only be interrupted by a successful PXE boot – which was exactly what I wanted. I quickly googled up the NASM code for rebooting the machine:
mov ax,0040h
mov ds,ax
mov word [0072h],0000h
jmp 0ffffh:0000h
To create a “bootloader”, simply save the code above to a file – I’ll assume further it’s called reboot.asm
– and then run the following command to compile it:
nasm -f bin reboot.asm
The resulting file will be called reboot
. Before actually writing it to the MBR, make sure you make a backup of the latter (I’ll assume further the disk in question is /dev/sda
):
dd if=/dev/sda of=/root/mbr.bin bs=512 count=1
You can now install the “bootloader” in the disk’s MBR:
dd if=reboot of=/dev/sda
From now on, whenever your BIOS tries to boot from that disk, your machine should be rebooted.
If you want to restore your previously used bootloader, just run the following:
dd if=/root/mbr.bin of=/dev/sda
I haven’t checked if other PXE bootloaders exhibit the same behavior as PXELINUX.