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.
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_6Install Required Software
apt-get install debootstrapInstall Operating Systems into the Folders
Ubuntu Lucid
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
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
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
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
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
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.
mount -o bind /proc /mnt/build/i386/ubuntu_10.04/proc/
chroot /mnt/build/i386/ubuntu_10.04When 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.
exit
unmount /mnt/build/i386/ubuntu_10.04You 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.
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"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.
apt-get install --reinstall language-pack-enThe 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.
apt-get install gpgvIn addition to running those commands, I also run the following as part of my preparations.
apt-get update && apt-get upgrade
apt-get install vim aptitudeIf 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…
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"Although the fix is different.
apt-get install locales
sed -i '/en_US.UTF-8/s/^#//' /etc/locale.gen
locale-gen en_US.UTF-8I also run the following.
apt-get update && apt-get upgrade
apt-get install vim aptitudeCreate 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.
cd /mnt/build/i386/; for a in `ls`; do echo -n $a; tar -czf "/mnt/build/"$a"_i386.tgz" -C $a .; echo " done."; donecd /mnt/build/amd64/; for a in `ls`; do echo -n $a; tar -czf "/mnt/build/"$a"_amd64.tgz" -C $a .; echo " done."; doneWell 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).