Speeding up PXE image transfer!

WARNING: This article was written 11 years ago, it may contain informations that are no longer valid.

At work I’m using a PXE boot system that make available all my favorite utilities (Avira Rescue CD, Memtest, Bart PE, and so on) just using network.

For years I’ve been stuck using just pxelinux.0 (from Syslinux) to create a menu and boot other systems. Pxelinux by itself support only TFTP transfer. And seriously, it’s SLOW.

Now, I don’t want to talk about how to create and setup all the system, but only how to speed the transfer of images, starting with an already working system (a dhcp server, pxelinux.0, and a tftp server).

Sadly, working in a computer shop, I don’t wanna fix other things at home, so for years I have followed the philosophy “If it works, why change it?”. But a night I stumbled in a link at etherboot.org, the homepage of gPXE. It was talking about “httpboot”. It made me think a lot. TFTP is a old way for transfer, it hasn’t any checksum because is over UDP. Http should be better, as stated on the site:

“HTTP can handle much larger files than TFTP, and scale to much larger distances. You can easily download multi-megabyte files, such as a Linux kernel and a root filesystem, and you can download from servers that are not on your local area network. We have successfully tested booting across the Atlantic using HTTP!”

Also you can pass some parameters via GET request to a PHP script that makes you boot something different by time, ip address, mac address, user and password check….  Yumm! Tasty.

Let’s go!

I mainly use Windows system, and I don’t want to get my hands dirty with some compiling. In this case, ROM-o-matic comes useful. I downloaded a UNDIONLY KPXE image, customizing it by including this script (just copied and pasted from examples at that link):

echo Performing DHCP on first network interface
dhcp net0
set 209:string pxelinux.cfg/default
set 210:string http://example.com/
chain ${210:string}pxelinux.0

Also I started a small webserver, lighttpd, it’s already compiled for Win32 enviroments (so much love <3) serving files from the same folder of TFTPD.

Then I changed my dhcp option 67 (Boot file name) to reflect the name of the .kpxe rom I downloaded from ROM-o-matic, and tried to boot.

Holy cow! IT WORKS! And it’s A LOT FASTER than TFTPD.

What is happening?

  • The PXE ROM of the network card boots the gPXE ROM
  • gPXE ROM:
    – ask for an IP address
    – set DHCP option 209 (for pxelinux this is the config file file path, so pxelinux will not have to try all the mac-address filenames and end up with “pxelinux.cfg/default”)
    – set DHCP option 210 (it’s the TFTP prefix for pxelinux. So when it ask any file, it prefixs the name with http://example.com/. And thanks to gPXE it can really ask it via HTTP!)
  • Calls pxelinux.0 and let him the honor of booting

But, two drawbacks:

  1. The DHCP request is made two time: one by the PXE ROM embedded in the ethernet card, another when the gPXE rom starts (see the “dhcp net0” line in the script)
  2. Press CtrlB to configure gPXE… appears everytime it boots, and it stays on screen for a few seconds. Precious seconds of NOTHING HAPPENING. I hate that.

Let’s fix this.

Googling for days I found that gPXE is no longer “really opensource”.  Reading some sites I learned that, for some reason I don’t know, from 2010, the “real opensource” and mantained project now is iPXE.

I liked it after reading one of the FAQs:

Q: What does the “i” in “iPXE” stand for?
A: It doesn’t.

Oh my god. Open source, updated, and with sense of humor. Instant download. I prefer it to gPXE because it’s more documented. But it hasn’t any ROM-o-matic. So this time, i must dirty my hands compiling. I created a virtual Debian Net Inst and installed all the utility required to compile, using apt-get:

  • gcc (version 3 or later)
  • binutils (version 2.16 or later)
  • make
  • perl

and also syslinux-common (it’s not stated on the website but it is necessary!) then I prepared all the stuff with:

git clone git://git.ipxe.org/ipxe.git

Now I can compile a ROM! Yay!

First of all I must write a file containing the script to embed. I named it myscript.ipxe. Then, for making the bootable rom:

make bin/undionly.kpxe EMBED=myscript.ipxe

And voilà! An updated an well documented version of.. the same gPXE stuff.
It works in the same way, but this time no prompt “Press CtrlB to configure gPXE…” well, PROBLEM 2 SOLVED.

The rom still asking for a new IP addres via DHCP. Reading the documentation at http://ipxe.org/cmd and the settings at http://ipxe.org/cfg, I found an option, called use-cached. It tells iPXE to use the already assigned IP address instead of asking a new one.

I tryed to edit the script in myscript.ipxe like this:

set use-cached 1
dhcp net0
set 209:string pxelinux.cfg/default
set 210:string http://example.com/
chain ${210:string}pxelinux.0


But the iPXE rom is always asking for an IP address. Days of googling and I found this: http://lists.ipxe.org/pipermail/ipxe-devel/2011-May/000687.html

It states that for use-cached to work it’s needed the .kkpxe file, that keeps the PXE stacks in to memory.

So this time I compiled it using

make bin/undionly.kkpxe EMBED=myscript.ipxe

Trasferred it to my PXE main folder, setted up the DHCP Boot Filename, and… voilà! It’s fast as hell. PROBLEM 1 SOLVED.

It’s like having only pxelinux.0 but in the background there is the power of HTTP transfer.

I’m very happy with this, and I wish someone will find this article and try it too!

A good looking and detailed explaination how this works can be found at http://jpmens.net/2011/07/18/network-booting-machines-over-http/. The only thing it miss is the use-cached stuff.

Feel free to contact me for everything you want to know, using the About section of this site ;)

Categorie: Tech

2 commenti

  1. article is great!
    but do you have made tests with lpxelinux.0? which is modern pxelinux with http(and other protocols) support?

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.