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 :
- 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.
- (optional) Create LVM volume via lvcreate.
- (optional) Create filesystem on lvm volume / disk partition.
- (optional) Mount newly create filesystem to /vserver/<guest>
- (optional) Link new guests pacman package cache to the host's
- mkdir -p /vserver/<guest>/var/cache/pacman/pkg
- mount -o bind /var/cache/pacman/pkg /vserver/<guest>/var/cache/pacman/pkg
- Prepare guest filesystem for pacman db and install base packages
- mkdir -p /newarch/var/lib/pacman
- 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>
- (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.
- Bind /dev, /proc, /sys to the corresponding directories in /vserver/<guest>
- Modify guest configuration files to enable a smoother boot process
- /etc/inittab : Delete all lines that create the consoles ( agetty )
- /etc/rc.shutdown : Still modifying this, but basically you want to remove anything hardware related. This includes most everything under Saving Random Seed'.
- Create /etc/init.d/rc which vserver will call rather than /etc/rc.sysinit.
- Create a vserver instance for our newly create filesystem
- 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 \
- To start on boot : echo default > /etc/vservers/<guest>/apps/init/mark
- vserver <guest name> build -m skeleton \
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