Automate Linux Installations with Debian Pre-Seeding (Part 2)
If you need to roll out a collection of servers or just want a way to get new ones in service quickly, Debian pre-seeding makes it easy. Here's how with CDs, floppies and USB sticks.
Plugging a new PC into your network, going out for a healthy walk, and returning to a completed operating system installation is one of life's little pleasures. Remember, laziness is a virtue in network administration. Hamsters spend their lives running the same circles. Network administrators automate repetitive tasks.
In last week's suspenseful installment we learned how to generate a quick 'n' dirty preseed configuration file for replicating a Debian installation, and how to perform a minimal custom installation with a USB stick. Today we'll cover how to start a network installation with either a newfangled USB stick or an oldfangled CD-ROM, or an even more antique 3.5" diskette.
Network Installation Options
If your BIOS and NIC support netbooting, you don't need a boot disk. You do need a TFTP and DHCP server, which are easy to set up. See Chapter 4.6. "Preparing Files for TFTP Net Booting" of the Etch installation manual.
To start a network installation from a CD-ROM, download the mini.iso image, which is about 8.7 megabytes.
I prefer to use a removeable boot device. That way I don't have to worry if the PC supports netbooting, and I don't have to hassle with changing the boot order in the BIOS after installation. The Etch installer supports all boot media: hard drive, diskette, CD/DVD, and USB sticks, and probably anything else you can cobble together, and you can find all the boot images you need on any Debian mirror.
Booting From a USB Stick
You need to go into the BIOS of your PC to enable booting from a USB stick. Make sure it is plugged in when you start up so the BIOS can detect it.
Network Installation With a USB Stick
Follow these steps to turn your sleek USB stick into a lean mean network installin' machine:
- Follow the instructions in Part 1 to re-partition and format the USB stick
- Extract the boot files to the USB stick, just like Part 1 shows
- Do not copy an .iso image to your USB stick
- Do copy your preseed.cfg file to your USB stick
- Finally, replace the initrd.gz image with a netboot initrd.gz image
To complete the last step, download a new initrd.gz from a Debian mirror, like mirrors.kernel.org. Make sure it comes from a netboot/debian-installer/*/2.6/ directory. Rename it to initrd26.gz and copy it to the USB stick. You need the netboot initrd.gz image, because the original one from boot.img.gz does not support a network installation, but instead requires local installation media.
Now when you boot up your USB stick, use the usual boot parameters as we learned in part 1:
linux26 preseed/file=/hd-media/preseed.cfg debconf/priority=critical
You'll walk through a few localization screens, configure networking, then be presented with a list of installation mirrors to choose from. Scroll up to the top to find the option for entering your own mirror. Tell it where it to find your local mirror, and let 'er rip. If your preseed file is configured correctly, the rest of the installation will be fully automatic.
This isn't completely hands-off, because the preseed file is not loaded until after the installation mirror is selected, so you still have to answer a few questions. To have a completely hands-off automatic installation requires either netbooting and loading all options from the network, or modifying initrd.gz. Here's a hint for modifying initrd: it's not that difficult, and you should use the newfangled Yaird- "Yet Another mkInitRD"- to do it.
Building a Local Debian Mirror
You'll need a local installation server. This can contain either a complete mirror of your desired Debian archives, or a partial mirror that caches only packages requested by clients on your network. A complete mirror requires anywhere from 10 to 40+ gigabytes of storage, depending on which archives you choose to mirror. You might want a complete mirror if you are continually trying out different builds and configurations, or if maximum installation speed is important. A partial mirror requires considerably less storage space, and is a good choice for network admins who don't need every last available package to be on site.
It is easy to create either type of local mirror. For creating a complete mirror, use the Apt-mirror command. For creating a partial mirror, use Apt-proxy. Both are easy to set up and use. You should be using apt-proxy anyway, to reduce the load on the official mirrors, and to speed up routine package installations and updates on your LAN.
Creating A Good Preseed File
A good starting point is to use the official example file. This is nicely-organized and easily adaptable to your own purposes. Creating one with the debconf-get-selections command (from part 1) is useful because you can copy and paste specific sections from it to get any extra packages you want.
The preseed file is used by the debconf-set-selections command, and requires these fields:
<owner> <queston name> <question type> <value>
Beware whitespace! The most common reason for preseed files not working correctly is wrong whitespace. There must be only a single space or tab between type and value. Use backslashes when you need to span a single line over several linebreaks. Check the syntax of your file with this command:
# debconf-set-selections -c preseed.cfg
Some Useful Installation Boot Options
When you pass in parameters at boot, always start with naming the kernel, which in my examples is linux26. linux24 selects the 2.4 kernel. To see all the different installation types, look in the syslinux.cfg file on your USB key. In fact you may put any boot parameters in this file, instead of entering them on the boot command line.
If you're installing Debian on a multi-homed box, like a Linux router, you should specify the correct interface to use at boot:
The Debian Installer automatically tries DHCP first. You can disable it this way if you prefer manual network configuration:
Turning off pcmcia services on laptops prevents a number of problems:
You may use any Debian installation media as a rescue disk:
We have covered a whole lot of ground in these two little articles. As you can see, the new Debian installer is very versatile, and with a bit of work will save you a lot of work.