Installation on Gentoo
Manually install a Linux-Vserver kernel
IF your portage tree contains a pre-patched linux-vserver kernel, then use that one and skip to the next chapter.
As of april 2016 there is no current maintainer for linux-vserver kernels on Gentoo. The Gentoo maintainers seem to have adapted a more "aggressive" approach related to removing unmaintained Gentoo packages, so they have deleted all "old" vserver pre-patched kernels from portage. This means that one has to install the vserver patch manually. However, this is a fairly simple process, depending on whether you find a kernel source in portage that has an available linux-vserver kernel patch also. This is what you need to do:
Have a look at Bertl's kernel patches. These are found on http://vserver.13thfloor.at/Experimental/ and named "patch-" + the kernel version the patch applies for. ("Experimental" is slightly misleading...)
You'll then have to find kernel sources for which there is a patch available. Take a look into /usr/portage/sys-kernel/vanilla-sources/. This is what you might see:
amd64 ~ # ls -l /usr/portage/sys-kernel/vanilla-sources/ totalt 228 -rw-r--r-- 1 portage portage 23681 april 6 17:34 ChangeLog -rw-r--r-- 1 portage portage 104895 nov. 9 04:28 ChangeLog-2013 -rw-r--r-- 1 portage portage 43787 nov. 9 05:11 ChangeLog-2015 -rw-r--r-- 1 portage portage 11396 april 6 17:34 Manifest -rw-r--r-- 1 portage portage 642 jan. 25 00:06 metadata.xml -rw-r--r-- 1 portage portage 456 mars 17 10:58 vanilla-sources-3.10.101.ebuild -rw-r--r-- 1 portage portage 456 mars 18 23:03 vanilla-sources-3.12.57.ebuild -rw-r--r-- 1 portage portage 456 mars 17 10:58 vanilla-sources-3.14.65.ebuild -rw-r--r-- 1 portage portage 456 april 6 12:49 vanilla-sources-3.18.30.ebuild -rw-r--r-- 1 portage portage 456 april 1 12:31 vanilla-sources-3.2.79.ebuild -rw-r--r-- 1 portage portage 456 mars 22 14:42 vanilla-sources-3.4.111.ebuild -rw-r--r-- 1 portage portage 456 april 6 12:49 vanilla-sources-4.1.21.ebuild -rw-r--r-- 1 portage portage 456 mars 17 10:58 vanilla-sources-4.4.6.ebuild -rw-r--r-- 1 portage portage 456 mars 17 10:58 vanilla-sources-4.5.0.ebuild
Unfortunately, at this time of writing no patch exists for any of the most recent kernels from that list. If it did, then install that version and skip the next step and use the chosen kernel as the kernel to install and patch later in this short writeup.
There is also a "gentoo-sources" kernel source alternative. These kernel are slightly patched with Gentoo updates. However, assumingly that these kernels are not so heavily patched by Gentoo that they couldn't accept the linux-vserver patch also.
Here is a sample Gentoo-sources list:
amd64 ~ # ls -l /usr/portage/sys-kernel/gentoo-sources/ totalt 500 -rw-r--r-- 1 portage portage 36798 april 6 17:34 ChangeLog -rw-r--r-- 1 portage portage 91971 nov. 9 04:28 ChangeLog-2007 -rw-r--r-- 1 portage portage 101665 nov. 9 04:28 ChangeLog-2012 -rw-r--r-- 1 portage portage 119486 nov. 9 05:11 ChangeLog-2015 -rw-r--r-- 1 portage portage 766 mars 17 00:18 gentoo-sources-3.10.101.ebuild -rw-r--r-- 1 portage portage 757 jan. 24 12:50 gentoo-sources-3.10.95.ebuild [...several kernels deleted to save space...] -rw-r--r-- 1 portage portage 770 okt. 26 13:05 gentoo-sources-4.0.9.ebuild -rw-r--r-- 1 portage portage 787 jan. 10 11:32 gentoo-sources-4.1.12.ebuild -rw-r--r-- 1 portage portage 786 mars 21 12:45 gentoo-sources-4.1.15-r1.ebuild -rw-r--r-- 1 portage portage 794 mars 18 19:57 gentoo-sources-4.1.20.ebuild -rw-r--r-- 1 portage portage 794 april 6 15:49 gentoo-sources-4.1.21.ebuild -rw-r--r-- 1 portage portage 793 mars 17 00:56 gentoo-sources-4.4.6.ebuild -rw-r--r-- 1 portage portage 793 mars 29 14:53 gentoo-sources-4.5.0-r1.ebuild -rw-r--r-- 1 portage portage 40428 april 6 17:34 Manifest -rw-r--r-- 1 portage portage 705 jan. 25 00:06 metadata.xml
There is a match. http://vserver.13thfloor.at/Experimental/ has a patch for 4.1.12, so let's install the 4.1.12 gentoo-sources and try the linux-vserver patch on it.
amd64 ~ # emerge -v =sys-kernel/gentoo-sources-4.1.12
Then download the corresponding patch from 13thfloor and save it into the same directory as the emerged kernel sources which in this case is /usr/src/gentoo-sources-4.1.12 .
cd into that source directory and install the linux-vserver kernel patch:
amd64 ~ # cd /usr/src/linux-4.1.12-gentoo/ amd64 linux-4.1.12-gentoo # patch -p1 < patch-4.1.12-vs18.104.22.168.diff patching file Documentation/vserver/debug.txt patching file Makefile Hunk #1 FAILED at 1. 1 out of 1 hunk FAILED -- saving rejects to file Makefile.rej patching file arch/alpha/Kconfig patching file arch/alpha/kernel/systbls.S patching file arch/alpha/kernel/traps.c patching file arch/arm/Kconfig [...further output deleted...]
Hopefully there shouldn't be any serious rejects. The only reject I got was the makefile itself. By looking at the .rej file, it is just the EXTRAVERSION that failed since EXTRAVERSION is already set to "-gentoo" by gentoo-sources. So you can rather just edit EXTRAVERSION line the makefile manually to whatever you like or keep it as it is.
--- Makefile 2015-10-29 09:20:01.000000000 +0000 +++ Makefile 2015-10-30 14:51:48.000000000 +0000 @@ -1,7 +1,7 @@ VERSION = 4 PATCHLEVEL = 1 SUBLEVEL = 12 -EXTRAVERSION = +EXTRAVERSION = -vs22.214.171.124 NAME = Series 4800 # *DOCUMENTATION*
Then configure the kernel as you like, and as descripted in later chapters.
Install a Linux-VServer kernel
Installing a prepatched kernel is as easy as:
# emerge vserver-sources
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.
# cd /usr/src/linux-<KERNELVERSION>-vserver-<VSERVERVERSION> # make menuconfig Linux VServer ---> [ ] Enable Legacy Kernel API [ ] Enable Legacy Networking Kernel API [ ] Remap Source IP Address [*] Enable COW Immutable Link Breaking [*] Enable Virtualized Guest Time [*] Enable Proc Security [*] Enable Hard CPU Limits [*] Avoid idle CPUs by skipping Time [*] Limit the IDLE task Persistent Inode Tagging (UID24/GID24) ---> [ ] Tag NFSD User Auth and Files [ ] Enable Inode Tag Propagation [*] Honor Privacy Aspects of Guests [ ] VServer Debugging Code
Note: If you are using reiserfs as file system on the partition where guest images are stored, you will need to enable extended attributes for reiserfs in your kernel configuration and additionally add the attrs option in /etc/fstab.
File systems ---> <*> Reiserfs support [*] ReiserFS extended attributes
/dev/hdb1 /vservers reiserfs noatime,attrs 0 0
After you've built and installed the kernel, update your boot loader and finally reboot to see if the kernel boots correctly.
(Building the kernel) # make (Installing) # make modules_install # cp arch/<arch>/boot/bzImage /boot/kernel-<KERNELVERSION>-vserver-<VSERVERVERSION> (Edit bootloader config file as required and) # reboot
Setup host environment
To maintain your virtual servers you need the util-vserver package which contains all necessary programs and many useful features.
# emerge >=sys-cluster/util-vserver-0.30.212
You have to run the vprocunhide command after every reboot in order to setup /proc permissions correctly for vserver use. An init script has been installed by util-vserver. To use it you should add it to a runlevel:
# rc-update add vprocunhide default # /etc/init.d/vprocunhide start # rc-update add util-vserver default # /etc/init.d/util-vserver start
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 separate vserver stages, profiles and baselayout. The only (temporary) drawback is that baselayout-2/openrc is still in testing (~arch) and there are no stages with baselayout-2/openrc available on the mirrors yet.
As soon as baselayout-2/openrc is stable you can use a precompiled stage3 from one of the Gentoo mirrors. In the meantime please download a stage3 or gentoo-vserver stage from here. Since a stage3 contains a complete root file system 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 /etc/inittab
Therefore, many users have requested the gentoo init style to be reimplemented, which has been abandoned since it was a very hacky implementation and more or less worked by accident due to other modifications done to baselayout back then. However, as of util-vserver-0.30.212 the gentoo init style has been reimplemented in a concise manner and will become the default in the future.
# vserver myguest build \ --context 1253 \ --hostname myguest \ --interface eth0:192.168.1.253/24 \ --initstyle gentoo \ -m template -- \ -t /path/to/gentoo-vserver-<arch>-<version>.tar.bz2 \ -d gentoo
You should be able to start and enter the vserver by using the commands below.
# vserver myguest start OpenRC 0.4.3 is starting up Gentoo Linux (x86_64) [VSERVER] Press I to enter interactive boot mode * /proc is already mounted, skipping * Setting hostname to myguest... [ ok ] * Creating user login records... [ ok ] * Cleaning /var/run... [ ok ] * Wiping /tmp directory... [ ok ] * Updating /etc/mtab... [ ok ] * Initializing random number generator... [ ok ] * Starting syslog-ng... [ ok ] * Starting fcron... [ ok ] * Starting Name Service Cache Daemon... [ ok ] * Starting local... [ ok ] # vserver-stat CTX PROC VSZ RSS userTIME sysTIME UPTIME NAME 0 90 1.4G 153.4K 14m00s11 6m45s17 2h59m59 root server 1253 2 3M 286 0m00s45 0m00s42 0m02s91 myguest # vserver myguest enter # ps ax PID TTY STAT TIME COMMAND 1 ? Ss 0:04 init  27637 ? Ss 0:00 /usr/sbin/syslog-ng 27656 ? Ss 0:00 /usr/sbin/fcron -c /etc/fcron/fcron.conf 27676 ? Ssl 0:00 /usr/sbin/nscd 27713 ? S+ 0:00 login 27737 pts/15 Ss 0:00 /bin/bash 27832 pts/15 R+ 0:00 ps ax # logout
Maintenance made easy
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 tell the init script to run all MARKed guests.
(Do this for every guest you want to start) # mkdir -p /etc/vservers/myguest/apps/init # echo "default" > /etc/vservers/myguest/apps/init/mark
Note: Since all guests marked with "default" are started by default, nothing more has to be done. If you have different marks you should also update /etc/conf.d/vservers.
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.
(Sync metadata for 'myguest') # vesync myguest (Sync metadata for all guests) # vesync -a (Sync metadata for all guests except 'myguest') # vesync -a -e myguest (Sync 'myoverlay' for all guests) # vesync -a \ --overlay /usr/local/overlays/myoverlay \ --overlay-host rsync://rsync.myhost.com/myoverlay \ --overlay-only (emerge app-editors/vim in 'myguest') # vemerge myguest -- app-editors/vim -va
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 /usr/portage/packages in every guest.
# mkdir -p /var/cache/vpackages # $EDITOR /etc/vservers/myguest/fstab (Add this line at the end) /var/cache/vpackages /usr/portage/packages none bind,rw 0 0
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') # vupdateworld -p myguest (Update 'myguest' using binary packages) # vupdateworld -k myguest (Update all guests using binary packages) # vupdateworld -ka
Note: In order to get binary packages you can either use PORTAGE_BINHOST (see man make.conf) or set FEATURES="buildpkg" in one or more guests.
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') # vdispatch-conf myguest (Update configuration files for all guests) # vdispatch-conf -a
These scripts will hopefully help some of you out with some basic tasks. Review each script carefully, so you know what it is doing.
The scripts here were outdated and the original contributor removed them.
Please take a look at the Gentoo Linux-VServer Howto for more information. In general we try to keep the wiki in sync, nevertheless it might help :)