Automating an Ubuntu Server Install

2joe28th Feb 2009Administration, , , ,

Introduction

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 8.04 LTS for the Install Server. It will be configured to distribute Ubuntu 8.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.

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 relatively easy. Ubuntu has an official document detailing the steps involved.

Please note, however, that there is a bug in the CDROM-supplied PXE files. When you get to the following step:

sudo cp -r /media/cdrom/install/netboot/* /var/lib/tftpboot/

Instead, download the updated files to the /var/lib/tftpboot/ directory. By not doing so, you will see an error message during the install about not being able to read the Apt repository. If you retry the failed step, the install continues, but this breaks the hands-free solution I’m aiming for.

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
cp ks.cfg /var/www/

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:

10.0.0.199 - - [26/Feb/2009:15:29:42 -0700] "GET /ks.cfg HTTP/1.1" 200 1008 "-" "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 8.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. Debuntu.org has a great article on how to do this.

Once you have apt-cacher running, modify your Kickstart file and change the install location to your Install Server.

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

Next, edit the /var/lib/tftpboot/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

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

Conclusion

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

I plan on improving on this solution soon by integrating Puppet into the install. Stay tuned.

2 Comments Comments Feed

  1. alex (May 14, 2009, 10:09 am).

    Hey mate. how did you manage to use apt-cacher in your kickstart file? i have it setup and working just not sure how to use it as a mirror during kickstart.

    cheers, alex.

  2. joe (May 19, 2009, 8:58 am).

    Hi Alex,

    I have this entry in my kickstart file:

    url –url http://10.0.0.1:3142/us.archive.ubuntu.com/ubuntu

    Hope that helps!

Add a Comment