Context Disk Limits on Kernel 2.6.x (vs2.0)
With this howto, you can limit the disk-usage for a single guest. This does not cover quotas inside a guest.
This version of this howto requires util-vserver 0.30.210. If you have an older version, [use an older version instead].
0. Make context of guest system static
The trick to make this working is, to tag all files which belong to a guest with a context ID (xid). Because you tag files with the xid, you must use static contexts for your guests (i.e. have a value between 2 and 49151 in /etc/vservers/<name>/context).
1. Mount the filesystem(s) with the tagxid-option
In order to tag files with the xid, your filesystem(s) must be mounted with the tagxid option. It might look something like this:
mount -o tagxid,rw /dev/whatever /vservers
or in fstab (for example):
/dev/whatever /vservers ext3 defaults,tagxid 0 2
2. Change the xid of already existing files
If you already have a bunch of files in your guest, you can tag the files afterwards with chxid. For example, to tag all files belonging to the test1 guest:
chxid -c test1 -R /vservers/test1/
You will have to repeat this for all filesystems your guest has write access to and that you intend to limit.
3. Set the disk limits
To limit the test1 guest to 5 GiB? and 100000 inodes on /vservers, you might use something like the following:
mkdir -p /etc/vservers/test1/dlimits/0 echo /vservers/test1 > /etc/vservers/test1/dlimits/0/directory echo $(( 5 * 1024 * 1024 )) > /etc/vservers/test1/dlimits/0/space_total echo 100000 > /etc/vservers/test1/dlimits/0/inodes_total echo 5 > /etc/vservers/test1/dlimits/0/reserved
It is preferable to put the full path to the guest in .../dlimits/*/directory rather than the mount point, because it will speed up the start time of the guest when the cache is missing.
If you created the guest with an older version of util-vserver (i.e. before 0.30.210) you will need to create the cache symlink:
ln -s /etc/vservers/.defaults/cachebase/test1 /etc/vservers/test1/cache
4. Start the guest
The first start (and subsequent starts after a non-graceful stop, i.e. after a power failure) after setting the disk limits will take a bit longer than usual, because the size of the guest has to calculated. After a graceful stop, the size of the guest is stored in a cache. If you add files while the guest is down from the outside that you later use chxid on, you will want to remove the cache file to get accurate results. It is typically stored in /usr/local/var/cache/vservers/dlimits/<xid><directory with _ instead of />.
Note: If your vserver-dir resides on your root filesystem, you might want to add rootflags=tagxid to your kernel args. That's because remounting with the tagxid option is not allowed, so when your distro wants to remount / read-write after fscking and you have the tagxid option in /etc/fstab the remount will fail and you are left with a read-only root filesystem.
(warning: it is not advised to mount the rootfs with tagxid -- Bertl :)
Note2: A simple script to do the chxid and vdlimit: http://people.linux.org.tw/~andrew/DiskLimit.sh -AndrewLee
there is an easier, more flexible, but also much more resource intensive way (no unification possible) to limit disk usage using lvm. (i shall document my next try and give full instructions later).