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 v2.0. This only works on ext2 and ext3 at the moment. 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. They are kept up-to-date afterwards 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/file (?) 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

And don't forget to use ext2 or ext3 as filesystem for this partition, because the tagxid-option is only available for those two!

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 Quotas working on a per context basis (per vserver). I have tried it and it appears to work. It was also recommended to run this once per reboot, so it could go in the /etc/rc.local file or something. I have put it into /etc/vservers/servername/scripts/poststart, which is where I think it would fit better, but it doesn't seem to be automatically executed when the vserver is started. I need to further investigate this and perhaps submit a bug report. Technically, it would be nice if all this was implemented with the tools...

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]