Monday, November 2, 2009

Tutorial, Howto setup Debian Lenny Linux PXEboot Server with DD-WRT DHCP options

Recently, I decided it was time to drop the CD/DVD installs of linux and move to something easier and quicker (although that is debateable).  As well, a few of my computers have no disc drive and switching disc drives from computer to computer gets very old very quickly.  As well, if a computer has a slimline drive opening the case to temporarily add a CD/DVD drive is too much work.  I finally decided to install a PXE server on my debian box, to allow network booting. Networking booting is an extremely handy way to install operating systems, boot to recovery tools, ect.
 Installing and Configuring a Tftp Server
The first thing we need to do is install a tftp server. The tftp server will be used to serve the files to the computer that is booting up. To install a tftpd server on debian we do this from the command prompt:
$sudo apt-get install tftpd-hpa
When you install the tftpd-hpa server, a few dialogs should come up. Just make sure you set the correct path for the server root. The newest version of tftpd-hpa is different than the older version, but since I'm running the cutting edge, I will be covering the newest version. After configuration, we will need to make sure the config file is setup correctly. If you ever need to reconfigure the file just run the following command:
$ sudo dpkg-reconfigure tftpd-hpa
Now to take a look at the config file:
$sudo nano /etc/default/tftpd-hpa 
The config file should appear as follows: Ensure that the "TFTP_DIRECTORY = /var/lib/tftpboot" directory is the correct path to your tftpboot directory. Everything else should be correct.
 Creating the Directory Structure/Downloading the Files
Now we need to create the directory structure necessary for PXEboot.  First, create the directory /var/lib/tftpboot.  Next we will be creating several files and directories.  When we are finished, the directory structure will look as follows. 

Next, we need to download the appropriate initrd.gz, linux, and pxelinux.0 files, which can be found several places.. such as here.  In the newest version of debian PXEboot, they have a GUI bootable version, however I decided to stick with a text boot version, and this tutorial will be about that option.  Once the initrd.gz, linux, and pxelinux.0 files have downloaded, put them in the appropriate folders.  In my configuration, I also have a xen folder for booting and installing a xen server, but that is not covered here.  If you are interested, the xen boot option should be available for download from the download link above.
 Creating the Menus and Defining Options
 Next we need to create the default and the boot.txt files.  The boot.txt file is the menu that shows up when you boot the computer.. in this example it will be a text only file.  The configuration of the file is extremely simple.  The only part you need to pay close attention to is the exact wording of the boot options.    
Next, we need to create the default file, which links to the boot.txt file.  The default file should look something like this:



The text box is not wrapped, to prove a point. Everything entered after the append option must be on one line, otherwise it will not work.  The labels in the default file must match the labels in the boot.txt as that is how the files are linked.  Obviously, you can add new labels to the default file, as long as you match it with the boot file.  I added the lenny_i386_autoinstall label, which will hopefully be covered later.  The DISPLAY option tells the PXEboot server what file to display for the menu.  The DEFAULT option tells the PXEboot server which label is the default label, which works well in conjunction with the TIMEOUT option.  The TIMEOUT option is by default zero (no time limit) but in my configuration I set a timeout of 40 seconds, which means that in 40 seconds of no activity, the DEFAULT option will be booted.
DHCP Server Options
However, there is still one piece of the puzzle missing.  You need a network booted machine to know where to look for the PXEboot server.  This sort of configuration will need to be passed to the machine via DHCP options.  In this instance, I will be using a router with dd-wrt installed to pass the DHCP options to the client.  Since dd-wrt is linux based, the command should be quite similar if you are using a linux DHCP server.  With dd-wrt make sure that you are using DNSMasq for DHCP, which can be found directly under the setup tab.



Next, you will need to add the option that will tell the client where to look for the server and what server to look for when network booting.  The option is configured under the DNSMasq box (not the DHCPd option, which may appear more relevant).  The format for the dhcp-boot option is: dhcp-boot=filename,servername,ipaddress


The filname option is what the name of the file is that the PXEclient should look for... in this case, that file is pxelinux.0.  The servername is not necessary... as you can see I left it out.  However, the commas are necessary.

Troubleshooting
For troubleshooting, I recommend you install Wireshark to sniff network traffic.  It is a very useful tool.  Next, a few common troubleshooting methods for narrowing down the problem.
Ensure the TFTP server is working.  If your client is unable to find the pxelinux.0 file, make sure you can tftp files from any machine (even from the machine that your tftp server is installed on).  This error could be cause by an incorrect tftp boot path, or the tftp server is not running.
Ensure that your network card/BIOS is PXEbootable.  An obvious problem, sometimes upgrading the BIOS will solve this.
 If all else fails, sniff the network traffic.  Use Wireshark to sniff the network traffic, this will help troubleshoot problems.
Hopefully soon I will cover using a preseed.cfg file to do an automated network boot and install. 

No comments:

Post a Comment