Installing And Using OpenVZ On Debian Lenny (AMD64) - Page 2

Want to support HowtoForge? Become a subscriber!
Submitted by falko (Contact Author) (Forums) on Thu, 2009-02-26 19:40. ::

3 Using OpenVZ

Before we can create virtual machines with OpenVZ, we need to have a template for the distribution that we want to use in the virtual machines in the /var/lib/vz/template/cache directory. The virtual machines will be created from that template.

A few templates are available in the Lenny repository. Let's add that repository to /etc/apt/sources.list:

vi /etc/apt/sources.list

deb lenny openvz

Of course (in order not to mess up our system), we want to install packages from that repository only if there's no appropriate package from the official Lenny repositories - if there are packages from the official Lenny repositories and the OpenVZ repository, we want to install the one from the official Lenny repositories. To do this, we give packages from the official Lenny repositories a higher priority in /etc/apt/preferences:

vi /etc/apt/preferences

Package: *
Pin: release o=Debian
Pin-Priority: 700

Package: *
Pin: release lenny archive
Pin-Priority: 650


wget -q -O- | apt-key add - && apt-get update

afterwards to download the key of that repository and update the package database.


apt-cache search openvz

In the output you should see some Debian templates, e.g.:

vzctl-ostmpl-debian-4.0-amd64-minimal - OpenVZ - OS Template debian-4.0-amd64-minimal
vzctl-ostmpl-debian-4.0-i386-minimal - OpenVZ - OS Template debian-4.0-i386-minimal
vzctl-ostmpl-debian-5.0-amd64-minimal - OpenVZ - OS Template debian-5.0-amd64-minimal
vzctl-ostmpl-debian-5.0-i386-minimal - OpenVZ - OS Template debian-5.0-i386-minimal

Pick the templates that you need and install them as follows (the amd64 templates are not available on an i386 host):

apt-get install vzctl-ostmpl-debian-5.0-amd64-minimal vzctl-ostmpl-debian-4.0-amd64-minimal

You can use one of these templates, but you can also find a list of precreated templates on For example, instead of installing the vzctl-ostmpl-debian-5.0-amd64-minimal template with apt, we could as well download it as follows:

cd /var/lib/vz/template/cache

(If your host is an i386 system, you cannot use an amd64 template - you must use i386 templates then!)

I will now show you the basic commands for using OpenVZ.

To set up a VPS from the vzctl-ostmpl-debian-5.0-amd64-minimal template (you can find it in /var/lib/vz/template/cache), run:

vzctl create 101 --ostemplate debian-5.0-amd64-minimal --config vps.basic

The 101 must be a uniqe ID - each virtual machine must have its own unique ID. You can use the last part of the virtual machine's IP address for it. For example, if the virtual machine's IP address is, you use 101 as the ID.

If you want to have the vm started at boot, run

vzctl set 101 --onboot yes --save

To set a hostname and IP address for the vm, run:

vzctl set 101 --hostname --save
vzctl set 101 --ipadd --save

Next we set the number of sockets to 120 and assign a few nameservers to the vm:

vzctl set 101 --numothersock 120 --save
vzctl set 101 --nameserver --nameserver --save

(Instead of using the vzctl set commands, you can as well directly edit the vm's configuration file which is stored in the /etc/vz/conf directory. If the ID of the vm is 101, then the configuration file is /etc/vz/conf/101.conf.)

To start the vm, run

vzctl start 101

To set a root password for the vm, execute

vzctl exec 101 passwd

You can now either connect to the vm via SSH (e.g. with PuTTY), or you enter it as follows:

vzctl enter 101

To leave the vm's console, type


To stop a vm, run

vzctl stop 101

To restart a vm, run

vzctl restart 101

To delete a vm from the hard drive (it must be stopped before you can do this), run

vzctl destroy 101

To get a list of your vms and their statuses, run

vzlist -a

server1:~# vzlist -a
       101          8 running

To find out about the resources allocated to a vm, run

vzctl exec 101 cat /proc/user_beancounters

server1:~# vzctl exec 101 cat /proc/user_beancounters
Version: 2.5
       uid  resource           held    maxheld    barrier      limit    failcnt
      101:  kmemsize         500737     517142   11055923   11377049          0
            lockedpages           0          0        256        256          0
            privvmpages        2315       2337      65536      69632          0
            shmpages            640        640      21504      21504          0
            dummy                 0          0          0          0          0
            numproc               7          7        240        240          0
            physpages          1258       1289          0 2147483647          0
            vmguarpages           0          0      33792 2147483647          0
            oomguarpages       1258       1289      26112 2147483647          0
            numtcpsock            2          2        360        360          0
            numflock              1          1        188        206          0
            numpty                1          1         16         16          0
            numsiginfo            0          1        256        256          0
            tcpsndbuf         17856      17856    1720320    2703360          0
            tcprcvbuf         32768      32768    1720320    2703360          0
            othersockbuf       2232       2928    1126080    2097152          0
            dgramrcvbuf           0          0     262144     262144          0
            numothersock          1          3        120        120          0
            dcachesize            0          0    3409920    3624960          0
            numfile             189        189       9312       9312          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            10         10        128        128          0

The failcnt column is very important, it should contain only zeros; if it doesn't, this means that the vm needs more resources than are currently allocated to the vm. Open the vm's configuration file in /etc/vz/conf and raise the appropriate resource, then restart the vm.

To find out more about the vzctl command, run

man vzctl


4 Links

Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Daniel Vazart (not registered) on Thu, 2009-08-27 15:59.

*** Pay attention ! ***

The pakage linux-image-openvz-amd64 it's a meta package that will install linux-image-2.6.26-2-openvz-amd64 kernel, this version it's an unstable branch of OpenVZ that not includes some parametres like --cpus and --cpulimit for more information take a look at :

Submitted by Anonymous (not registered) on Sun, 2009-04-26 19:31.

Instead of editing the /etc/apt/source.list file, it would be better to create a file openvz-lenny.list in /etc/apt/sources.list.d/

The content of openvz-lenny.list could then be this:

# Add repository for Open VZ for Lenny

deb lenny openvz

# eof

You might even create the file and then just ask the user to do a

wget URL/openvz-lenny.list

and then let them copy it to /etc/apt/sources.list.d/ instead.

Submitted by Quasimodo's clone (not registered) on Sat, 2009-04-04 04:42.

Using the host part of the IP address in the VEID is a good idea, but it isn't mentioned in this tutorial, that the range from 0 to 100 is reserved for OpenVZ internal purposes. Actually theres only the VEID 0 in use, representing the hardware node itself, however, in future versions the use of reserved IDs could result in colisions.
See man vzctl and documentation.

You should use for IP address the VEID 1034 and for 1101 instead of only 3 digits since there are host part numbers below 101 or you just count from 101 upward independent of the IP. Also you can NOT use IDs starting with 0, since the values are reduced to integers. So it wouldn't be a good idea to use 0034 and 0101.