Debootstrap gives us a simple and consistent way to cleanly setup machines by installing packages directly into a file system directly from the repos.  These have the flexibility of being used across many different kind of machines.

Create Directory Structure

Here we are just creating the directories into which we will be installing the operating systems into.

bash
mkdir -p /mnt/build/amd64 /mnt/build/i386
cd /mnt/build/amd64; mkdir ubuntu_10.04 ubuntu_10.10 ubuntu_11.04 ubuntu_11.10 debian_5 debian_6
cd /mnt/build/i386; mkdir ubuntu_10.04 ubuntu_10.10 ubuntu_11.04 ubuntu_11.10 debian_5 debian_6

Install Required Software

bash
apt-get install debootstrap

Install Operating Systems into the Folders

Ubuntu Lucid

http://us.archive.ubuntu.com

bash
debootstrap --arch=i386 --variant=minbase lucid /mnt/build/i386/ubuntu_10.04/ http://us.archive.ubuntu.com/ubuntu/
debootstrap --arch=amd64 --variant=minbase lucid /mnt/build/amd64/ubuntu_10.04/ http://us.archive.ubuntu.com/ubuntu/

Ubuntu Maverick

bash
debootstrap --arch=i386 --variant=minbase maverick /mnt/build/i386/ubuntu_10.10/ http://us.archive.ubuntu.com/ubuntu/
debootstrap --arch=amd64 --variant=minbase maverick /mnt/build/amd64/ubuntu_10.10/ http://us.archive.ubuntu.com/ubuntu/

Ubuntu Natty

bash
debootstrap --arch=i386 --variant=minbase natty /mnt/build/i386/ubuntu_11.04/ http://us.archive.ubuntu.com/ubuntu/
debootstrap --arch=amd64 --variant=minbase natty /mnt/build/amd64/ubuntu_11.04/ http://us.archive.ubuntu.com/ubuntu/

Ubuntu Oneiric

bash
debootstrap --arch=i386 --variant=minbase oneiric /mnt/build/i386/ubuntu_11.10/ http://us.archive.ubuntu.com/ubuntu/
debootstrap --arch=amd64 --variant=minbase oneiric /mnt/build/amd64/ubuntu_11.10/ http://us.archive.ubuntu.com/ubuntu/

Debian Lenny

bash
debootstrap --arch=i386 --variant=minbase lenny /mnt/build/i386/debian_5/ http://ftp.us.debian.org/debian/
debootstrap --arch=amd64 --variant=minbase lenny /mnt/build/amd64/debian_5/ http://ftp.us.debian.org/debian/

Debian Squeeze

bash
debootstrap --arch=i386 --variant=minbase squeeze /mnt/build/i386/debian_6/ http://ftp.us.debian.org/debian/
debootstrap --arch=amd64 --variant=minbase squeeze /mnt/build/amd64/debian_6/ http://ftp.us.debian.org/debian/

Enter the Newly Installed Environments using Chroot

Chroot or CHange ROOT allows us to enter a given folder and have that be our new operating environment.  It becomes a completely isolated enviornment with access only to the files and utilities which already exist within that operating environment.  You do not need to enter a chroot to modify files, but you will need to enter a chroot to install software packages.

bash
mount -o bind /proc /mnt/build/i386/ubuntu_10.04/proc/
chroot /mnt/build/i386/ubuntu_10.04

When you are ready to exit your environment and move to the next one, then break the chroot with exit, and then unmount proc.

Exiting the Chroot (not yet)

Before exiting make sure you make the appropriate modifications in the next section.

bash
exit
unmount /mnt/build/i386/ubuntu_10.04

You will then need to enter the other installed templates so that you can get them sorted out as well.

Make Modifications to Ubuntu Templates

When using apt-get to install software I noticed these errors on Ubuntu.

text
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
text
GPG error: http://ftp.utexas.edu lucid Release: Could not execute '/usr/bin/gpgv' to verify signature (is gpgv installed?)

The first error is simply a problem with the language pack.  We can fix it by running the following.

bash
apt-get install --reinstall language-pack-en

The second error didn’t occur on oneiric, but occurred on all older versions of Ubuntu I tried.  It can be fixed by running the following.

bash
apt-get install gpgv

In addition to running those commands, I also run the following as part of my preparations.

bash
apt-get update && apt-get upgrade
apt-get install vim aptitude

If you have any other modifications to make on your templates now is the time to do it.

Make Modifications to Debian Templates

On Debian we need to fix than locale error we received on ubuntu.

The problem…

text
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"

Although the fix is different.

bash
apt-get install locales
sed -i '/en_US.UTF-8/s/^#//' /etc/locale.gen
locale-gen en_US.UTF-8

I also run the following.

bash
apt-get update && apt-get upgrade
apt-get install vim aptitude

Create the Final Archives

Now we are going to tar gzip these things into there own little files so that we can simply extract as needed.  These commands will do the whole batch, instead of having to type each one manually.

text
cd /mnt/build/i386/; for a in `ls`; do echo -n $a; tar -czf "/mnt/build/"$a"_i386.tgz" -C $a .; echo "      done."; done
text
cd /mnt/build/amd64/; for a in `ls`; do echo -n $a; tar -czf "/mnt/build/"$a"_amd64.tgz" -C $a .; echo "      done."; done

Well that pretty much sorts it out for us.  Now we end up with a bunch of tgz files which can be extracted into a file system and used for whatever purpose we need to use them (lxc, openvz, vserver).