Automating an Ubuntu Server Install

Posted by jtopjian on July 7, 2010 under Administration | 2 Comments to Read

Introduction

Updated for Ubuntu 10.04 LTS

While the installation procedure for Ubuntu Server is simple enough, I wanted to create a total hands-free solution. Doing so would allow me to simply boot a new PC or Virtual Machine and have a working Ubuntu Server in 10 minutes or so. The solution I came up with involves creating a master install server that uses several technologies such as dhcp, tftp, apache, and apt-cacher.

The Install Server

I used Ubuntu 10.04 LTS for the Install Server. It will be configured to distribute Ubuntu 10.04 LTS Server to the clients that connect to it.

As a side note, it should be quite possible to simultaneously distribute other Linux distributions using the same Install Server.

My install server is actually a VMWare Virtual Machine. I’m using VMWare Fusion 3 on my Mac. The virtual machine has two NICs: one on my Bridged network on one on a host-only network. This will allow me to create installs in a virtual sandbox environment.

In order to set up this type of environment, first create a new virtual machine with two NICs:

  • eth0: 192.168.0.0
  • eth1: 192.168.255.0

Next, configure the server as a gateway. Read the ufw Masquerading section here. Don’t forget to change DEFAULT_INPUT_POLICY to ACCEPT as well.

Finally, if you are doing this with VMWare Fusion on a Mac, ensure the VMWare host-only DHCP server is not running:

$ sudo kill -15 `sudo cat /var/run/vmnet-dhcpd-vmnet1.pid`

The Boot Process

Almost all modern PCs are able to be booted without a bootable media via PXE. Instead of booting from media, the PC will attempt to contact a DHCP server for its booting instructions.

Creating a PXE-supported DHCP and TFTP server is extremely easy with dnsmasq.

First, install dnsmasq:

$ apt-get install dnsmasq

Next, configure it. The /etc/dnsmasq.conf config file is very well documented — just follow through and read the settings. For reference, here is my config:

bogus-priv
filterwin2k
interface=eth1
dhcp-range=192.168.255.50,192.168.255.150,12h
dhcp-boot=pxelinux.0
enable-tftp
tftp-root=/var/ftpd
dhcp-authoritative

Next, copy the PXE files supplied with the Ubuntu 10.04 ISO:

$ sudo cp -r /media/cdrom/install/netboot/* /var/ftpd/

Once you have completed this step, you should be able to boot a PC or Virtual Machine to the Ubuntu Installer.

Utilizing an Answer File

The next step is to automate the answers to the Ubuntu Installer questions. Since Ubuntu is based off of Debian, it supports Debian’s Preseeding feature. However, I chose to use a kickstart formatted answer file since it’s more widely used. Ironically I still had to use a Preseed file to get this whole project working, but I will explain that later.

Again, Ubuntu has an official page (and here) describing its Kickstart compatibility. Here is a great article describing how to create a Kickstart file. It also provides a sample file in case you just want to copy a working one.

Once you have your Kickstart file, you’ll need to put it somewhere so the PXE-booted clients can access it. The easiest way is to just install Apache and put it in the default Document Root:

$ apt-get install apache2
$ mkdir /var/www/ubuntu
$ cp ks.cfg /var/www/ubuntu

Next, modify the PXE boot screen so the booted clients read the Kickstart file. This is described in the Ubuntu PXE Document under Use your ks.cfg.

To ensure the PXE-client is reading the Kickstart file, keep an eye on the Apache logs:

$ tail -f /var/log/apache2/access.log

You should see something like so:

192.168.255.84 - - [07/Jul/2010:11:20:13 -0600] "GET /ubuntu/ks.cfg HTTP/1.1" 200 1320 "-" "Wget"

Caching the Packages

At this point, you should be able to boot a PXE-client, have it retrieve an answer file, then start to automatically download a fresh copy of Ubuntu 10.04 LTS from whichever mirror you specified in your Kickstart file. This is great because it’ll also install all updated packages so there’s no need to update your system once it’s done.

On the downside, if you create 10 automated servers, they will always download the same packages from across the Internet each time. A better solution would be to cache the packages so only the first PXE-client downloads the package and any other PXE-client will pull the package from the cache — saving both time and bandwidth.

apt-cacher is a solid Apt proxy and it’s very easy to set up. To install, simply do:

$ apt-get install apt-cacher

Then edit /etc/default/apt-cacher to enable it:

AUTOSTART=1

Next, edit /etc/apt-cacher/apt-cacher.conf and add a path_map entry:

path_map = ubuntu us.archive.ubuntu.com/ubuntu

Finally, update your ks.cfg file to point to your apt-cacher proxy:

url --url http://192.168.255.1:3142/ubuntu

You can ensure it’s working by watching the apt-cacher log file during an install:

$ tail -f /var/log/apt-cacher/access.log 

Installing Only the Server Packages

The final step to this project is to tell the installer to install the Server version of Ubuntu and not the Desktop version. This is where the Preseed file I mentioned earlier comes in.

On the Ubuntu Server CD is a preseed file called ubuntu-server.seed located in /media/cdrom/preseed/. Copy this file to the Apache Document Root:

$ cp /media/cdrom/preseed/ubuntu-server.seed /var/www/ubuntu

Next, edit the /var/ftpd/pxelinux.cfg/default and in the same area where you added the Kickstart information, add this:

preseed/url=http://10.0.0.1/ubuntu-server.seed

For reference, the entire /var/ftpd/pxelinux.cfg/default file should look something like this:

label linux
    kernel ubuntu-installer/amd64/linux
    append ks=http://192.168.255.1/ubuntu/ks.cfg preseed/url=http://192.168.255.1/ubuntu/ubuntu-server.seed vga=normal initrd=ubuntu-installer/amd64/initrd.gz -- quiet

Now boot a PXE-client and in 10 minutes you should have a fully functional Ubuntu 10.04 LTS install.

Conclusion

This solution allows you to create a working Ubuntu 10.04 LTS install without the use of a CDROM or having to answer any questions during the install.

About Joe:
Joe Topjian is the owner of Terrarum -- a system administration company that specializes in Linux Infrastructure and Automation. More information about Terrarum can be found here.
Website:http://terrarum.net
Jabber:joe@topjian.net
  • Cobbler » Terrarum said,

    [...] surface, I’ve found it to be extremely worthwhile to learn and definitely supersedes my previous deployment [...]

  • Deploying Ubuntu with Cobbler » Terrarum said,

    [...] it to utilize a kickstart file to automate responses. I had been doing this for quite some time without Cobbler, so I knew it had to be an issue internal to [...]

Add A Comment