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!

No comments:

Post a Comment