Difference between revisions of "Arch VServer"

From ArchWiki
Jump to: navigation, search
m
Line 5: Line 5:
 
=Introduction=
 
=Introduction=
  
This article aims to provide all necessary information about setting virtual servers on Arch Linux. You can setup virtual servers to provide different services on just one machine as if they were on different machines with a very little power loss. You can get more information about virtual servers [http://en.wikipedia.org/wiki/Virtual_private_server here].
+
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 [http://en.wikipedia.org/wiki/Virtual_private_server here].
  
=Installation=
+
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) ( [[User:Delerious010|Delerious010]] 11:30, 15 November 2009 (EST) ).
You need the patched kernel.
+
  
kernel26-vserver is available in [http://aur.archlinux.org/packages.php?ID=24281 AUR]
+
=Preparing the Host=
  
For more secure chroots and compatibility you need '''''dietlibc''''' and '''''beecrypt'''''.
+
To prepare the vserver host environment, you will need to install both a patch kernel and the vserver utilities which are located in [http://wiki.archlinux.org/index.php/AUR AUR]. In the following steps, the instructions are provided using [http://wiki.archlinux.org/index.php/Yaourt 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
  
dietlibc is available in [community] repository, therefore you can manually download and install it or you can comment out [community] in your pacman.conf and install it via pacman:
+
'''Please note''' : Since vserver requires a patched kernel, it's possible that your vserver kernel may lag behind the standard kernel26 package release.
  
pacman -Sy dietlibc
+
=Paths of Interest=
  
beecrypt is available in [http://aur.archlinux.org/packages.php?ID=16387 AUR].
+
'''/etc/vservers''' : configuration root ( [http://www.nongnu.org/util-vserver/doc/conf/configuration.html ''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
  
Next, you need util-vserver to administer the guests. (creating aur package//adopting it..)
+
=Preparing the Guests=
  
=Configuration=
+
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 [http://wiki.archlinux.org/index.php/Install_From_Existing_Linux 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><br>'''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 \<br> --context <unique context number ... 1 through ???> \<br> --interface <device:ip/netmask> \<br> --flags lock,virt_mem,virt_uptime,virt_cpu,virt_load,sched_hard,hide_netif \<br> --initstyle plain
 +
## 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=
 
=Troubleshooting=
Line 29: Line 83:
  
 
=More Resources=
 
=More Resources=
[http://linux-vserver.org/Installation_on_ArchLinux http://linux-vserver.org/Installation_on_ArchLinux]
+
[http://linux-vserver.org/Problematic_Programs Problematic Programs]
 +
[http://linux-vserver.org/Howto_make_bsd-style_init_sysv-compatible Make BSD style init SYSV compatible]
 +
[http://www.cedarcreeksoftware.com/an-even-easier-linux-vserver-tutorial.html Vserver tutorial]
 +
[http://linux-vserver.org/Installation_on_ArchLinux linux-vserver.org's Installation on ArchLinux]
 +
[http://wiki.linux-vserver.org/Networking_vserver_guests linux-verserver.org's networking tutorial]
 
<!-- vim: set ft=Wikipedia: -->
 
<!-- vim: set ft=Wikipedia: -->

Revision as of 16:30, 15 November 2009

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