Before reading this post it may be useful to know you can download our own created Ubuntu 9.04 Jaunty image created using these instructions from our OpenVZ and Xen VPS OS templates for HyperVM page.
As always, instructions will be brief. If you feel I have missed out some important detail, feel free to comment and I *may* update the article.
First create and mount a 10GB ext3 filesystem for our image:
sudo lvcreate -L 10G -n template.modernadmin.com-disk VolGroup00
sudo mkfs.ext3 /dev/VolGroup00/template.modernadmin.com-disk
sudo mkdir /mnt/tmp
sudo mount /dev/VolGroup00/template.modernadmin.com-disk /mnt/tmp
Next, we install debootstrap. Since version 1.0.10-2.fc11+ has dependency problems on CentOS 5.3, we’ll use an older version I have mirrored here:
wget http://www.modernadmin.com/downloads/ostemplates/debootstrap-1.0.10-1.fc10.noarch.rpm
sudo rpm -Uvh debootstrap-1.0.10-1.fc10.noarch.rpm
Since jaunty specific scripts are not in this release of debootstrap, lets copy from gutsy:
sudo cp /usr/share/debootstrap/scripts/gutsy /usr/share/debootstrap/scripts/jaunty
Now install jaunty into /mnt/tmp using debootstrap:
sudo debootstrap --include=udev,ssh,quota --arch amd64 jaunty /mnt/tmp http://uk.archive.ubuntu.com/ubuntu/
We need to copy modules into the template – these will be specific to your Xen host node(s). In our case we have a few custom sets, but for now we only want the latest version:
sudo cp -dpR /lib/modules/2.6.18-128.1.6.el5xen /mnt/tmp/lib/modules/
Populate the sources.list file for apt-get:
sudo cat <<EOF > /mnt/tmp/etc/apt/sources.list
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty main restricted universe multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty main restricted universe
deb http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted universe multiverse
deb-src http://gb.archive.ubuntu.com/ubuntu/ jaunty-updates main restricted universe
deb http://security.ubuntu.com/ubuntu jaunty-security main restricted universe
deb-src http://security.ubuntu.com/ubuntu jaunty-security main restricted universe
EOF
Create a temporary interface which will be removed later on. Also populate some other required files:
sudo cat <<EOF > /mnt/tmp/etc/network/interfaces
auto eth0 lo
iface eth0 inet static
address 95.154.208.250
netmask 255.255.255.0
up route add -net 95.154.208.0 netmask 255.255.255.0 dev eth0
up route add default gw 95.154.208.1
iface lo inet loopback
EOF
sudo cat <<EOF > /mnt/tmp/etc/hosts
127.0.0.1 localhost template.modernadmin.com
EOF
sudo cat <<EOF > /mnt/tmp/etc/hostname
template.modernadmin.com
EOF
sudo cat <<EOF > /mnt/tmp/etc/fstab
proc /proc proc defaults 0 0
devpts /dev/pts devpts defaults 0 1
/dev/sda2 none swap sw 0 1
/dev/sda1 / ext3 errors=remount-ro 0 1
EOF
sudo cat <<EOF > /mnt/tmp/etc/event.d/xvc0
start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/getty 38400 xvc0
EOF
sudo rm -rf /mnt/tmp/etc/event.d/tty1
sudo echo “alias eth0 xennet” > /mnt/tmp/etc/modprobe.d/xen
#echo “xvc0″ >> /mnt/tmp/etc/securetty
sudo cat /dev/null > /mnt/tmp/etc/udev/rules.d/70-persistent-net.rules
This next section is completely optional. We will install DenyHosts and any other custom packages to further secure the virtual machines by default.
First, chroot to the new template and set a root password:
sudo chroot /mnt/tmp
passwd root
Exit the chroot and unmount the template from the host node:
exit
sudo umount /mnt/tmp
Start the VM:
sudo xm create template.modernadmin.com.cfg -c
Inside the Xen domU you have just started, install denyhosts, configure as required and then shutdown:
apt-get -y update
apt-get -y upgrade
apt-get -y install denyhosts
apt-get -y clean
shutdown -h now
This step is also optional and only applies if you started the VPS as above and is simply a cleanup step:
sudo mount /dev/VolGroup00/template.modernadmin.com-disk /mnt/tmp
sudo rm -f /mnt/tmp/etc/ssh/ssh_host_*
sudo cat << EOF > /mnt/tmp/etc/rc2.d/S15ssh_gen_host_keys
#!/bin/bash
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ”
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ”
rm -f \$0
EOF
sudo chmod a+x /mnt/tmp/etc/rc2.d/S15ssh_gen_host_keys
sudo cat <<EOF > /mnt/tmp/etc/network/interfaces
# loopback interface
auto lo
iface lo inet loopback
EOF
sudo cat /dev/null > /mnt/tmp/var/log/apt/term.log
sudo cat /dev/null > /mnt/tmp/var/log/auth.log
sudo cat /dev/null > /mnt/tmp/var/log/boot
sudo cat /dev/null > /mnt/tmp/var/log/bootstrap.log
sudo cat /dev/null > /mnt/tmp/var/log/btmp
sudo cat /dev/null > /mnt/tmp/var/log/daemon.log
sudo cat /dev/null > /mnt/tmp/var/log/debug
sudo cat /dev/null > /mnt/tmp/var/log/denyhosts
sudo cat /dev/null > /mnt/tmp/var/log/dmesg
sudo rm -rf /mnt/tmp/var/log/dmesg.*
sudo cat /dev/null > /mnt/tmp/var/log/dpkg.log
sudo cat /dev/null > /mnt/tmp/var/log/faillog
sudo rm -rf /mnt/tmp/var/log/fsck/*
sudo cat /dev/null > /mnt/tmp/var/log/kern.log
sudo cat /dev/null > /mnt/tmp/var/log/lastlog
sudo cat /dev/null > /mnt/tmp/var/log/lpr.log
sudo cat /dev/null > /mnt/tmp/var/log/mail.err
sudo cat /dev/null > /mnt/tmp/var/log/mail.info
sudo cat /dev/null > /mnt/tmp/var/log/mail.log
sudo cat /dev/null > /mnt/tmp/var/log/mail.warn
sudo cat /dev/null > /mnt/tmp/var/log/messages
sudo cat /dev/null > /mnt/tmp/var/log/pycentral.log
sudo cat /dev/null > /mnt/tmp/var/log/syslog
sudo cat /dev/null > /mnt/tmp/var/log/udev
sudo cat /dev/null > /mnt/tmp/var/log/user.log
sudo cat /dev/null > /mnt/tmp/var/log/wtmp
sudo cat /dev/null > /mnt/tmp/root/.bash_history
sudo cat /dev/null > /mnt/tmp/etc/udev/rules.d/70-persistent-net.rules
Finally, package the system into a .tar.gz and you are good to go!
cd /mnt/tmp
sudo tar czf /home/hypervm/xen/template/ubuntu-9.04-x86_64-modernadmin.tar.gz .
sudo chmod 755 /home/hypervm/xen/template/ubuntu-9.04-x86_64-modernadmin.tar.gz
Feel free to reproduce this article elsewhere but please give ModernAdmin.com credit where possible. A link back to our site goes a long way and would be greatly appreciated!