VPS/VServer Guide

This guide walks through the setup of a basic virtual server using Linux-VServer Technology.

The Linux-VServer Concept
The basic concept of the Linux-VServer solution is to separate the user-space environment into distinct units (sometimes called Virtual Private Servers) in such a way that each VPS looks and feels like a real server to the processes contained within.

Emerge
Install a VServer kernel sources:

Kernel
After the vserver-sources are installed it's time to configure them using make menuconfig. Below is a common configuration for 2.1.1 and above. If you are using 2.0.x some configuration options may not be present.

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

Kernel
Install the kernel:

Setup host environment
To maintain your virtual servers you need the util-vserver package which contains all necessary programs and many useful features.

Install util-vserver:

You have to run the vprocunhide command after every reboot in order to setup /proc permissions correctly for vserver guests. Two init scripts have been installed by util-vserver which run the vprocunhide command for you and take care of virtual servers during shutdown of the host.

util-vserver init scripts:

Download a precompiled stage3
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, since baselayout-2/openrc, all required changes have been integrated, eliminating the need for seperate vserver stages, profiles and baselayout. Stage tarballs can be downloaded from our mirrors.

Since a stage3 contains a complete root filesystem you can use the template build method of util-vserver. However, this method only works reliable since util-vserver-0.30.213_rc5, so make sure you have the right version installed.

You have to choose a context ID for your vserver (dynamic context IDs are discouraged) as well as the necessary network device information (In this example eth0 is configured with 192.168.1.253/24 and the context ID is equivalent to the last two parts of the virtual servers IP).

Using the template build method
For a long time now, plain init style was the only init style available for gentoo, i.e. a normal init process will be started inside the guest, just like on any common Unix system. However this approach has some drawbacks:


 * No possibility to see output of init/rc scripts
 * Wasted resources for idle init processes in each guest
 * Annoying conflicts for

Therefore, many users have requested to re-implement the Gentoo init style, which has been abandoned since it was a very hacky implementation and more or less worked by accident due to other modifications done to base layout back then. However, as of util-vserver-0.30.212 the gentoo init style has been re-implemented in a concise manner and will become the default in the future.

Start stage3 installation:

You should now be able to start and enter the vserver by using the commands below. Test the virtual server:

Start guests on boot
You can start certain guests during boot. Each guest can be assigned a MARK. Now everything you have to do is configure these MARKs in the guests configuration and add the appropriate init scripts to the default runlevel. Configure MARKs for each guest:

Add init script to the default runlevel:

Keep Portage in sync
The script vesync will help you to keep the metadata cache and overlays in sync. vemerge is a simple wrapper for emerge in guests:

Update guests
Gentoo guests can share packages to save compilation time. In order to use shared packages, you have to create a central directory for packages on the host. We will use /var/cache/vpackages on the host and mount it to /var/cache/packages in every guest.

Now you can use vupdateworld to update every guest. The command is equivalent to something like emerge --deep --update --newuse world depending on command line options.

Pretend update for 'myguest':

Update 'myguest' using binary packages:

Update all guests using binary packages:

After a successful update you can easily update all configuration files with vdispatch-conf. It is a simple wrapper for dispatch-conf and behaves exactly the same.

Update configuration files for 'myguest':

Update configuration files for all guests:

Contact
Please feel free to contact the author or file a bug on Bugzilla in case of any problems.