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
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

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 --save
vzctl set 110 --nameserver --save
vzctl set 110 --numothersock 120 --save

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

echo "deb dapper-updates main restricted" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb dapper universe" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb dapper-security main restricted" >> /var/lib/vz/private/110/etc/apt/sources.list
echo "deb 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
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
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:

8 Comment(s)

Add comment


From: Anonymous at: 2006-03-10 17:54:57

I tried befor the Xen tutorial from Falko but had some problems with compiling ACPI options in the Xen kernel.
This OpenVZ howto works right from the first time i set it up like you explained with the ACPI options compiled in the VZ kernel and everything. So i can shut off and WOL start the host system now too.
Installing the virtual systems is easy and fast. I'm a happy man hehe
Very cool Howto! Thanks!

From: Anonymous at: 2006-03-17 10:17:23

it should be

echo "deb stable openvz" >> /etc/apt/sources.list

From: Anonymous at: 2006-06-22 13:48:45


should be :


stable is missing...

From: Anonymous at: 2006-06-22 13:54:01

should be

From: Anonymous at: 2006-06-23 08:26:15


with the packages from I also hat the

arpsend: can't get iface 'eth0:' address : Cannot assign requested address

problem. The real problem is the ':'... Change /usr/share/vz/vps-functions with 

<       awk "/^[0-9].*:/&&/UP/ {print substr(\\$2, 0, length(\\$2))}"`
>       awk "/^[0-9].*:/&&/UP/ {print substr(\\$2, 0, length(\\$2)-1)}"`

and networking works as expected...


From: Anonymous at: 2006-07-03 21:18:53

please be careful:

from now the vzctl (>= 3.0.10-1dso1) depends on "gawk" not on the plain awk!

so there 's no need to change the source in "vps-functions" 

And if someone detected a "bug" please let me know :-)

Thorsten Schifferdecker


tsd [at]

see more at

From: Anonymous at: 2006-07-03 21:24:10

please be carefully:

from now the vzctl depends on gawk, so there is no need to modify the "vps-functions".

I've someone hit a bug in the debian packages ... please let me know :-)

Thorsten Schifferdecker


tsd [at]

or look at 


From: Anonymous at: 2006-05-26 02:19:57

Excellent, thank you, and hey, I *almost* understood it all, tho being a *nix newbie with only some ancient experience with ibm and sco-unix all I know these days is debian.

I had *some* trouble making the debian cache and template, apt-get got me the debootstrap util.
Rebuilding the kernel I used stab077 instead of stab064, that all went fine

The ubuntu bit was kinda annoying when the attraction to the document was that it was all debian sarge, but I got over it ;)

Id like my contribution to be this little script i wrote to simplify making a new VPS from a template down to one command plus some bulk starting/stopping stuff .

If its not posted here, its cause 'it looked suspicous' to the forum/comments parsing code on here.

Cheers and thanks