Arch VServer

From ArchWiki
Revision as of 16:30, 15 November 2009 by Delerious010 (Talk | contribs)

Jump to: navigation, search

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Arch VServer#)

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Arch VServer#)

Introduction

This article aims to provide all necessary information regarding the creation of a vserver host and it's related guests on Arch Linux. This will enable you to setup virtual servers that provide different services as if they were on different machines, with a very little overhead. You can get more information about virtual servers here.

I've just started playing around with vserver and, since this page was pretty empty, figured I'd jot down some notes. I'll come back to clean things up / clarify things soon(ish) ( Delerious010 11:30, 15 November 2009 (EST) ).

Preparing the Host

To prepare the vserver host environment, you will need to install both a patch kernel and the vserver utilities which are located in AUR. In the following steps, the instructions are provided using yaourt to fetch them automatically. This has the aded benefit of pulling down the required dependencies ( dietlibc and beecrypt ) automagically :

  1. yaourt -S kernel26-vserver util-vserver

Please note : Since vserver requires a patched kernel, it's possible that your vserver kernel may lag behind the standard kernel26 package release.

Paths of Interest

/etc/vservers : configuration root ( reference )

/etc/vservers/.defaults : configuration skeleton used when building new guests
/etc/vservers/.defaults/vdirbase : symlink to the folder containing vserver guests. This defaults to /vservers.
/etc/vservers/<guest name> : guest specific configurations

Preparing the Guests

Vserver will launch guests from subfolders of /etc/vservers/.defaults/vdirbase ( which defaults to /vservers ). As such, creating a new guest system is as simple as installing the required packages in a folder. Furthermore, there's nothing stopping you ( and quite a few things encouraging you ) to mount filesystems to the subfolders of vdirbase and install your guest in there.

The following steps are going to be very brief so as not to duplicate information from Install From Existing Linux. For the most part, this can all be easily automated via a few simple bash scripts.

In looking at /etc/vservers/.distribution, i'm getting the fealing that we could just create a template for ArchLinux to fully automate the below steps, however I've not had the time to investigate in more detail.

  1. (optional) Create LVM volume via lvcreate.
  2. (optional) Create filesystem on lvm volume / disk partition.
  3. (optional) Mount newly create filesystem to /vserver/<guest>
  4. (optional) Link new guests pacman package cache to the host's
    1. mkdir -p /vserver/<guest>/var/cache/pacman/pkg
    2. mount -o bind /var/cache/pacman/pkg /vserver/<guest>/var/cache/pacman/pkg
  5. Prepare guest filesystem for pacman db and install base packages
    1. mkdir -p /newarch/var/lib/pacman
    2. pacman -Sy base -r /vserver/<guest>
      Note : To save some time, it's probably a good idea to create a text file containing all the packages to install and call it via pacman -Sy `cat <file>` -r /vserver/<guest>
  6. (optional) If you want to chroot into the newly created guest so as to install new packages, it might be a good idea to mount a few filesystems required by some packages.
    1. Bind /dev, /proc, /sys to the corresponding directories in /vserver/<guest>
  7. Modify guest configuration files to enable a smoother boot process
    1. /etc/inittab : Delete all lines that create the consoles ( agetty )
    2. /etc/rc.shutdown : Still modifying this, but basically you want to remove anything hardware related. This includes most everything under Saving Random Seed'.
    3. Create /etc/init.d/rc which vserver will call rather than /etc/rc.sysinit.
  8. Create a vserver instance for our newly create filesystem
    1. vserver <guest name> build -m skeleton \
      --context <unique context number ... 1 through ???> \
      --interface <device:ip/netmask> \
      --flags lock,virt_mem,virt_uptime,virt_cpu,virt_load,sched_hard,hide_netif \
      --initstyle plain
    2. To start on boot : echo default > /etc/vservers/<guest>/apps/init/mark

/etc/init.d/rc

if [ $1 -eq 3 ]; then
echo "entering runlevel 3:multi";
/etc/rc.multi
fi
if [ $1 -eq 6 ]; then
echo "entering runlevel 6:reboot";
/etc/rc.shutdown
fi
if [ $1 -eq 0 ]; then
echo "entering runlevel 0: shutdown";
/etc/rc.shutdown
fi
if [ $1 -eq 4 ]; then
echo "entering runlevel 4";
fi
if [ $1 -eq 5 ]; then
echo "entering runlevel 5";
fi
if [ $1 -eq 1 ]; then
echo "entering runlevel 1:single";
/etc/rc.single
fi
if [ $1 -eq 2 ]; then
echo "entering runlevel 2:multi";
/etc/rc.multi
fi

Troubleshooting

Tips & Tricks

More Resources

Problematic Programs Make BSD style init SYSV compatible Vserver tutorial linux-vserver.org's Installation on ArchLinux linux-verserver.org's networking tutorial