Monday, November 9, 2009

Example Preseed file tutorial for Debian Lenny PXEboot Server

 The Default File
The next step for our PXE Server (for the previous step see here) is to make an option for an automated deployment.  This is especially useful in a production environment as you can network boot a computer, feed the appropriate options in the command line and walk away, with entire confidence that the OS will install flawlessly.  Now for the preseed file to work correctly the default file needs to be edited (again, see here). 

If you inspect the file above you will notice the line that is used for the preseed.cfg file, which must be one line, but is broken in this example for formatting. :
LABEL lenny_i386_autoinstall kernel debian/lenny/i386/linux append ramdisk_size=14984 locale=en_US console-setup/layoutcode=en_US netcfg/wireless_wep= netcfg/choose_interface=eth0 netcfg/get_hostname=DebianServer netcfg/get_domain= console-keymaps-at/keymap=us url=http://IP ADDRESS/pxescripts/preseed.cfg initrd=debian/lenny/i386/initrd.gz --
Alright, lets break a little bit of this down.  In order for our auto installation scheme to work, there need to be some options passed on directly to the kernel, and lets go over a few of them.
1. ramdisk_size - stores some execution space in the RAM, speeds things up.
2. locale=en_US and console-setup/layoutcode=en_US - setting US English as the default language
3. netcfg/wireless_wep - I believe this is for a wireless password, but not entirely sure.
4. netcfg/choose_interface - This allows you to chose the network interface that will be used
5. netcfg/get_hostname - allows you to set the hostname of the machine.
6. netcfg/get_domain - allows you to set the domain of the computer
7. console-keymaps-at/keymap - allows you to set the keyboard mapping
8. url=http://IP ADDRESS/PATH/preseed.cfg - specifies where the preseed.cfg file can be found.
Now you will notice that many of these are defined in the default file... if I wasn't lazy, and this was a work environment, it would be better to manually enter at least one of these, namely netcfg/get_hostname.  This way I would not have to go back and change the hostname for almost all of the machines... a big time saver.  As well, you'll notice that to fetch the preseed.cfg file I used a http:// address.. I believe a ftp:// and file:// prefix will work as well.  Now, the reason these options all need to be passed on directly to the kernel is because many of these options are asked before the networking is configured.  So until the machines gets an IP address during installation (which is after the language is decided) the preseed.cfg file is not available to fill in the answers... so these options need to be directly passed onto the kernel.
The Preseed.cfg File


Now I will explain some of the more cryptic/hard to grasp elements of the preseed.cfg file
The first few lines set the installer language and keyboard layout... I don't think those are necessary, they should have passed directly to the kernel.  Next, I am telling the installer to automatically choose the interface to use.  The next few lines are not necessary, as we passed those on directly to the kernel.  The mirror settings section is very important, especially if (like me) you decided to cache (using apt-cache or apt-mirror) files to ease bandwidth traffic.  The first two lines select the country, and the directory string sets the distribution.  The proxy string is the key for making sure the files are pulled from your personal apt-cache.  As you can see, I'm pulling it from my web server, with the port for my apt-cache defined. Next, the suite specifies the version of the linux distro.  The partitioning can be difficult to set up, especially if your machines have one, two or more hard drives.  If the machine only has one hard drive, specifying a hard drive is not necessary.  Since one of my testing machines has two hard drives, I added the "d-i partman-auto/disk string /dev/hda", which specifies that the installer should use the first hard disk.  Next, after selecting lvm for the method, you can choose one of the pre-defined partitioning schemes.  The options are:
# - atomic: all files in one partition
# - home:   separate /home partition
# - multi:  separate /home, /usr, /var, and /tmp partitions
As you can see, I chose the atomic method.  For improved performance, you may want to choose one of the other methods.
Next, you can set up the user accounts and passwords.  The first thing you can do is set the root password.  In the example, the password is sent in clear test (it is masked in the example), but I certainly recommend you send the password as a MD5 hash.  To generate a MD5 hash, just run the following command:
$echo "password" | mkpasswd -s -H MD5
Next, you can choose the package that you want to install.  I chose the standard desktop install.
Essentially, that covers the trickier parts of the preseed.cfg file.  Happy automated installing!

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.