Performing an automated Ubuntu install using preseeding

When performing an automated Ubuntu install, preseeding is an integral part of the process. Learn the different variables and settings necessary for a basic preseed configuration.

Solutions provider takeaway : As a solutions provider, you should be looking for the easiest way to perform an automated Ubuntu install, and this chapter excerpt offers the required steps you should follow when using the preseeding automation method.

About the book:
This chapter excerpt on Automated Ubuntu Installs is taken from The Official Ubuntu Server Book. This book covers the best methods for an Ubuntu install, backup and step-by-step deployment. Read through information on optional security tools, fault tolerance and clustering and different troubleshooting techniques.

After you have gone through the Ubuntu Server install a few times, you start to realize that you generally pick the same options for a majority of the install no matter what type of server it is. It might be OK to manually enter install options when you have a single server to set up, but what if you have ten or a hundred? At some point you start to wish you could hire an intern or build a robot to press Next for you. While this might work, Ubuntu has provided a cheaper (free) option with two automated installation methods: preseeding and Kickstart. Preseeding is derived from the Debian Linux distribution, and Kickstart has been ported from Red Hat and is called Kickseed under Ubuntu. Both have their advantages and shortcomings, and in fact the recommended method of automating Ubuntu server installs is a combination of both.

In this chapter I will cover both automation methods and how to use them to supplement a CD-ROM install. Finally, I will show how to use Kickstart and preseeding together for a fully automated installer over the network. By the end you will be able to set up one or a hundred Ubuntu servers with about the same amount of effort. Then your robot can focus on more important tasks like bringing you coffee.

There are two different ways you can read this chapter. I discuss preseeding first because it is the classic way to automate Debian and Ubuntu installs, and even if you Kickstart servers you will often need to supplement it with preseed values. So if you are interested in how the entire process works and fits together, you should read the chapter straight through. This will provide you with a good foundation on preseeding so that when you learn about Kickstart you can truly see how it eases the process. On the other hand, if you just want to get started with an automated installer, I recommend skipping ahead to the Kickstart section in the chapter. There is a lot of useful information in the preseed section, but preseeding is a pretty vast and complex topic, especially if you are new to it. If you just want to get things working on a basic automated install, you will want to use Kickstart. The Kickstart section will get you up and running, and then if you need to do anything that isn't yet possible in Kickstart, you can return to the preseeding section.

Preseeding

The concept behind preseeding is pretty simple. Every possible option in the Ubuntu install is represented by a variable. Once you discover what those variables are, you can set them ahead of time in a file and instruct the Ubuntu installer to load and apply them for you. The key to preseeding, of course, is to know what those values are. There are a number of good online guides for preseeding, but I've noticed that most of them, even those for Ubuntu, still seem to provide Debian-based examples.

The main way to discover all of the available preseeding options is to use debconf-get-selections. For instance, to find out all of the current preseed settings from your current install, you would run

$ debconf-get-selections --installer > alloptions.cfg

This would dump all of the installation-focused preseeding options into alloptions.cfg. The great thing about preseeding, though, is that it isn't limited to installer options—every package you install that asks you questions can have its answers preseeded. To dump the entire debconf database containing these values into the same alloptions.cfg file, run

debconf-get-selections >> alloptions.cfg

Now you might be tempted to simply use this alloptions.cfg file as your preseed.cfg file. The problem is that this file contains all of the configuration options, including many that should not be preseeded. Use this file only as a guide when you want to discover a particular preseeding option that you want to set; instead I recommend that you start with the base preseed.cfg I will provide below and tweak that.

Basic Preseed Configuration for CD-ROM

There are a few different ways to introduce preseeding options to the installer, but probably the simplest way is to use the default Ubuntu install CD while specifying options directly at the boot prompt and putting a preseed.cfg file full of options on a local Web server. It turns out that if you are going to use preseeding by itself, there are certain options that you can't set strictly in a preseed file—either they must go on the boot prompt, or you will have to answer the questions manually.

The first step is to set up a default preseed.cfg file. Below is a basic preseed file that describes a default Ubuntu server install for a system in the United States. Copy these settings into a file named preseed.cfg:

## Options to set on the command line
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

d-i netcfg/choose_interface select auto
d-i netcfg/wireless_wep string

d-i base-installer/kernel/override-image string linux-server
d-i clock-setup/utc-auto boolean true
d-i clock-setup/utc boolean true
d-i time/zone string US/Pacific
d-i clock-setup/ntp boolean true

d-i mirror/country string US
d-i mirror/http/proxy string
d-i pkgsel/install-language-support boolean false
tasksel tasksel/first multiselect standard, ubuntu-server

d-i partman-auto/method string regular
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-lvm/confirm boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i passwd/user-fullname string Ubuntu User
d-i passwd/username string ubuntu
d-i passwd/user-password password insecure
d-i passwd/user-password-again password insecure

d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i finish-install/reboot_in_progress note

Keep in mind that with these default settings the installer will find the first disk it can, format over it, and install the base system on top of it, so make sure before you try this on a server that you are willing to lose all of the data on its disks. Otherwise, if you do want to preserve data on a server, be sure to first check out the Partitioning section below to find out how to tweak the default settings.

Once you have set up the preseed.cfg file, put it on a local Web server that your test server can access. For this example let's assume the server is at www.example.net and you put the file in the main document root so it can be found at www.example.net/preseed.cfg. Now boot the server on which you wish to install Ubuntu off of the Ubuntu Server install CD. Once you answer the language prompt, hit F6 so you can edit the default boot arguments, as shown in Figure 4-1. Use the arrow keys to move to the left past the initrd= argument and backspace over the file=/cdrom/preseed/ ubuntu-server.seed section of the prompt. That is actually Ubuntu's own preseed file that it uses for the install, but we will replace it with our own. To do that we use the url option to point to our Web server, so type

url=http://www.example.net/preseed.cfg

Figure 4-1 Ubuntu install boot screen with boot arguments

Of course, change that to point to the path to your actual Web server and preseed file. Unfortunately we will need to specify a few extra options on the command line so the installer can get past the initial phase of the install, get on the network, and retrieve the rest of its settings. If you look at the top of my example preseed.cfg file, you will see that I set apart a few options to go on the boot prompt:

d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain

To add these to the boot prompt, just type the full path to a particular option (such as debian-installer/locale), an = sign, and then the option to set it to. After you are finished, your complete boot prompt, including all the options that were there before that you need to keep, will look like this:

url=http://www.example.net/preseed.cfg
debian-installer/locale=en_US console-setup/ask_detect=false
console-setup/layoutcode=us
netcfg/get_hostname=unassigned-hostname
netcfg/get_domain=unassigned-domain
initrd=/install/initrd.gz quiet --

Now that's quite a bit of typing, but Ubuntu has provided some shorthand for some of the options. For instance, debian-installer/locale can be replaced with just locale, netcfg/get_hostname can be replaced with hostname, and netcfg/get_domain can be replaced with domain. With all of the shortcuts in place the command line looks a bit more manageable:

url=http://www.example.net/preseed.cfg locale=en_US
console-setup/ask_detect=false console-setup/layoutcode=us
hostname=unassigned-hostname domain=unassigned-domain
initrd=/install/initrd.gz quiet --

About the authors:
Kyle Rankin is a senior system administrator for Quinstreet Inc., and the current president of the North Bay Linux Users' Group. He has also authored Ubuntu Hacks.

Benjamin Mako Hill is on the Ubuntu Community Council governance board and on the founding Ubuntu team. Mako Hill is in charge of helping to grow the Ubuntu development and user community during its first year. He has also published The Official Ubuntu Book.

Once you have typed all of these values into the boot prompt, press Enter and go get a cup of coffee. The installer should get its own IP address over DHCP, retrieve the preseed.cfg file from your Web server, complete the install, and then reboot. When you get back, you should be welcomed with a default Ubuntu login prompt. Of course, if everything didn't go smoothly, you might see, for instance, an error retrieving the preseed.cfg file. If that is the case, try retrieving the same file from a Web browser on the same network and make sure your path is correct and your Web server is configured correctly.

Other things that might halt the installation process could be the installer not being able to get a DHCP lease or, as is most often the case, a mistake in the preseed.cfg file. As you will discover, a good preseed file is something you get after a lot of trial and error. When you set an option incorrectly, the installer will simply stop at that point in the install and prompt you for that particular option. As you create more sophisticated preseed.cfg files, you might run through the same install multiple times before you get it exactly right.

The default preseed.cfg I listed above will get you started, but where do you go from there? Below I will dig into each of the main configuration categories and explain how to customize the default preseed.cfg file for your needs.

Networking Options

In my sample preseed.cfg I introduced the following networking options:

d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string unassigned-domain
d-i netcfg/choose_interface select auto
d-i netcfg/wireless_wep string

The first two options I used on the boot prompt with their aliases hostname and domain to set the hostname and domain, respectively, for this machine. The choose_interface option allows you to choose which network interface to use on the machine for the install. In my case I chose auto, which will pick the first interface that has link, if possible. Instead of choosing auto, you could also set this option to a specific interface, such as eth1. Now if eth1 were a wireless card and your wireless network uses WEP, you could use the wireless_wep option to set the WEP key. Even though I didn't use a wireless connection in my example, I still set this to a dummy value so I wouldn't get prompted for a WEP key during the install.

Printed with permission from Prentice Hall Inc. Copyright 2009. The Official Ubuntu Server Book by Kyle Rankin and Benjamin Mako Hill. For more information about this title and other similar books, please visit https://www.informit.com/.

Dig Deeper on MSP business strategy

MicroScope
Security
Storage
Networking
Cloud Computing
Data Management
Business Analytics
Close