Thursday, 18 July 2013

OpenVZ Debian 7 - 64 bit

The quick and dirty command guide to running Debian 7 using OpenVZ, I'm using a server running Debian on 64 bit.

Check for Virtualization, anything more than 0 will do:

cat /proc/cpuinfo | grep vmx | wc -l

Install the Kernel Required: apt-get install linux-image-openvz-amd64
Install the required packages: apt-get install vzctl vzquota vzdump debootstrap

Depending on your distro you may have OpenVZ's directories in /var/lib/vz or /vz, once you know which change directory:

cd /vz/template/cache/ -or- cd /var/lib/vz/template/cache/

Download the Debian 7 64 bit template (more on the website):


Create the container using the template (filename less the .tar.gz):

vzctl create 101 --ostemplate debian-7.0-x86_64

Why 101? Basically it's the ID of the container, OpenVZ reserves ID 1 to 100 so be sure to user an ID larger than 100, I simply opted for 101.

Command Cheatsheet:

Values containing a colon are in the format -> softlimit:hardlimit, eg. 10G:25GB for the disk space below:

Start container on boot: vzctl set 101 --onboot yes --save
Set Hostname: vzctl set 101 --hostname --save
Add an IP: vzctl set 101 --ipadd --save
Remove an IP: vzctl set 101 --ipdel --save
Set the nameserver: vzctl set 101 --nameserver --save
Set the memory limits: vzctl set 101 --privvmpages 1024M:2048M --save
Set the CPU usage limit (eg. 200% or 2 CPU's): vzctl set 101 --cpulimit 200 --save
Set the CPU count limit, eg. 2 CPU's: vzctl set 101 --cpus 2 --save
Set the disk space limits: vzctl set 101 --diskspace 10G:25G --save
Set the CPU units limit: vzctl set 101 –cpuunits 1000 –save

More detail on the CPU units limit:
3 containers with 1000 limit each, ie. 3000 in total will result in each container getting 1000/3000, ie. 1/3rd of the CPU's time.

To start a container: vzctl start 101
To enter the container: vzctl enter 101
To execute commands without entering container: vzctl exec 101 your_command
To change the password: vzctl exec 101 passwd
To start ssh on the Debian 7 container: vzctl exec 101 /etc/init.d/ssh start
To remove the container: vzctl destroy 101

Backing up a container with suspend: vzdump --compress --dumpdir /home/backup --suspend 101
Restoring a container: vzrestore /home/vzdump-101.tgz 101

To enable fuse, execute these on the host:
1. modprobe fuse
2. vzctl set 101 --devnodes fuse:rw --save

You can also build your own template, to do this for Debian Wheezy with:
debootstrap --arch amd64 wheezy /vz/private/101

Hope you have great fun with OpenVZ, I know I am, if you have any questions or would like to add to this post, please comment!

No comments:

Post a Comment