OpenVZ Tutorial – Installation, Setup and Running your first program inside container.
Mar 23rd, 2008 | By Premnath Sah | Category: TechnologyOpenVZ is a virtualization technology similar to Solaris containers / BSD Jails etc. These kind of virtualization saves a lot of memory and run at almost full speed (very minimal overhead) whereas other virtualization techniques take a beat in the range of 5-25%. OpenVZ falls under the category called Operating system level virtualization
Installation:
I tried OpenVZ in Fedora 8 and OpenVZ binary kernel provided at openvz.org. Installing OpenVZ requires a modified Linux kernel. You can either install the binary kernel provided by openvz.org or we can download kernel source from kernel.org and compile the kernel after patching it using the patches provided.
Steps taken to install OpenVZ
everything following needs to be run as root
1 2 3 | cd /etc/yum.repos.d wget http://download.openvz.org/openvz.repo rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ |
I used yum for installing the openvz
1 | yum install ovzkernel |
we will have to edit /etc/systcl.conf and make sure these lines are present
1 2 3 4 5 6 | net.ipv4.ip_forward = 1 net.ipv4.conf.default.proxy_arp = 0 net.ipv4.conf.all.rp_filter = 1 kernel.sysrq = 1 net.ipv4.conf.default.send_redirects = 1 net.ipv4.conf.all.send_redirects = 0 |
next, we should disable selinux
edit /etc/sysconfig/selinux and set
1 | SELINUX=disabled |
if you selected kernel version 2.6.8 or earlier then follow this step
edit /etc/modprobe.conf and add
1 | options ip_conntrack ip_conntrack_enable_ve0=1 |
reboot the system into newly installed OpenVZ kernel
After the system boots into OpenVZ kernel and follow these steps
1 | yum install vzctl vzquota |
Installation is almost complete. We just need to start OpenVZ service it takes care of loading requires kernel modules etc.
1 | /sbin/service vz start |
Now the OpenVZ has been successfully installed in my system.
Creation of Virtual Machine / Container:
I wanted to test “Suse 10″ and found that it is available as prebuilt OpenVZ distro (they call is template cache) at http://openvz.org/download/template/cache . Other prebuilt distributions includes asianux, centos, debian, fedora, gentoo, mandriva, ubuntu.
I had to just download the tarball in my case it is opensuse-10-i386-default.tar.gz and store it at /vz/template/cache. no need to untar it.
Creation of Virtual Machine or a Container
1 2 3 4 | vzctl create 101 --ostemplate opensuse-10-i386-default vzctl set 101 --ipadd 10.1.2.3 --save vzctl set 101 --nameserver 10.0.2.1 --save vzctl start 101 |
Here 101 is the id we use to refer opensuse container. it can be anything above 100. create command creates a container with id 101 and we will be referring opensuse container using this container. –ipadd add a ipaddress to the container. default networking is done using venet driver and its simple, fast and secure but cannot acquire ip using dhcp etc. there is also veth driver which is a virtual ethernet device and can acqurire ip using dhcp but requries more configuration.
with –nameserver option with set the nameserver to be used by the container.
Running a program inside Container:
to run any command inside a container from the host system
1 | vzctl exec 101 ps -efww |
this will run ps -efww and return the result.
if you want to login into the container
1 | vzctl enter 101 |
This tutorial is over. we will look into other advanced concepts like setting up networking using ethernet and others in upcoming tutorials.
RSS Feed
Email









[...] blogsreel wrote an interesting post today onHere’s a quick excerptOpenVZ Tutorial – Installation, Setup and Running your first program inside container. March 23, 2008 – 6:18 pm by Premnath Sah OpenVZ is a virtualization technology similar to Solaris containers / BSD Jails etc. These kind of virtualization saves a lot of memory and run at almost full speed (very minimal overhead) whereas other virtualization techniques take a beat in the range of 5-25%. OpenVZ falls under the category called Operating system level virtualization Installation: I tried OpenVZ [...]
[...] Sally B. wrote an interesting post today onHere’s a quick excerptOpenVZ is a virtualization technology similar to Solaris containers / BSD Jails etc. These kind of virtualization saves a lot of memory and run at almost full speed (very minimal overhead) whereas other virtualization techniques take a … [...]
Am using vmware, drawback is i can’t go for customer kernel, specifically you will realize this problem in webhosting field, but am not sure whether openvz has this feature.
Though vmware is good at in its own areas like ease to install, manage, added application, costly support
Well sometimes opensource applications gets into a better shape (not always) when it was bought by big giants…
Recently acquired one’s…
(1) Citrix bought Xen
(2) MySQL bought Sun
@hawk
What do you mean by using customer kernel? you mean using your own kernel?
you can use your kernel as long as you can patch the kernels using the provided patches at openvz.org. but i dont think it will be straight forward.