Installing And Using OpenVZ On Ubuntu 13.04 (AMD64)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Wed, 2013-07-17 08:30. :: OpenVZ | Ubuntu | Virtualization

Installing And Using OpenVZ On Ubuntu 13.04 (AMD64)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Follow me on Twitter
Last edited 06/04/2013

In this HowTo I will describe how to prepare an Ubuntu 13.04 server for OpenVZ. With OpenVZ you can create multiple Virtual Private Servers (VPS) on the same hardware, similar to Xen and the Linux Vserver project. OpenVZ is the open-source branch of Virtuozzo, a commercial virtualization solution used by many providers that offer virtual servers. The OpenVZ kernel patch is licensed under the GPL license, and the user-level tools are under the QPL license.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Preliminary Note

I'm using an x86_64 (amd64) system here. If you are on an i386 system, a few commands will be slightly different.

 

2 Installing OpenVZ

For Ubuntu 13.04, there is no OpenVZ kernel in the official repositories. Therefore we must install OpenVZ from the official RPM packages from the OpenVZ project (see Install kernel from RPM on Debian 6.0) - with ploop support

 

2.1 Installing From The Official RPM Packages From The OpenVZ Project

Download the latest vzkernel, vzctl, ploop and vzquota RPM packages from http://wiki.openvz.org/Download/kernel/rhel6 and http://wiki.openvz.org/Download/utils, e.g. as follows::

cd /tmp
wget http://download.openvz.org/kernel/branches/rhel6-2.6.32/042stab076.8/vzkernel-2.6.32-042stab076.8.x86_64.rpm
wget http://download.openvz.org/kernel/branches/rhel6-2.6.32/042stab076.8/vzkernel-devel-2.6.32-042stab076.8.x86_64.rpm
wget http://download.openvz.org/utils/vzctl/4.3.1/vzctl-4.3.1-1.x86_64.rpm
wget http://download.openvz.org/utils/vzctl/4.3.1/vzctl-core-4.3.1-1.x86_64.rpm
wget http://download.openvz.org/utils/ploop/1.7/ploop-1.7-1.x86_64.rpm
wget http://download.openvz.org/utils/ploop/1.7/ploop-lib-1.7-1.x86_64.rpm
wget http://download.openvz.org/utils/vzquota/3.1/vzquota-3.1-1.x86_64.rpm

Install the following packages...

apt-get install fakeroot alien libcgroup1

... and convert the RPM packages to DEB packages:

fakeroot alien --to-deb --scripts --keep-version vz*.rpm ploop*.rpm

Install the DEB packages as follows:

dpkg -i vz*.deb ploop*.deb

Next we have to make sure that the correct kernel (the OpenVZ kernel) is booted when you restart the system. In the output of the last command, you should see something like this:

Setting up vzkernel (2.6.32-042stab076.8) ...
update-initramfs: Generating /boot/initrd.img-2.6.32-042stab076.8
WARNING: could not open /lib/modules/2.6.32-042stab076.8/modules.builtin: No such file or directory
WARNING: could not open /tmp/mkinitramfs_I0VIfE/lib/modules/2.6.32-042stab076.8/modules.builtin: No such file or directory
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.8.0-19-generic
Found initrd image: /boot/initrd.img-3.8.0-19-generic
Found linux image: /boot/vmlinuz-2.6.32-042stab076.8
Found initrd image: /boot/initrd.img-2.6.32-042stab076.8
Found memtest86+ image: /memtest86+.bin
done

This means there is also another kernel on the system (3.8.0), and the openVZ kernel (2.6.32) is not the first in the list. So to make the OpenVZ kernel the default kernel, we have two options - adjust the default kernel in GRUB (recommended) or remove the non-VZ kernel(s).

To adjust the default kernel in GRUB, open /etc/default/grub...

vi /etc/default/grub

... and modify the GRUB_DEFAULT line (counting starts with 0; our OpenVZ is the third kernel in the Advanced options for Ubuntu GRUB submenu (which is the second option in the boot menu after the 3.8.0 kernel), so we need to put in "1>2" here (in quotes) - you can find more about GRUB submenus here: https://help.ubuntu.com/community/Grub2/Submenus):

[...]
GRUB_DEFAULT="1>2"
[...]

Update GRUB afterwards:

update-grub

To remove the default kernel, run...

apt-get remove linux-image linux-image-3.8.0-19-generic

... and update GRUB:

update-grub

Now that we have made sure the correct kernel will boot, we can go on.

Next we must check that we are using UUIDs instead of device names in /etc/fstab because otherwise the system might not boot with the openVZ kernel. Run...

blkid

... to find out the UUIDs of your devices/partitions:

root@server1:/tmp# blkid
/dev/sda1: UUID="9b8299f1-b2a2-4231-9ba1-4540fad76b0f" TYPE="ext2"
/dev/sda5: UUID="M83xtW-GofR-FFaa-myo1-T4Gw-grKe-Kg1Etc" TYPE="LVM2_member"
/dev/mapper/server1--vg-root: UUID="a5a6e916-64e1-4af9-8bd4-32491d7edcac" TYPE="ext4"
/dev/mapper/server1--vg-swap_1: UUID="a68ae8a2-c2cd-4e92-af08-a71661f8f719" TYPE="swap"
root@server1:/tmp#

Open /etc/fstab:

vi /etc/fstab

My original /etc/fstab looks as follows (as you see, the UUID of the /boot partition is already being used, but for / and swap, the device names are in use):

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/server1--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=9b8299f1-b2a2-4231-9ba1-4540fad76b0f /boot           ext2    defaults        0       2
/dev/mapper/server1--vg-swap_1 none            swap    sw

Modify it so that UUIDs are used for all partitions:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
#/dev/mapper/server1--vg-root /               ext4    errors=remount-ro 0       1
UUID=a5a6e916-64e1-4af9-8bd4-32491d7edcac /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=9b8299f1-b2a2-4231-9ba1-4540fad76b0f /boot           ext2    defaults        0       2
#/dev/mapper/server1--vg-swap_1 none            swap    sw              0       0
UUID=a68ae8a2-c2cd-4e92-af08-a71661f8f719 none            swap    sw              0       0

Make sure OpenVZ starts automatically at boot time:

update-rc.d vz defaults
update-rc.d vzeventd defaults

Next we need to link a few libraries:

ln -s /usr/lib64/libvzctl-4.3.1.so /usr/lib
ln -s /usr/lib64/libploop.so /usr/lib

If you want to use ploop containers, do this:

apt-get install parted

Also, open /etc/init.d/vz...

vi /etc/init.d/vz

... and add the line mkdir $VARLOCK/ploop to make sure that the directory /var/lock/ploop is recreated after a reboot:

#!/bin/sh
#  Copyright (C) 2000-2009, Parallels, Inc. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# OpenVZ startup script, used for redhat and debian related distributions.

###
# chkconfig: 2345 96 20
# description: OpenVZ startup script.
###

### BEGIN INIT INFO
# Provides: vz
# Required-start: $network $remote_fs $syslog
# Required-stop:  $network $remote_fs $syslog
# Should-Start:  sshd vzeventd
# Should-Stop:  sshd vzeventd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenVZ startup script
# Description: OpenVZ startup script.
### END INIT INFO


# This line is needed to cheat /etc/init.d/rc who expects action word

. /usr/libexec/vzctl/scripts/initd-functions
mkdir $VARLOCK/ploop
[...]

Create a symlink from /vz to/var/lib/vz to provide backward compatibility:

ln -s /vz /var/lib/vz

Open /etc/sysctl.conf and make sure that you have the following settings in it:

vi /etc/sysctl.conf

[...]
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.ip_forward=1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.eth0.proxy_arp=1
[...]

If you need to modify /etc/sysctl.conf, run

sysctl -p

afterwards.

The following step is important if the IP addresses of your virtual machines are from a different subnet than the host system's IP address. If you don't do this, networking will not work in the virtual machines!

Open /etc/vz/vz.conf and set NEIGHBOUR_DEVS to all:

vi /etc/vz/vz.conf

[...]
# Controls which interfaces to send ARP requests and modify APR tables on.
NEIGHBOUR_DEVS=all
[...]

Install vzdump:

apt-get install vzdump

Finally, reboot the system:

reboot

If your system reboots without problems, then everything is fine!

Run

uname -r

and your new OpenVZ kernel should show up:

root@server1:~# uname -r
2.6.32-042stab076.8
root@server1:~#


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 Michael H. Warfield (not registered) on Tue, 2013-07-23 18:24.

Simple question.  Why?  As in "why bother?"

There's a simple reason the OpenVZ kernel is no longer included in Ubuntu.  The reason is LXC and Linux containers.  What real, practical, advantage does OpenVZ (more specifically the OpenVZ custom patched kernel) offer over that of the mainline 3.x kernel?

We now have cgroups and namespaces in the main-line kernel and the need for this custom patched ongoing maintenance headache (PITA) is largely alleviated.  The OpenVZ user space (vzctl et al) will even run over top of the main-line kernels (3.x and a few prior).  There are some limitations, but not many and generally requirement specific.  The OpenVZ developers have been contributing to the Linux kernel containers and namespace development effort.  I routinely see the same names on both -devel mailing lists.  Many of the remaining limitations are being addressed.

All that's even if you really want to run the OpenVZ user space.  Quite frankly, I migrated off of OpenVZ over to LXC a couple of years ago and not looked back.  While it has its limitations, LXC has some versatility that is sadly lacking in OpenVZ (like arbitrary container names, not just numerical IDs).  Last time I looked (and this could have very easily changed over the last two years) the OpenVZ kernel patches were also not compatible with the cgroups options and using an OpenVZ kernel disabled your ability to use cgroups for other process management.  I would have hoped they would have resolved that by now but it was true back then.

Linus made it abundantly clear years ago that the OpenVZ / Virtuoso patches would not be accepted into the upstream sources.  He had his reasons and the OpenVZ people shifted gears to support getting containers into the kernel.  That is where we are going.  The OpenVZ patched kernel has always lagged and will always lag behind the mainstream kernel and bug fixes will be similarly delayed.

The reference to the Linux Vserver project is also amusing (I use to use them too) since that project hasn't been updated in a couple of years.  I abandoned that one years and years ago after they broke IPv6 networking and found OpenVZ to be superior to that.

Submitted by Anonymous (not registered) on Sat, 2013-11-02 20:46.

While it has its limitations, LXC has some versatility that is sadly lacking in OpenVZ (like arbitrary container names, not just numerical IDs).  
 
 

Ok... So, I should migrate to LXC because I can put some arbitrary name to a container ? 

That's a definitive reason... xD 

On my opinion live migration, templates, control panels completly overcomes LXC, on a future when LXC is more mature it will rock, but now, LXC isn't for a production enviorenment. Just for testing on that computer no body uses... 

Submitted by EarthCrash (registered user) on Thu, 2013-07-25 19:40.
Thank you for explain!
Submitted by Anonymous (not registered) on Tue, 2013-07-23 10:50.

i can't booting with vz kernel.

i've got error in boot process:

ALERT!  /dev/mapper/ubuntu-root does not exist.  Dropping to a shell!
 
there is no /dev/mapper directory and no uuid for lvm in /dev/disk/by-uuid.
i think that vz's kernel have no modules for lvm so can't mount lvm's root filesystem.
during install rpms, we can see below messages
WARNING: could not open /lib/modules/2.6.32-042stab078.28/modules.builtin: No such file or directory
WARNING: could not open /tmp/mkinitramfs_vXC6YN/lib/modules/2.6.32-042stab078.28/modules.builtin: No such file or directory
So i think something is missing in this tutorial.
any idea? 
Submitted by karab44 (registered user) on Sun, 2013-08-18 09:56.
got the same problem bro :/