Installation on Gentoo

From Linux-VServer

Revision as of 02:54, 11 January 2007 by (Talk)

Jump to: navigation, search


Host configuration

Install a Linux-VServer kernel

Installing a prepatched kernel is as easy as:

# emerge vserver-sources

However, the main portage tree only contains stable kernels (at the time of writing this is 2.0.x). If you want to install 2.1.1 or above, please take a look at the Gentoo VPS Project Overlay and Howto install 3rd party ebuilds.

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 filesystem on the partition where guest images are stored, you will need to enable extended attributes for reiserfs in your kernel config 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
# 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 util-vserver

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 vservers default
# /etc/init.d/vservers start

The vshelper script is used to restart virtual servers correctly. You have to tell the kernel where the vshelper script is located:

# echo 'kernel.vshelper = /usr/lib/util-vserver/vshelper' >> /etc/sysctl.conf
# sysctl -p

Guest configuration

You have to download a vserver prepared stage3 from one of the Gentoo mirrors. Those stages are located under the experimental/<arch>/vserver/ directory. Since a stage3 contains a complete root filesystem you can use the template build method of util-vserver. However, this method is only available since util-vserver-0.30.211, 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 and the context ID is equivalent to the last two parts of the virtual servers IP).

# vserver myguest build \
  --context 1253 \
  --hostname myguest \
  --interface eth0: \
  --initstyle plain \
  -m template -- \
    -t /path/to/stage3-<arch>-<version>.tar.bz2 \
    -d gentoo

You should be able to start and enter the vserver by using the commands below. If you miss commands like mount or dmesg you should emerge util-linux inside your virtual server as the vserver profile doesn't ship this package by default.

# vserver myguest start
# vserver-stat
0       90   1.4G 153.4K  14m00s11   6m45s17   2h59m59 root server
1253     2     3M   286    0m00s45   0m00s42   0m02s91 myguest
# vserver myguest enter
# ps ax
    1 ?        S      0:00 init [3]
22887 ?        Ss     0:00 /usr/sbin/syslog-ng
20496 pts/0    S      0:00 /bin/bash -login
20508 pts/0    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:// \
(emerge app-editors/vim in 'myguest')
# vemerge myguest app-editors/vim -va

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 /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

External Resources

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 :)

Personal tools