PXE Booting
From Wiki
Most network PXE booting HOWTOs are useless from what I've seen. They either involve using another device to boot (CD, floppy, HD, etc.), didn't tell me what was going on behind the scenes, used BOOTP, or simply wasn't what I wanted. So here's this one.
You want to follow this document to setup the base of PXE network booting, and then one of the following documents to setup a specific linux distro to boot, or make your own. =)
Contents |
Introduction
PXE booting is one of the many ways you can boot a computer (or embedded device, or just about anything, possibly a toaster even) entirely from the network without any form of storage on the destination computer (RAM aside). It can be used for most anything. You can run a complete OS off the network using just the RAM, or you can mass-install/update an OS stored on the local hard disk. This HOWTO will get the core of PXE booting setup, and from there you can use one of the above links to setup a specific distro.
Needed Hardware
Your average home hardware router will 100% not work. Quite a few high-end home routers will not work. The PXE client has to receive an additional DHCP option that 99% of the routers you've seen do not support. I can't say I've ever touched a Cisco router, but chances are decent that it'll support PXE booting. Read the next section for a little more detail as to why. For a list of hardware that has what's needed to do PXE booting, see PXE Capable Hardware.
PXE Boot Process
1. PXE client boots up, starts up PXE boot ROM.
2. The PXE boot ROM sends a DHCP request.
3. The responding DHCP request (should) contain an additional DHCP option, the "filename" options. (This is why the average hardware router won't work. You can't specify the needed options.)
4. The PXE client attempts to download the file specified over TFTP. (If not specified, the client tries to connect to the computer that gave it the DHCP lease. If the "next-server" param is specified, it will instead attempt to download the file off of that server. Note that DNS is not available here, so it must be an IP address. There is no way around this.)
5. If the PXE client downloads the file, it then executes this file and from there PXE is out of the picture. That's the entire PXE process.
6. If any of the above steps fail, the computer should continue on with the boot process.
Used Software
dhcpd - the ISC DHCP server
PXELINUX - PXELINUX is a PXE boot loader, most commonly used to boot linux kernels over PXE (also see my modified pxelinux.0)
tftp-hpa - tftp server, which is used to obtain the needed config files, kernel, and depending, the initrd.
memtest86 - memtest86 is a very simplistic "OS" that we'll use just to ensure that PXE booting itself is working correctly - Memtest86
Installing Software on the Image Server
I'll keep this brief, and do it later. You need to install dhcpd and tftp-hpa, and just have pxelinux and memtest86 resident somewhere on the disk for later.
Configuring Software
DHCP
DHCPd
The DHCP configuration on most other HOWTOs have been ranging anywhere from 20 lines with no documentation, to a single line with documentation. I'll try and say what's needed and document it well.
DHCPd is setup with the "dhcpd.conf" file, commonly residing in your /etc directory.
First, my example setup.
ddns-update-style interim;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.254;
default-lease-time 3600;
max-lease-time 4800;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "l.brantleyonline.com";
option time-offset -7;
option ntp-servers 192.168.0.1;
option netbios-name-servers 192.168.0.1;
}
host kyle {
hardware ethernet 00:0C:6E:64:D8:B4;
fixed-address 192.168.0.254;
option host-name "kyle";
filename "pxelinux.0";
next-server 192.168.0.1;
}
We have two main blocks here, the subnet block
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.254;
default-lease-time 3600;
max-lease-time 4800;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "l.brantleyonline.com";
option time-offset -7;
option ntp-servers 192.168.0.1;
option netbios-name-servers 192.168.0.1;
}
and the host block.
host kyle {
hardware ethernet 00:0C:6E:64:D8:B4;
fixed-address 192.168.0.254;
option host-name "kyle";
filename "pxelinux.0";
next-server 192.168.0.1;
}
For now, we'll concentrate on the host block, namely two parameters it takes. The "filename" and the "next-server", as these two are PXE-specific. next-server specifies which server (IP address only) to contact (via tftp) in order to download the next stage of the boot phase. Note that if you do not specify the next-server, then it will default to the IP address of the DHCP server where it obtained its IP address from. However, some motherboards seem to send packets to 0.0.0.0 and you might get a "martian destination" error in system log if you don't specify "next-server". The filename paramater specifies which file to download off of the specified tftp server, and then executed.
Now, as you can see, only the computer with the MAC address 00:0C:6E:64:D8:B4 is instructed to download the pxelinux.0 file and execute it. If you were to deploy this over an entire subnet, it'd be a tedious task to create host blocks for every computer. Likewise, the following is perfectly valid.
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.254;
default-lease-time 3600;
max-lease-time 4800;
option routers 192.168.0.1;
option domain-name-servers 192.168.0.1;
option subnet-mask 255.255.255.0;
option domain-name "l.brantleyonline.com";
option time-offset -7;
option ntp-servers 192.168.0.1;
option netbios-name-servers 192.168.0.1;
filename "pxelinux.0";
next-server 192.168.0.1;
}
This would instruct every client that obtained a DHCP address in this subnet to download pxelinux.0 from 192.168.0.1 and then execute it (remember, that the next-server option is not required).
That's the basic dhcp setup required here. Either designate a single (or multiple) host to PXE boot by adding the filename parameter to its host block, or an entire subnet by adding it to its subnet block.
Remember to start your dhcp server (or restart) also :). Port 67/udp should be open when it's running, and likewise in order for the clients to obtain an address, be sure that this port is open to any client that may need it.
tftp-hpa
To install tftp-hpa, I used gentoo's emerge command and then changed things as needed.
in /etc/conf.d/in.tftpd:
INTFTPD_PATH="/srv/diskless"
INTFTPD_OPTS="-l -v -s ${INTFTPD_PATH}"
Note that the -v in this case is optional, but it may help with debugging later on. The INTFTPD_PATH is simply a path which your tftp server will serve files out of, nothing more. It won't typically contain anything other than a few configuration files, kernels, and initrd's, so not much space is needed, and it can be stored pretty much anywhere.
After making these changes, I started it up with /etc/init.d/in.tftpd start. At this point, 69/udp should be open. 69/udp is the tftp port (surprise) and likewise it is very important that this port is reachable by your clients.
pxelinux
Introduction
pxelinux is part of the SYSLINUX package. Once installed, just copy the pxelinux.0 file over to your tftp server directory. At this point, you should be able to use a tftp client and download pxelinux.0. If this fails, a lot of tftp servers are permissions-paranoid, so try setting the file permissions on pxelinux.0 to something more world readable.
In the same directory where you placed pxelinux.0, make a directory called "pxelinux.cfg". Based on the suffix of that directory, you can guess that this contains the needed config files.
First, obtain your MAC address (of the NIC which will be used to PXE boot). This can be obtained a variety of ways, but probably the easiest way is just ifconfig.
eth0 Link encap:Ethernet HWaddr 00:0C:6E:64:D8:B4
inet addr:192.168.0.254 Bcast:192.168.0.255 Mask:255.255.255.0
It's the "HWaddr" param that you're looking for. With this, create a file in the pxelinux.cfg directory named "01-00-0c-6e-64-d8-b4". Note that this is the MAC address of the interface, in lowercase, separated by dashes, prefixed with "01-". Why? pxelinux looks for config files in the following order:
pxelinux.cfg/01-00-0c-6e-64-d8-b4
pxelinux.cfg/C0A800FE
pxelinux.cfg/C0A800F
pxelinux.cfg/C0A800
pxelinux.cfg/C0A80
pxelinux.cfg/C0A8
pxelinux.cfg/C0A
pxelinux.cfg/C0
pxelinux.cfg/C
pxelinux.cfg/default
If you're wondering just where I got the "C0A800FE" string, the answer to that is simple. It's the IP address that the client obtained, in hex. This is easily obtained by the gethostip command.
kyle@olorin ~/ $ gethostip 192.168.0.254 192.168.0.254 192.168.0.254 C0A800FE
Note the last bit, "C0A800FE". This is the IP address 192.168.0.254 in hex. pxelinux will search for the corresponding MAC address file first, then the IP in hex, one letter at a time (to cover a very large range of IPs, for example), and then default. It sounds complex at first, but the idea is simple. A few examples to explain this concept.
-If you know the MAC address that will be PXE booting, and they're few in number, just make their own config files. Simple, effective, it works. -Say you needed to network boot an entire /24 subnet without recording their MAC addresses. This is made simple also. If the subnet was 192.168.54.0/24, you'd use the gethostip to convert 192.168.54 to hex, and it would come out as C0A836. If you create a config file named "C0A836" in the pxelinux.cfg/ directory now, assuming that the client isn't matched before (by MAC address, or more specific hex IP), that entire /24 block will use the C0A80036 config file. -Remember the order! It checks for MAC address, then a specified IP subnet range, and then it reverts to the default config file (aptly named default). This means that if you have a config file for an entire subnet, but if it finds a MAC address (or more specific IP-in-hex) match, that will be used instead. This can be useful for singling out a single computer by MAC, or IP, or most anything.
Creating the configuration files
I've always hated the configuration files, just due to how a majority of them were spaced. It made them look like mud and not much else to me. Note that per-line spacing is arbitrary (line breaks are not, though), but I'll be spacing these in order to make them more readable.
My default config file currently as follows.
prompt 1
default memtest86
timeout 1000
label memtest86
kernel memtest86
Possibly the only option here that's a little obscure is the prompt option. If you set it to one, the client gets the "boot: " prompt. Set it to 0, it doesn't. Defaults to 0 if not set.
default is the default option to execute, and timeout is how long it takes (in tenths of seconds) before executing the default option. Fairly simple stuff.
Now, on to the label part. "label memtest86" is simply a label for the kernel. At the boot prompt (and in the default option), the label is input and the kernel for that label is booted.
prompt 1
default memtest86
timeout 150
label memtest86
kernel memtest86
label memtest
kernel memtest86
In this case, I can choose to boot either "memtest86" or "memtest" at the boot prompt, but it'll still execute the kernel "memtest86". For now, this (or the previous) config file is a good copy and paste drop in for testing, so unless you know what you're doing now, just save it as pxelinux.cfg/default.
Testing
memtest86
You'll want the bootable version of memtest86 placed in the same directory as pxelinux.0. This should be a ~80K file, which file reports to be an "x86 boot sector". You can usually obtain this from most any distro, or you can find more info here.
Client setup
First off, your client must support PXE booting in one way, shape, or form. My primary computer supports PXE booting with its onboard NIC. You can buy PXE-compliant NICs for $10 (or so I hear), you can make a floppy to utilize PXE, or a CD, or even install it on your hard drive. End result, you'll know when your computer is booting PXE when it requests an IP address before an OS boots up. This is a good thing =).
An example for an HP NC6220 Laptop is: to activate the network adapter for boot via PXE you have to enable it in BIOS:
Set Security -> Device security -> Internal network adapter boot to Enable and Boot mode to PXE.
As well as Advanced -> Boot options -> MultiBoot to Enable and Notebook Ethernet to your First boot device.
Making a pxe boot image with a menu to load a bigger image
Download ftp://ftp.3com.com/pub/nic/3c90x/util430.exe and extract Imgedit.exe
Actual testing
Example filesystem setup:
/srv/diskless
/srv/diskless/pxelinux.cfg
/srv/diskless/pxelinux.cfg/default
/srv/diskless/pxelinux.0
/srv/diskless/memtest86
The /srv/diskless path should be the TFTP server's root directory that you set in the configuration file, so that a client can connect and request "pxelinux.0" without hassle. Also note that the DHCP server should be handing out leases with at least one additional option, the filename option, which instructs the PXE client to download that file. Double-check your dhcp, tftp, and pxelinux config files, make sure it's all running, and then fire up a PXE client. If all goes well, you should be presented first with a pxelinux setup screen which brings up a "boot: " prompt. Press enter and memtest86 should fire up.
When Things Go Wrong
FAQ
Read the PXE FAQ.
When all else fails
1. CHECK YOUR LOGS! READ THE ERROR MESSAGES! RETRACE YOUR STEPS, AND GOOGLE!
2. IRC is a wonderful place. irc://irc.freenode.net/pxe is where I'll be most of the time.
Categories: Linux | PXE
