Gentoo Logo

Gentoo OpenVZ Howto


1.  Host configuration

Install an OpenVZ kernel

Code Listing 1.1: Install openvz-sources

# emerge openvz-sources

After the openvz-sources are installed it's time to configure them using make menuconfig.

Code Listing 1.2: Configure openvz-sources

# cd /usr/src/linux-<KERNELVERSION>-openvz-<OPENVZVERSION>
# make menuconfig

Processor type and features  --->
  [*] Fair CPU scheduler
  [*]   VCPU scheduler support
File Systems  --->
  [*] Quota support
  <M> VPS filesystem
  <M> Virtuozzo Disk Quota support
  [ ]   Unloadable Virtuozzo Disk Quota module
  [*]   Per-user and per-group quota in Virtuozzo quota partitions
OpenVZ  --->
  [*] Virtual Environment support
  <M>   VE calls interface
  [ ]   Enable sysfs support in Virtual Environments
  <M>   VE networking
  [*]     VE netfiltering
  <M>   VE watchdog module

After you've built and installed the kernel, update your boot loader and finally reboot to see if the kernel boots correctly.

Code Listing 1.3: Install the kernel

(Building the kernel)
# make
# make modules_install
# cp arch/<arch>/boot/bzImage /boot/kernel-<KERNELVERSION>-openvz-<OPENVZVERSION>
(Edit bootloader config file as required and)
# reboot

Setup host environment

To maintain your virtual servers you need the vzctl package which contains all necessary programs and many useful features.

Code Listing 1.4: Install vzctl

# emerge vzctl

The vzctl packages has installed an init script called vz. It will help you to start/stop virtual servers on boot/shutdown:

Code Listing 1.5: vzctl init script

# rc-update add vz default
# /etc/init.d/vz start

2.  Creating a guest template

Create the template tarball

Since many hardware related commands are not available inside a virtual server, there has been a patched version of baselayout known as baselayout-vserver. However all required changes have been integrated into normal baselayout-2, eliminating the need for seperate vserver stages, profiles and baselayout. The only (temporary) drawback is that baselayout-2 is still considered to be in alpha stage and there are no stages with baselayout-2 available on the mirrors yet.

As soon as baselayout-2 is stable you can use a precompiled stage3/4 from one of our mirrors. In the meantime please download a stage3/4 from here.

Note: Unfortunately vzctl does not understand bzip2 (yet?) and needs a different filename to recognize gentoo as the distribution, so you have to convert the stage tarball.

Code Listing 2.1: Convert stage tarball

# cd /vz/template/cache
# bunzip2 stage4-<arch>-<version>.tar.bz2
# mv stage4-tarball.tar gentoo-<arch>-<version>.tar
# gzip gentoo-<arch>-<version>.tar
# cd -

Create VPS

Code Listing 2.2: Create VPS

# vzctl create <vpsid> --ostemplate gentoo-<arch>-<version>

Note: Do not use vpsids <=100, they are reserved.

Test the virtual server

You should be able to start and enter the vserver by using the commands below.

Code Listing 2.3: Test the virtual server

# vzctl start <vpsid>
# vzctl enter <vpsid>
# ps ax
    1 ?        S      0:00 init [3]
20496 pts/0    S      0:00 /bin/bash -i
20508 pts/0    R+     0:00 ps ax
# logout


Page updated March 22, 2007

Summary: In this Howto you will learn to setup a basic virtual server using the OpenVZ Technology

Benedikt Boehm

Donate to support our development efforts.

Copyright 2001-2014 Gentoo Foundation, Inc. Questions, Comments? Contact us.