You are on page 1of 5

Network boot operating systems with gPXE

Download this article as a single PDF document

Contents
1 Introduction 2 Required software 3 Installation 4 Configuration 4.1 How to setup the DHCP server 4.2 How to setup the TFTP server 4.3 How to setup gPXE 5 Starting services 6 Testing 7 Screenshots 8 Links

Introduction
gPXE is a new version of the well know Etherboot project. The project created network booting code that allows computers to load their operating system from a network. The code can be stored in a number of places, including BIOS Flash, EPROMs, floppy, CD, HD, or other bootable media.

Required software
Software used for this howto: Ubuntu Linux 9.04 gPXE 1.0.1: http://etherboot.org/wiki/download SysLinux 3.86: http://syslinux.zytor.com/ Internet Systems Consortium DHCP server V3.1.1 - http://www.isc.org TFTP server from Linux NetKit - http://www.hcs.harvard.edu/~dholland/computers/netkit.html NOTE: Although I used Linux in this HowTo you can use any O.S running DHCP and TFTP servers to make this work. My boot server at home runs NetBSD and works great. All you need is the compiled gPXE binary.

NOTE 2: gPXE was forked and the new project can be found at: http://ipxe.org/

Installation
Run following commands to install TFTP and DHCP servers:
# apt-get install tftpd # apt-get install dhcp3-server

Download tarball of gPXE from http://kernel.org/pub/software/utils/boot/gpxe/gpxe-1.0.1.tar.gz Extract it and compile:


# tar zxf gpxe-1.0.1.tar.gz # cd gpxe-1.0.1/src # make

The file we need is called undionly.kpxe and you can find it in


# gpxe-1.0.1/src/bin/undionly.kpxe

Configuration
How to setup the DHCP server
Edit the config file:
/etc/dhcp3/dhcpd.conf

so it looks like this:


allow booting; allow bootp; ddns-update-style none; log-facility local7; default-lease-time -1; max-lease-time 7200; authoritative; option space gpxe; option gpxe-encap-opts code 175 = encapsulate gpxe; option gpxe.bus-id code 177 = string; subnet 192.168.1.0 netmask 255.255.255.0 { use-host-decl-names on; range 192.168.1.26 192.168.1.30; option routers 192.168.1.1; option broadcast-address 192.168.1.255; option root-path "192.168.1.1:/home/tftpboot/"; next-server 192.168.1.1; if not exists gpxe.bus-id { filename "gpxe/undionly.kpxe"; } else { # filename "http://192.168.1.1/boot/boot.php"; filename "gpxe/menu.gpxe"; } server-name "lapdance"; server-identifier 192.168.1.1; }

I will not be going into details here. This config file is using the "conventional TFTP" configuration with /home/tftpboot as it's relative root directory fetching all the files from there. The subnet definition will hand out IPs for our clients from defined range. PXE booting your client it will first download the gPXE binary which will "take over" from there and download it's own configuration file. The if not exists gpxe.bus-id option is used to first hand out the undionly.kpxe file to PXE and then the menu.gpxe configuration file to gPXE.

Note: Notice the filename "http://192.168.1.1/boot/boot.php"; option. It allows you to fetch config from a HTTP server. It can be a dymamically created config or a simple txt file as menu.gpxe but downloaded over HTTP. For more info read http://etherboot.org/wiki/appnotes/authmenus

How to setup the TFTP server


The TFTP server will run as inetd service. Therefor we have to edit /etc/inetd.conf so it looks like this:
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /home/tftpboot

How to setup gPXE


Create directory for our files:
/home/tftpboot/gpxe

And create there a text file called menu.gpxe looking as follows:


#!gpxe chain menu.c32 menu.cfg

This file is going to chain load menu.c32 and our menu config file. You can replace menu.c32 with vesamenu.c32 for a more fancy boot window. As mentioned above, to be able to create a boot menu for gPXE we will need either menu.c32 or vesamenu.c32 file which are distributed with SysLinux. To obtain one of the files download tarball of SysLinux: http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.86.tar.gz Unpack it and go to the menu directory:
syslinux-3.86/com32/menu/

There you will find two files, menu.c32 and vesamenu.c32. The first one can be used to create simple CLI menus and the last one alows to create more "fancy" graphical menus. The menu.c32 works well over serial cable and we will use it in this HowTo.

Copy syslinux-3.86/com32/menu/menu.c32 and gpxe-1.0.1/src/bin/undionly.kpx to /home/tftpboot/gpxe You can also copy syslinux-3.86/com32/mboot/mboot.c32 to /home/tftpboot/gpxe as this file is used to netboot i.e. FreeBSD and NetBSD.

Now create a config file for our boot menu and call it menu.cfg (still in /home/tftpboot/gpxe directory). It will look like this:
PROMPT 0 ALLOWOPTIONS 0 MENU ROWS 6 MENU TITLE PLEASE CHOSE A SYSTEM TO BOOT LABEL MENU LABEL NETBOOT MENU DISABLE LABEL SuSe MENU LABEL ^1 SUSE MENU INDENT 1 KERNEL vmlinuz-suse APPEND ro root=/dev/hda1 initrd=initrd-suse.img MENU SEPARATOR LABEL MENU LABEL DEBIAN MENU DISABLE LABEL DEBIAN MENU LABEL ^1 DEBIAN MENU INDENT 1 KERNEL vmlinuz-debian APPEND ro root=/dev/hda1 initrd=initrd-debian.img LABEL UBUNTU MENU LABEL ^2 UBUNTU MENU INDENT 1 KERNEL vmlinuz-ubuntu APPEND ro root=/dev/hda1 initrd=initrd-ubuntu.img

The options are described here: http://syslinux.zytor.com/wiki/index.php/SYSLINUX How to create bootable Linux images is out of scope of this HowTo.

Starting services
Now we need to start the TFTP and DHCP services To start the inetd server:
# /etc/init.d/openbsd-inetd start

The DHCP server:


#/etc/init.d/dhcp3-server start

Testing
Boot your computer using PXE network booting. If all went you should be able to see message about DHCP address and then gPXE will get downloaded and show a menu on your screen.

Screenshots
And some screenshots. Loading of gPXE with VirtualBox : Initial boot with PXE/gPXE:

An example of gPXE menu:

Links
http://etherboot.org/wiki/appnotes http://syslinux.zytor.com/wiki/index.php/Comboot/menu.c32 http://syslinux.zytor.com/wiki/index.php/SYSLINUX

That's all folks! YazzY

miltonlab said ... 18:05, 11 January 2010 (CET) Interesting... I will prove it and then comment more YazzY said ... 15:01, 14 January 2010 (CET) Nothing to "prove", really. I'm using it very often and it works :) miltonlab said ... 16:51, 26 January 2010 (CET) Where i find the operating system images (*.img or others) for boot with gPXE? YazzY said ... 23:51, 10 February 2010 (CET) Try ploplinux or tinycore or any install kernel of a BSD should do. Fortrix said ... 17:06, 14 November 2010 (CET) The only thing that I couldn't find anywhere and therefore had to grab the parts of the info from different sites - that is what should I do to boot via pure HTTP using kernel and initramfs images from a server far far away, therefore with no TFTP usage. And that is quite simple. 1. Grab latest tarball from http://kernel.org/pub/software/utils/boot/gpxe/ and unpack it. 2. Go to src directory in the tarball and create a text file here (for example, netboot.gpxe) with such contents: 1. !gpxe dhcp net0 initrd http://server.org/path/to/initramfs.gz kernel http://server.org/path/to/kernel/bzImage boot bzImage (Of course, replace the address paths of the initrd and kernel to the valid ones) 3. Compile the gPXE USB image using the command: make EMBEDDED_IMAGE=netboot.gpxe bin/gpxe.usb 4. You have the bootable harddisk image in bin/gpxe.usb file now, so write the image to the USB stick via dd or other tool, or create a bootloader entry to it, or just boot a virtual machine from this harddisk image to check if the boot is working. 5. Now, if you have a working wired Internet connection and your provider uses DHCP to give you IP address (and you're using no other mechanisms for Internet access such as PPTP, L2TP or PPPoE), you will be able to boot the specified kernel and initramfs via HTTP successfully. For the current gPXE version (1.0.1) the resulting gpxe.usb image is just 336 kilobytes. I think this is the ultimate tool for truly cloud computing. Fortrix said ... 17:09, 14 November 2010 (CET) As newlines in the comments can't show correctly here, I'll repost the netboot.gpxe file contents: [newline]#!gpxe [newline]dhcp net0 [newline]initrd http://server.org/path/to/initramfs.gz [newline]kernel http://server.org/path/to/kernel/bzImage [newline]boot bzImage Muthu said ... 15:23, 8 February 2011 (CET) Thanks Yazzy for those wonderful steps.. In our setup, I need to install OSes rather than boot the OSes thru gPXE. Can you pls tel me what I need to change for OS installs? YazzY said ... 18:12, 7 March 2011 (CET) Muthu: You just need an install kernel or a kernel and initrd and maybe a kickstart or autoyast config file or whatever your Linux distro uses to automatically configure the system. YazzY said ... 18:16, 7 March 2011 (CET) Fortrix: The example of the dhcpd.conf file in the howto has a commented out line with http in it. It lets you use http or ftp to fetch image files instead of tftp. More info is available on the website of the gpxe project.

You might also like