Setup disk quotas on Debian
Quotas are a simple mean to limit the disk usage of some software or users. This article list some of the methods used to implement disk quotas on Debian.
This howto is tested on :
- Debian 6.0 Squeeze
Quotas on folders
Quotas described in this article are global to file systems. To set quotas on different folders for a unique user, the easiest way is to use the Logical Volume Manager LVM or loopback devices. Create an LVM disk for each folder you want the size of limited.
Installation
Operating System configuration
Load the kernel module responsible for the management of quotas, and make sure it is loaded at system startup :
command modprobe quota_v2 if [ -z "$(command grep 'quota_v2' '/etc/modules')" ]; then command echo 'quota_v2' >> '/etc/modules' fi
Install the quotas management tools :
command apt-get install quota quotatool
File System configuration
To support quotas, a file system must be mounted with the "usrquota" option.
Provide the file system device for witch you want to enable quotas :
FS_DEV="/dev/sda3"
Add the usrquota option to file system fstab line :
command sed -i \ -e "s|^\(${FS_DEV}[ \t]*[^ \t]*[ \t]*[^ \t]*[ \t]*[^ \t]*\)\([ \t].*\)$|\1,usrquota\2|" \ '/etc/fstab'
Remount the file system with the needed option :
command mount -o remount,usrquota "${FS_DEV}"
Fetch the file system mount point :
FS_MOUNT="$(command mount \ | command grep "${FS_DEV}" \ | command cut --delimiter=" " --fields=3)"
Create the quotas informations storages :
if [ ! -e "${FS_MOUNT}/aquota.user" ]; then command touch "${FS_MOUNT}/aquota.user" command chmod 600 "${FS_MOUNT}/aquota.user" fi if [ ! -e "${FS_MOUNT}/aquota.qroup" ]; then command touch "${FS_MOUNT}/aquota.group" command chmod 600 "${FS_MOUNT}/aquota.group" fi
Enable quotas for the file system :
command quotacheck -vagum
Configuration
Place a 250MB quotas on /home for current user :
command quotatool -u "${USER}" -bq '200M' -l '250 MB' /home
Show all the quotas placed on /home :
command repquota /home
Thanks
- Thanks to Steve for his guide Limiting your users use of disk space with quotas on Debian Administration.