PXE is a method for booting an operating system over a network, it stands for Pre-Executable environment. Here I will show you how to build a PXE server to boot and or install operating systems over your network.

Installing the server OS

I made this server inside VMWare, however the steps are the same if you are using a different virtual machine server or a physical machine. I used Debian 5.0 and used the net-install iso. Since we will only be needing a bare Debian install and just a few extra packages there is no need to download/install the entire OS.

Once you boot the installer follow all the installation prompts and enter the values that apply to you (language/timezone/password/etc). When taksel runs I would recommend you unselect all the options to get the smallest install possible.

tasksel in debain

After this the installation will finish, the computer will reboot and you will be presented with a login prompt.

Installing and Setting up the required Services

Now that you have a fresh install of Debian install the required packages

apt-get install tftpd-hpa dhcp3-server lftp

This will install the tfp server and a dhcp server. the two programs needed to load files over pxe. Next we need to configure the network to be static. edit /etc/network/interfaces and change the network configuration to something like this:

iface eth1 inet static
address 192.168.1.6
netmask 255.255.255.0
gateway 192.168.1.1

Now bring back up the network interface with ifdown eth0; ifup eth0 to have the new settings take effect.

Next we want to edit /etc/dhcp3/dhcpd.conf. this is the configuration file for the dhcp server. You can look at the default file to see how it is setup, but we don’t need it. replace it with:

allow booting;
allow bootp;

option domain-name-servers 192.168.1.1;
default-lease-time 86400;
max-lease-time 604800;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.200;
filename "pxelinux.0";
next-server 192.168.1.6;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
option routers 192.168.1.1;
}

This will configure your dhcp server to hand out addresses between 192.168.1.100-200, use a router of 192.168.1.1. And if the dhcp client asks the dhcp server for boot information it will tell it to load a file named pxelinux.0 from 192.168.1.6, which is our server. DHCP is now setup.

Now we need to edit the tftp settings. Edit /etc/default/tftpd-hpa. Change the RUN_DAMON to yes and change the options directory to /tftp, save and close the file. Noe run mkdir -p /tftp to create our tftp folder. this will be the server root.

Now start the PXE server with:

/etc/init.d/dhcp3-server start /etc/init.d/tftpd-hpa start

Setting up the PXE tftp folder

In the root of the tftp folder we need to have pxelinux.0. this is the file that our DHCP server tells the client to download. You can download the latest version from here: http://www.kernel.org/pub/linux/utils/boot/syslinux/ you will need pxelinux.0 found in the core folder of the zip. Place pxelinux.0 in the /tftp folder. Next create a pxelinux.cfg folder inside /tftp. And inside the pxelinux.cfg folder create a default file. This file will contain the boot information for clients if there is not a file that matched their MAC address. If there is one it would be in the pxelinux.cfg folder. Inside of default put:

DISPLAY boot.txt

DEFAULT debian_install

LABEL debian_installl
kernel debian/etch/i386/linux
append vga=normal initrd=debian/lenny/i386/initrd.gz

LABEL memtest
kernel memdisk
append initrd=memtest.img

LABEL DSL
kernel dsl/linux24
append ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=791 initrd=dsl/minirt24.gz nomce noapic quiet
BOOT_IMAGE=knoppix

PROMPT 1
TIMEOUT 0

And now create a boot.txt in your /tftpd folder with the following contents:

=PXE Boot Menu=
+++++++++++++++
options are:
debian_install
DSL
memtest

Now the boot.txt will be displayed allowing you to enter a label that is defined in default and it will boot that kernel with the given options. You can edit default and boot.txt however you like. In the examples iv given you have the option to install Debian, boot memtest, or boot damn small Linux. However we are still missing a vital part of the pxe server. We need the actual boot files. You can download the Debian files HERE The DSL and memtest files can be found on their appropriate websites.

Each boot option should go in its own folder inside the /tftp folder. In the above example Debian is in the Debian folder, dsl is in dsl. However because memtest is only a single file i put it directly in the tftpd root. Remember you must edit the default file to contain the correct boot arguments and kernel for what you are trying to boot.

Happy Network Booting!

PXE from Syslinux