Step by Step Linux Vserver
Step by Step Linux Vserver
Step by Step Linux Vserver
6 - Linux-VServer
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
We currently migrate to MediaWiki from our old installation, but not all content has been migrated yet. Take a look at the Wiki Team page for instructions how to help or browse through our new wiki at wiki.linux-vserver.org to find the information already migrated.
Now that we have a place to store our sources, we need to fetch them. We start with the vanilla
1 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
sources.
# Get Linux 2.6.14.3 sources wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.14.3.tar.bz2 # Extract them tar xjf linux-2.6.14.3.tar.bz2
Now it's time to get the Linux-VServer patch and apply it to the sources. While we're at it, I'll tell you a nice trick I learned from Bertl, that allows you to keep a lot source trees on your disk without using up lots of disk space (and this also speeds up 'diff' a lot, which is really nice if you do kernel-hacking). What we do is creating a hard-linked copy of our sources and patch this copy with the Linux-VServer patch. That way, only the patched files use additional disk space (and because hard-linked files are equal by definition, diff doesn't need to compare them ;). So let's go.
# Get the Linux-VServer 2.01 patch wget http://www.13thfloor.at/vserver/s_rel26/v2.01/patch-2.6.14.3-vs2.01.diff.bz2 # Create a hard-linked copy of the vanilla sources, this will get the Linux-VServer p cp -la linux-2.6.14.3 linux-2.6.14.3-vs2.01 # Switch to that new directory cd linux-2.6.14.3-vs2.01 # Patch the sources bzip2 -dc ../patch-2.6.14.3-vs2.01.diff.bz2 | patch -p1
Now we got two sources, the vanilla sources for 2.6.14.3 and the Linux-VServer sources for 2.6.14.3vs2.01. You might ask "Why do we need two source trees at all? I only want one kernel!" and that's a good question. Here's one answer: Updates! If a new vanilla kernel is released, you can just download the patch from your version to the new version, if you had patched your one and only vanilla source tree, you couldn't do this. And if a new Linux-VServer patch is released, you can simply create another hardlinked copy of your vanilla sources and apply the new patch there. This can really save you time (and bandwith), because you can keep everything you might need, without wasting lots of disk space. But be aware that this needs some disciple when hacking the source. Because hard-linked files share the same data on the disk, you need to make sure that your editor does The Right Thing, otherwise you might mess up all your source trees... (I might write some docs about working with hard-linked source trees sometimes... ;)
2 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
# Create a hard-linked copy of the patched sources cp -la linux-2.6.14.3-vs2.01 linux-2.6.14.3-vs2.01-build # Switch to that new source tree cd linux-2.6.14.3-vs2.01-build
Now let's start configuring that copy, I'll only explain some of the Linux-VServer-specific kernel configuration options here (as of 2.0), the rest is up to you ;). You can choose whatever configuration method you like, for example:
# Configure the kernel using a ncurses based menu make menuconfig
3 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
make
If you don't happen to have a really fast box, it is a good time to get a new cup of coffee now ;)
util-vserver installation
The kernel alone won't help you, you also need some tools to exploit all those new features you got, so let's get them. The latest tools can be found [here]. For Linux-VServer on 2.6 kernels you should use the alpha tools, as only those support the new features (and don't worry, they're also pretty rock-stable). I'll use util-vserver 0.30.210 in this document, you should use whatever is latest. As a first step, of course, we need to get the sources.
#if you are using debian or a debian drived distribution the add the source repositor #then do su apt-get build-dep util-vserver exit #the above will install many of the required tool to compile util-vserver # Go to our source directory cd ~/src # Get the sources for alpha util-vserver wget http://www.13thfloor.at/~ensc/util-vserver/files/alpha/util-vserver-0.30.210.tar # Extract the sources tar xjf util-vserver-0.30.210.tar.bz2
Now that we got our sources, we need to do the usual steps: configure, make, make install. While configuring the tools you may get some error messages about missing stuff, for example dietlibc, vconfig and e2fs headers. The error messages are accompanied by explanations what you should do, so read them carefully.
# Switch to the util-vserver source directory cd util-vserver-0.30.210 # Configure the sources (you may want to adjust settings here, the defaults work, but ./configure # Build the tools make # Become root su -
4 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
# Install the tools make install # It's a good point to fix the /proc entries for the guests /etc/init.d/vprocunhide restart (this path depends on configuration, see output of 'v # Back to our regular user exit
Now we got our tools in place and we're ready to build our first vserver!
Testing
Oh, wait, we're not ready yet! To be sure that your setup works fine, we got a test script that checks some basic functionality. So download the [testme.sh] script and check if everything's fine.
# Back to our source directory cd ~/src # Get the script wget http://vserver.13thfloor.at/Stuff/SCRIPT/testme.sh # Make it executable chmod +x testme.sh # Become root su # Run the test script ./testme.sh # Back to our regular user exit
If the script shows any errors, feel free to join us on irc (#vserver @ OFTC) or ask on the [mailing list]. If you ask on the mailing list, don't forget to include your kernel version, the version of the Linux-VServer patch, the version of util-vserver and of course the output of the test script.
5 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
blame us for the /var/lib/vservers path, that's a debian oddity, all other distros we know of use /vservers -- Bertl) The second step, setting the barrier flag on the base directory, is needed so guests can't escape from their chroot. On Linux 2.6 this isn't really necessary, since another mechanism is used to lock in the guests anyway, but it can't hurt to be on the save side.
# The old link pointed to /var/lib/vservers ls -la /etc/vservers/.defaults/vdirbase lrwxr-xr-x 1 root root 17 2005-06-18 13:26 /etc/vservers/.defaults/vdirbase -> / # So now we set it to our desired directory rm /etc/vservers/.defaults/vdirbase ln -s /home/vservers /etc/vservers/.defaults/vdirbase ls -la /etc/vservers/.defaults/vdirbase lrwxrwxrwx 1 root root 14 2005-06-18 23:26 /etc/vservers/.defaults/vdirbase -> / # And set a chroot barrier flag on that directory, # using setattr from the vserver tools setattr --barrier /home/vservers/ # We use showattr to display the flags set on that dir, # -d is used to get the flags on the directory, rather then on the content. showattr -d /home/vservers/ ---Bui- /home/vservers/ # The uppercase B shows us that the barrier flag is set now
So, after you have (or have not) done this, we are ready to set up our first vserver.
vserver DebianSid build -m debootstrap -- -d sid -m ftp://ftp.at.debian.org/debian/ # Watch debootstrap set up the guest.
This will setup a vserver in /home/vservers/DebianSid? (depends on the setting of vdirbase, cf. above). Management data is stored in /etc/vservers/DebianSid?. Additionally there will be some runtime data in /var/run/vservers/DebianSid? and /var/run/vservers.rev.
6 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
If something went wrong just delete these directories (except /var/run/vservers.rev, there just delete the entry that points to /etc/vservers/DebianSid?, if any), and re-run the vserver build command. While you wait for debootstrap to finish it might be a good idea to read the [flower page], which is a comprehensive documentation of the configuration options for vserver and its guests. You may wish to save it on your harddisk and view it there, just to get rid of the annoying stylesheet. So, debootstrap (or whatever method you used) is finished, you could start up our vserver, but it's not a good idea yet (of course I learned this the hard way ;). Most bootstrapping methods configure the guest as they would configure a real system. They install init scripts for all kinds stuff (setup of the console, setting the system clock, mounting drives, mounting /sys and /proc, ...). But you don't want the guests to do those things on startup/shutdown, since they are either handled by the host itself or by vserver. There doesn't happen anything fatal if you don't disable these scripts (since the guests just don't have the permission to do those things per default) but you'll get lots of scary error messages. What you have to delete (and where the init scripts are stored in the first place) will depend heavily on your system. Below you can see what I did to clean up my init scripts.
cd /home/vservers/DebianSid/etc/rc0.d rm K20makedev K25hwclock.sh S30urandom S31umountnfs.sh cd /home/vservers/DebianSid/etc/rc6.d rm K20makedev K25hwclock.sh S30urandom S31umountnfs.sh
cd /home/vservers/DebianSid/etc/rcS.d rm S05keymap.sh S48console-screen.sh S50hwclock.sh S40networking S45mountnfs.sh S10c rm S30procps.sh S35mountall.sh S36mountvirtfs S39ifupdown S30checkfs.sh S18ifupdown-c cd /home/vservers/DebianSid/etc/rc2.d rm S20makedev S11klogd
Here's some hints on what you want to delete: everything that has something to do with mouting, networking (interfaces/ifupdown), the hardware clock (hwclock), console, creation of device nodes (makedev) and probably the halt/reboot stuff. You can also disable the klogd (kernel log daemon). It doesn't print error messages, but it doesn't get any data to log from the kernel, so it's pointless. Stuff you probably don't want to kill includes sysklogd (the syslog daemon, not the kernel log daemon), cron, inetd (really depends on what you want to use the guest for), other logging stuff (bootlogd perhaps) and other stuff you might think you need.
7 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
vserver DebianSid stop Stopping periodic command scheduler: cron. Stopping internet superserver: inetd. Stopping system log daemon: syslogd. Sending all processes the TERM signal...done. Sending all processes the KILL signal...done.
If it works like this everything is fine, and you can check out what you can do in the guest. You probably want to run
base-config
to get the Debian distribution installed to useable point. Please simply ignore the annoying error messagees about "LC stuff" - they vanish after base-config. (note: using 'LC_ALL=C LANG=C' might avoid those 'issues') In the next chapter we'll look at some configuration stuff. The rest of this chapter is dedicated for those that didn't get it to work that well yet.
Possible problems
I had some minor problems before getting the guest to start up so nicely, I hope this section helps others who run into the same problems.
Alternativ you can give the host another Port for ssh. Try to run all services in a VServer, not on the host. Error message that mount failed when starting up: This one is not fatal, the guest starts up as normal anyway. It's annoying though.
vserver DebianSid start mount: wrong fs type, bad option, bad superblock on none, missing codepage or other error In some cases useful info is found in syslog - try dmesg | tail or so /etc/vservers/DebianSid/fstab:2:1: failed to mount fstab-entry
The last line tells us that the problem is not inside the guest, but it's in the vserver setup of the guest. The entry on line 2 in /etc/vservers/DebianSid?/fstab could not be mounted. The entry was to mount a tmpfs virtual file system on /tmp. Since I don't have tmpfs built into my kernel
8 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
(CONFIG_TMPFS unset), this didn't work. Commenting out the line fixed the problem. Error message regarding permissions on enter: Also non-fatal, but annoying:
vserver DebianSid enter mesg: /dev/pts/1: Operation not permitted
I don't fully understand this one, but it seems to be a problem in util-vserver. The bug depends on the method how you got root in the host. If you got root by "su", the problem shows itself. If you used "su -" (which spawns a login shell as root), it won't. (note: this is not a bug, this is the pts security in action, which prohibits the guest from messing with a pts allocated on the host -- Bertl) So if this really annoys you so much, use "su -" to get root, or better yet, fix it in the vserver tools and send a patch :)
Configuration
Yet to be written. This will be updated when I finally overcome my lazyness, or when someone else comes by and feels sorry for this page for not being updated in such a long time ;) In the meantime, you can check out the [flower page] I mentioned above. Behind the angry fruit salad hides some valuable information. Note: before you turn blind, try to see if your browser lets you switch the page style. On Firefox, you fid this option in the menu: View->Page Style Select 'boring' and it actually becomes readable.
Migration
This part covers the migration from the old (<= 1.2.10) config style to the new one (2.0+). It starts right away with the files necessary for making your old vservers work (this is based on a Debian guest system!). I used the [flower page] to understand the options as well as the skeleton setup method to create the minimum setup files. If you followed this step-by-step guide, your directory holding the config files should be /etc/vservers/. If it's in a different place, replace /etc/vservers/ with the correct path corresponding to your setup! Everything that doesn't end with a "/" is supposed to be a file and not a directory. The contents of a file is the value of the config option or in some cases a script. /etc/vservers/<vserver-name>/context Usually you won't need this, just create this file if you are using a fixed context for your vserver (i.e. 5) /etc/vservers/<vserver-name>/fstab Stuff that will be mounted within the vserver
none none /proc /dev/pts proc devpts defaults gid=5,mode=620 0 0 0 0
Hint: In case you are using LVM, physically mount those LVM devices on boot in the
9 de 10
http://oldwiki.linux-vserver.org/Step-by-Step+Guide+2.6
fstab of your hostsystem. Then include a bind mount in the fstab config file for the vserver above, i.e.
<path-to-mounted-lvm> / none bind
/etc/vservers/<vserver-name>/interfaces/<interface-number>/ Add a directory for each IP you want to assign (i.e. 1/, 2/, 3/ and so on) /etc/vservers/<vserver-name>/<interface-number>/dev Device the IP will be bound to (i.e. eth0) /etc/vservers/<vserver-name>/<interface-number>/ip The actual ip address (i.e. 192.168.1.1) /etc/vservers/<vserver-name>/<interface-number>/prefix The Prefix (i.e. 24; check [this page] for more info) /etc/vservers/<vserver-name>/<interface-number>/name Optional, but if present the interface will show up in ifconfig, if not present the interface will only show up in "ip addr show" /etc/vservers/<vserver-name>/name Name of the vserver (i.e. DebianSid?) /etc/vservers/<vserver-name>/run Symbolic link (ln -s) to /var/run/vservers/<vserver-name> If the vserver is not started the destination for the link might not exist, this doesn't matter /etc/vservers/<vserver-name>/uts/nodename Hostname (i.e. debiansid.com) vdir Symbolic link (ln -s) to /etc/vservers/.defaults/vdirbase/<vserver-name> These files are required in case you're using LVM, because the values can't be found automatically on vserver start. /etc/vservers/<vserver-name>/apps/init/cmd.stop Enter "/etc/init.d/rc" in the first line and "6" in the second line (i.e. if you are using a Debian as guest system and want runlevel 6 to be your shutdown runlevel) /etc/vservers/<vserver-name>/apps/init/runlevel Number of the runlevel to start (i.e. 2) /etc/vservers/<vserver-name>/shell The default shell for "vserver <name> enter" (i.e. /bin/bash) Entry in the fstab file for the LVM mount (see "/etc/vservers/<vserver-name>/fstab" above!) For all the other options, check out the [flower page].
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
10 de 10