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.

Context Disk Limits on Kernel 2.6.x (vs2.0)

With this howto, you can limit the disk-usage for a single vserver. This does not cover quotas inside a vserver.

The trick to make this working is, to tag all files which belong to a context-id with this context-id. The patch for this is already included in vs2.0. After the files are tagged, you initialize the simulated "free disk space" with the vdlimit tool for every vserver.

This tool has to be run after every boot of the host-system, because it only *initializes* the values. By storing the values at system-shutdown and loading them again on startup, you can circumvent the expensive call to "du" and "ls -R" (which you will see below). According to IRC, lycos and rosehosting make it that way.

After the system is up, the values are kept up-to-date automagically.

1. Tag files with context-id

To make this work, you have to mount the partition for your vservers with the "tagxid"-option. This mount-option tags each inode with the context-ID, so every file can be associated with the corrosponding context-id.

mount -o tagxid,rw /dev/whatever /wherever

or in fstab (for example):

/dev/whatever /wherever ext3 defaults,tagxid 0 2

If you already have a bunch of files on your vserver, you can tag the inodes/files (?) afterwards with the chxid-program. For example, tag it with context-id 50:

chxid -c 50 -R /wherever/vhost0/

2. Limit usage

This was recommended on IRC to get Disk Limits working on a per context basis (per vserver). This has to be run after every boot of the host-system. Please read above for a smart option (store on shutdown, load on startup).

You can either run it as just-another-job on system-startup or you can (as I prefer) put it as a oneliner-shellscript into /etc/vservers/servername/scripts/prepre-start.d.

Syntax:

/usr/sbin/vdlimit --xid <number> --set space_total=<size_in_kilobytes>
--set space_used=`du -s /vservers/<vserver_name>/ | awk '{print $1}'`
--set inodes_total=<number_of_inodes>
--set inodes_used=`ls -1aRi /vservers/<vserver_name>/ | awk '/^[0-9]+ / { print $1 }' |
sort -u | wc -l` --set reserved=5 /vservers/<vserver_name>/

Example (setting a vserver called test1 with context 100 to 4 GB):

/usr/sbin/vdlimit --xid 100 --set space_total=4000000 --set space_used=`du -s /vservers/test1/ | awk '{print $1}'`
--set inodes_total=4000000 --set inodes_used=`ls -1aRi /vservers/test1/ | awk '/^[0-9]+ / { print $1 }' | sort -u |
wc -l` --set reserved=5 /vservers/test1/

This will make it look like the hard drive is actually that size from within the vserver:

Filesystem            Size  Used Avail Use% Mounted on
/dev/hdv1             3.9G  2.2G  1.5G  59% /

Note: If running this on an existing vserver, make sure that the du command's result is not bigger then the limit you are setting. It will return an error and then blow away your / mount, causing major disk space problems! :) See [bug# 14026]

Note2: 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 :)

Note3: 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)