You can find an easier to read version of this howto at 5dollarwhitebox.org.
Quoted from 13thfloor.at/vserver/project:
Linux-VServer allows you to create virtual private servers and security contexts which operate like a normal Linux server, but allow many independent servers to be run simultaneously in one box at full speed. All services, such as ssh, mail, Web, and databases, can be started on such a VPS, without modification, just like on any real server. Each virtual server has its own user account database and root password and doesn't interfere with other virtual servers.
You can find a presentation on Linux-vserver at http://www.linux-vserver.org.
The two main terms to know are:
- Host System: This is the physical server that "hosts" the Guest OSs (virtual servers).
- Guest System: These are the virtual servers that run on top of the Host OS.
Start out with a fresh install of Debian Sarge 3.1. It is recommended to keep the host system as minimal as possible (I rarely see any reason to run any more than SSH and iptables).
Packages to install
Always update your apt database before installing software, and upgrade current packages:# apt-get update && apt-get upgrade
Then we need to install a few basic packages:
- util-vserver: Userland utilities to control virtual servers
- ssh: This should probably have been installed already
- ncurses-base, and libncurses5-dev: Needed for "make menuconfig" when compiling kernel.
# apt-get install util-vserver ssh ncurses-base libncurses5-dev
|/var/lib/vservers||Home directory for the vservers files|
|/etc/vservers.conf||basic config file (not much to see there)|
|/etc/vservers||Hold the config directories for each virtual server|
|/usr/sbin/vserver||Utility to interact, build, start, stop, enter, etc the vservers|
|/bin/vshelper||Another utility to control how vservers function|
Please that I have not done this section "The Debian Way". Everything was done using a Vanilla kernel from kernel.org. You can find good links in the user comments below for other resources. Get the latest Kernel, currently linux-vserver latest stable release is for the 184.108.40.206 kernel.. which is what we get:# cd /usr/src
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-220.127.116.11.tar.gz
# wget http://www.13thfloor.at/vserver/s_rel26/v2.0/patch-18.104.22.168-vs2.0.diff.gz
Get the latest kernel patch from linux-vserver.org or 13thfloor.at/vserver:
# tar -zxvf linux-22.214.171.124.tar.gz
# gunzip patch-126.96.36.199-vs2.0.diff.gz
# mv patch-188.8.131.52-vs2.0.diff /usr/src/linux-184.108.40.206
# Patch the kernel sources:
# cd /usr/src/linux-220.127.116.11
# cat patch-18.104.22.168-vs2.0.diff | patch -p1
# cp /boot/config-2.6.X /usr/src/linux-22.214.171.124/.config
If you're already running a similar 2.6.x kernel you can copy your current config before building. It should be somewhere like "/boot/config-2.6.x"
That last command is only if you want to use an existing config... please don't attempt to use a 2.4.X config file... pretty please. ;)
# make menuconfig
Ok, lets make this happen. There are a few things that you want to include when we compile. First things first though, you need to have a working compile for your system... and that I can not help you with. Please reference link if you need help compiling a kernel.
For future use, you should probably include LVM (and dev-mapper support)... as this is handy for virtual servers.
Enable Legacy kernel API
You see a category for "Linux Vserver". The default selections should be groovy, however you should have something like the following selected:
Enable Proc Security
Enable Hard CPU Limits
Cool... now we have our config.... lets make the kernel:
# make modules_install
# cp .config /boot/config-126.96.36.199-vs2.0
# cp System.map /boot/System.map-188.8.131.52-vs2.0
# cp arch/i386/boot/bzImage /boot/vmlinuz-184.108.40.206-vs2.0
# mkinitrd -o /boot/initrd.img-220.127.116.11-vs2.0 18.104.22.168-vs2.0
Using the 'vi' command edit /boot/grub/menu.lst and add the following lines *BEFORE* the other entries already there... and make sure that the line "default" is set to "0":title Vanilla 22.214.171.124-vs2.0
Then we will want to update our grub config:
kernel /vmlinuz-126.96.36.199-vs2.0 root=/dev/hda2 ro
And there you have it. Now, we should be able to reboot and have our new kernel ready for some virtual servers.
# uname -r
Check that kernel after we boot up to make sure we're running on the new one:
Setting Up The Virtual Servers
Creating virtual Debian Servers on a Debian host is next to ridiculously simple. The following lays it out for you:# vserver <VSERVER_NAME> build \
-n <VSERVER_NAME> \
--hostname <FQDN> \
--interface <NET_DEVICE>:<IP>/<CIDR> \
-m debootstrap -- -d <DEBIAN_DISTRO>
So, our first virtual server will have the following information:
# vserver vserver1 build \
Therefore, the following command will create it:
-n vserver1 \
--hostname vserver1.mydomain.com \
--interface eth0:192.168.1.10/24 \
-m debootstrap -- -d sarge
The backslashes '\' signify a new line... however you can execute this all as one command without the use of backslashes.
And there you go... the installation begins a debian net install of the selected distro. This should take no more than a few minutes. On my system, the base install only takes up 144MB. Now lets see what we have:
# ls -lah /var/lib/vservers/vserver1
drwxr-xr-x 20 root root 4.0K Nov 10 08:17 .
drwxr-xr-x 4 root root 4.0K Nov 10 08:13 ..
drwxr-xr-x 2 root root 4.0K Nov 10 08:17 bin
drwxr-xr-x 2 root root 4.0K Dec 15 2004 boot
drwxr-xr-x 3 root root 4.0K Nov 10 08:13 dev
drwxr-xr-x 37 root root 4.0K Nov 10 08:17 etc
drwxrwsr-x 2 root staff 4.0K Dec 15 2004 home
drwxr-xr-x 2 root root 4.0K Nov 10 08:16 initrd
drwxr-xr-x 7 root root 4.0K Nov 10 08:17 lib
drwxr-xr-x 2 root root 4.0K Nov 10 08:16 media
drwxr-xr-x 2 root root 4.0K Dec 15 2004 mnt
drwxr-xr-x 2 root root 4.0K Nov 10 08:16 opt
drwxr-xr-x 2 root root 4.0K Dec 15 2004 proc
drwxr-xr-x 2 root root 4.0K Nov 10 08:16 root
drwxr-xr-x 2 root root 4.0K Nov 10 08:17 sbin
drwxr-xr-x 2 root root 4.0K Nov 10 08:16 srv
drwxr-xr-x 2 root root 4.0K May 10 2005 sys
drwxrwxrwt 2 root root 4.0K Nov 10 08:17 tmp
drwxr-xr-x 11 root root 4.0K Nov 10 08:16 usr
drwxr-xr-x 13 root root 4.0K Nov 10 08:16 var# ls -lah /etc/vservers/vserver1
drwxr-xr-x 5 root root 4.0K Nov 10 08:13 .
drwxr-xr-x 6 root root 4.0K Nov 10 08:13 ..
drwxr-xr-x 4 root root 4.0K Nov 10 08:13 apps
-rw-r--r-- 1 root root 112 Nov 10 08:13 fstab
drwxr-xr-x 3 root root 4.0K Nov 10 08:13 interfaces
-rw-r--r-- 1 root root 5 Nov 10 08:13 name
lrwxrwxrwx 1 root root 22 Nov 10 08:13 run -> /var/run/vservers/vserver1
drwxr-xr-x 2 root root 4.0K Nov 10 08:13 uts
lrwxrwxrwx 1 root root 37 Nov 10 08:13 vdir -> /etc/vservers/.defaults/vdirbase/vserver1
# vserver <VSERVER_NAME> [ start | stop | restart | enter ]
Now that we have our vserver installed, lets start it up. The syntax for the 'vserver' command is:
# vserver vserver1 startStarting system log daemon: syslogd.
And for our vserver1:
Starting kernel log daemon: klogd.
Starting MTA: exim4.
Starting internet superserver: inetd.
Starting deferred execution scheduler: atd.
Starting periodic command scheduler: cron.
CTX PROC VSZ RSS userTIME sysTIME UPTIME NAME
0 35 73.4M 5.4K 0m05s21 0m02s33 1m13s00 root server
49152 5 11M 967 0m00s00 0m00s00 0m30s52 vserver1
# vserver vserver1 enter
And you're now in the context of the virtual server. To get out and back to the host system, just type "exit".
Notes on Configuration
You'll first need to run "apt-setup" and configure apt same as any other debian system. The debian bootstrap install is a very minimal base installation. You will need to install everything that you want.
It should be mentioned that each virtual server has its own IP address. However, since these IPs are configured as Aliases to you actually net device (i.e. eth0) they are all listening on the same physical device. This can pose a problem when default configurations specify to "Listen" on all interfaces. Every service within the vserver must specify a Listen Address.
SSH:# apt-get install sshd
# vi /etc/ssh/sshd_config
Change the line:
# /etc/init.d/ssh restart
The rest is really up to your imagination and figuring out the wonders of undocumented open source... have fun!
BJ Dierkes, RHCE-LPIC1
wdierkes [at] 5dollarwhitebox [dot] org