Disk quota

From ArchWiki
Revision as of 12:35, 3 September 2007 by Farch (talk | contribs) (added group quotes settings)
Jump to: navigation, search

After starting administrating the network on a little school, I did learn quite a lot about Linux. Here's some of it.

Installing Quota-tools

This is a little HOWTO to setup Userquota on Arch Linux. First of all you need a full functional Arch Linux machine. Afterwards we need to get the package quota-tools.

$ pacman -Sy quota-tools


Now we got the things we need. and are ready for the configuration. First we need to edit /etc/fstab - thats where we decide which mounts we need to make a quota on. Let's say we have a special harddrive thats mounted in /home - the line in /etc/fstab looks like this:

/dev/hdb1 /home ext3 defaults 1 1

we need to edit it to this

/dev/hdb1 /home ext3 defaults,usrquota 1 1
That's it here, so the next part is to start quota and make it index the files.
$ mount -v -o remount /home    <-- to remount home
$ quotacheck -a -m             <-- to make an index over the files 
$ quotaon -uv /home            <-- start quota

The last line may answer with this error: The kernel does not support quota - you need to recompile it
I did a reboot and everything worked afterwards. (You can change /home to -a in the last line, then it starts on all devices )

quotaon must be run everytime the machine starts, so its a good idea to make a startscript or put it into rc.local

The user quotes

Now we shall setup how much the users quantum of space will be. That's where we use this command:

$ edquota -u quotauser
Disk quotas for user quotauser (uid 500):
Filesystem      blocks       soft       hard     inodes     soft   hard       
/dev/hda2       695879         0           0       6741        0      0

Here is the idea to make a testuser, then afterwards copy the files to all the users. The limits is here defined in kbytes - so that 10000 = 10MB. If the qoutas is not setup, the default is there's no limits. We can also see that the user quotauser in this moment uses 695879 fileblocks (679MB) and 6741 files with no limits on. Now edit the number so it looks like this:

Disk quotas for user quotauser (uid 500):
Filesystem      blocks       soft       hard     inodes     soft   hard       
/dev/hda2       695879       10000      15000     6741        0      0

This means that the user ALWAYS can use 10MB of space, and can be graced for a period for 5 more. If you want to set the grace time, you can do it with:

$ edquota -t 
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem      Block grace period      Inode grace period
/dev/hda2        7 days                    7days

The trick about using a testuser, is that you really easy can copy the quota to all users on your system. Done by:

$ edquota -p quotauser `awk -F: '$3 > 499 {print $1}' /etc/passwd`

Here makes the same settings on all users with uid on 500 and above..

The group quotes

/dev/hdb1 /home ext3 defaults,usrquota,grpquota 1 1

$quotacheck -acguvm  <-- to make an index over the files

= Other interesting commands =
There are several interesting commands, but here are some of them:
* repquota -a      <-- shows the status on diskusage
* warnquota        <-- can be used to warn the users about their quota
(warnquota sends mail to the users, is the files /etc/quotatab & /etc/warnquota.conf. These are used to make the messages more readable)

at last the quotastats is used to give info about the quota system:

$ quotastats
Number of dquot lookups: 101289
Number of dquot drops: 101271
Number of still active inodes with quota : 18
Number of dquot reads: 93
Number of dquot writes: 2077
Number of quotafile syncs: 134518740
Number of dquot cache hits: 7391
Number of allocated dquots: 90
Number of free dquots: 2036
Number of in use dquot entries (user/group): -1946

More info

Please be free to edit/add comments or corrections about this page.