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:

8 Comment(s)

Add comment

Comments

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 http://debian.systs.org/ stable openvz" >> /etc/apt/sources.list

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

wget http://download.openvz.org/kernel/022stab064.1/patches/patch-022stab064-combined.gz

should be :

wget http://download.openvz.org/kernel/stable/022stab064.1/patches/patch-022stab064-combined.gz

stable is missing...

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

http://download.openvz.org/kernel/022stab064.1/configs/kernel-2.6.8-022stab064-i686.config.ovz

should be

http://download.openvz.org/kernel/stable/022stab064.1/configs/kernel-2.6.8-022stab064-i686.config.ovz

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

Hi, 

with the packages from debian.systs.org 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 

100c97
<       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] debian.systs.org

see more at http://debian.systs.org/

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] debian.systs.org

or look at http://debian.systs.org/ 

 

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