Building A Virtual Server (VPS) With Debian 3.1 (Sarge) And OpenVZ - Page 3

3 Build Your Own Ubuntu OpenVZ Virtual Private Server Template

First install the debootstrap utility from Ubuntu. This allows us to bootstrap Debian Sarge and Ubuntu installations.

cd /tmp
wget http://archive.ubuntulinux.org/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.3.0ubuntu3_all.deb
dpkg -i debootstrap_0.3.3.0ubuntu3_all.deb

Now we bootstrap the Ubuntu installation. I use the VPS ID 110. You can use any ID, as long as it is unused on the server and > 100.

debootstrap --arch i386 dapper /var/lib/vz/private/110 http://archive.ubuntulinux.org/ubuntu

Apply the basic configuration to the VPS:

vzctl set 110 --applyconfig vps.basic --save

Set the name of the template:

echo "OSTEMPLATE=ubuntu-6.06" >> /etc/vz/conf/110.conf

Set the IP and nameserver. If you get this warning: "Warning: configuration file for distribution ubuntu-6.06 not found default used", ignore it.

vzctl set 110 --ipadd 192.168.0.169 --save
vzctl set 110 --nameserver 192.168.0.2 --save
vzctl set 110 --numothersock 120 --save

Add some additional package sources to the sources.list of the VPS:

echo "deb http://archive.ubuntulinux.org/ubuntu dapper-updates main restricted" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb http://archive.ubuntulinux.org/ubuntu dapper universe" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu dapper-security main restricted" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb http://security.ubuntu.com/ubuntu dapper-security universe" >> /var/lib/vz/private/110/etc/apt/sources.list

Start the VPS:

vzctl start 110

Update the system:

vzctl exec 110 apt-get update
vzctl exec 110 apt-get -u upgrade
vzctl exec 110 apt-get install ssh libedit2 openssh-client openssh-server quota

Disable gettys on terminals:

vzctl exec 110 sed -i -e '/getty/d' /etc/inittab

Fix some mounts:

vzctl exec 110 rm -f /etc/mtab
vzctl exec 110 ln -s /proc/mounts /etc/mtab

Run apt-get clean to remove unnecessary packages:

vzctl exec 110 apt-get clean

Stop the VPS and remove the IP addresses:

vzctl set 110 --ipdel all --save
vzctl stop 110

Delete the SSH host keys and create a script thet generates new host keys on first boot of the VPS:

rm -f /var/lib/vz/private/110/etc/ssh/ssh_host_*
cat << EOF > /var/lib/vz/private/110/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
chmod a+x /var/lib/vz/private/110/etc/rc2.d/S15ssh_gen_host_keys

Pack the VPS to make it easily installable:

cd /var/lib/vz/private/110
tar czf /var/lib/vz/template/cache/ubuntu-6.06-minimal.tar.gz .

Hint: The dot in the line above is part of the command! It reads ....tar.gz[space][dot]

Now we remove the VPS we used to setup the template:

vzctl destroy 110

To create an instance of our Ubuntu server template, you can use this command:

vzctl create 102 --ostemplate ubuntu-6.06-minimal --config vps.basic

and then follow the other steps described in chapter 2.

4 Links

All trademarks are the property of their respective owners. OpenVZ and Virtuozzo are trademarks of SWSoft.

Share this page:

0 Comment(s)