Using gPXE to alter boot configuration with Server Side Scripting

April 2009


gPXE is a PXE boot loader that supports HTTP. This makes it possible for a client to be booted with what the server thinks is appropriate, based on whatever information we like to make it depend on. gPXE is actually meant to be put in a BOOT ROM, but a gPXE bootstrap can be chainloaded onto a standard NIC with onboard PXE support using a DHCP and a TFTP server. The basic setup also describes other DHCP servers, but the Linux case in short is:

  1. Prepare the TFTP server

    Roughly:

    apt-get -y install tftpd-hpa
    mkdir /var/lib/tftpboot/tftpboot
    scp ~/tmp/syslinux-3.75/gpxe/src/bin/undionly.kpxe !$

  2. Configure dhcpd.conf

    group gpxe
      {
      if substring (option vendor-class-identifier, 0, 9) = "PXEClient"
        {
          allow booting;
          next-server 129.125.36.36;
          filename "undionly.kpxe"; # This file compiled from the newest PXELinux source
        }
      if exists user-class and option user-class = "gPXE"
        {
          filename "http://my.domain.com/pub/boot/boot.php";
        }
      
      host sandbox  { hardware ethernet 00:11:22:33:44:55 ; fixed-address 192.168.65.43 ; }
      
      } # end group gpxe