Difference between revisions of "Disk Limits and Quota"
From Linux-VServer
(→Activating disk limits) |
(→Activating disk limits) |
||
Line 17: | Line 17: | ||
## Create one sub-directory for each filesystem (in most cases, you should have only one), using any identifier (for example <tt>root</tt>) | ## Create one sub-directory for each filesystem (in most cases, you should have only one), using any identifier (for example <tt>root</tt>) | ||
## Under <tt>/etc/vservers/vs_name/dlimits/root/</tt> create the following files : | ## Under <tt>/etc/vservers/vs_name/dlimits/root/</tt> create the following files : | ||
− | ### <tt>directory</tt> : contains the directory to which the limit should be applied (for example /vservers/vs_name) | + | ### <tt>directory</tt> : contains the directory to which the limit should be applied (for example <tt>/vservers/vs_name</tt>) |
### <tt>inodes_total</tt> : the amount of inodes this vserver should be limited to | ### <tt>inodes_total</tt> : the amount of inodes this vserver should be limited to | ||
### <tt>reserved</tt> : how much space (percentage-wise) should be reserved for the root user | ### <tt>reserved</tt> : how much space (percentage-wise) should be reserved for the root user |
Revision as of 08:45, 21 April 2010
Contents |
Introduction
We call Disk Limit a disk space limit in a filesystem for one context (i.e. VServer). If you are interested in using user/group quotas inside a VServer, this is not the right place, look at the Quotas page.
Of course, you can also use a dedicated partition (or logical volume) for each guest, which is another way to limit disk space usage per guest.
Activating disk limits
For VServer version 2.0, please read http://oldwiki.linux-vserver.org/Disk+Limits
For VServer 2.2+, the procedure is nearly the same, only the mount option has changed:
- Activate the XID tagging on the filesystem hosting the VServer, using the tag mount option. You cannot use the remount option to add the tag on an already mounted filesystem. Be warn, it is not advised to use it on the root filesystem! In the next example, we use the /dev/sdb1 partition to host all the guests, under the /vservers directory
mount -o tag /dev/sdb1 /vservers
- Consider modifying your /etc/fstab file if necessary, to make the mount option persist across reboots
- Tag the files belonging to the VServer with its XID
chxid -URx -c vs_name /vservers/vs_name
- Write the limits under the /etc/vservers/vs_name/dlimits directory :
- Create this directory if necesary
- Create one sub-directory for each filesystem (in most cases, you should have only one), using any identifier (for example root)
- Under /etc/vservers/vs_name/dlimits/root/ create the following files :
- directory : contains the directory to which the limit should be applied (for example /vservers/vs_name)
- inodes_total : the amount of inodes this vserver should be limited to
- reserved : how much space (percentage-wise) should be reserved for the root user
- space_total : the amount of space this vserver should be limited to (measured in blocks of 1024 bytes)
Controling disk limits
After starting your VServer, you can control the actual limit using the vdlimit command (in this example, 300 is the context number associated with vs_name) :
- vdlimit --xid vs_name /vservers
300 /vservers space_used=154604 space_total=204800 inodes_used=7834 inodes_total=100000 reserved=5
You can also use the vdu command to count space or inodes used by a specific guest
- vdu --xid vs_name --space /vservers
/vservers 154604
- vdu --xid vs_name --inodes /vservers
/vservers 7834
If you just want to update disk usage of a guest activating disk limits, then you can use this script. It will count the usage of all files and update the limits:
#/bin/sh _dir=/var/lib/vservers if [ ! -d $_dir/$1 ]; then echo no such vserver exit 1; fi; chxid -URx -c $1 $_dir/$1 vdlimit --xid $1 -s space_used=$(vdu --xid $1 --space $_dir/$1 | cut -d" " -f2) $_dir/$1 vdlimit --xid $1 -s inodes_used=$(vdu --xid $1 --inode $_dir/$1 | cut -d" " -f2) $_dir/$1
Removing disk limits
To remove disk limits, remove the /etc/vservers/vs_name/dlimits/root directory and remove the limits with the following command
- vdlimit --xid vs_name --remove /vservers
More information
- See also dlimits on the util-vserver homepage http://www.nongnu.org/util-vserver/doc/conf/configuration.html
- For information about limiting diskspace with XFS, please see the XFS page.