Difference between revisions of "Disk quota"

From ArchWiki
Jump to: navigation, search
(added journaled quotas, more templates)
Line 1: Line 1:
 
[[Category: Security (English)]]
 
[[Category: Security (English)]]
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]
After starting administrating the network on a little school, I did learn quite a lot about Linux. Here's some of it.
+
From [[Wikipedia:Disk quota|Wikipedia]]:
= Installing Quota-tools =
+
:"''A '''disk quota''' is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of setting diskquota to disks, is to allocate limited diskspace in a reasonable way.''"
This is a little HOWTO to setup Userquota on Arch Linux. First of all you need a full functional Arch Linux machine.
+
This article covers the installation and setup of disk quotas.
Afterwards we need to get the package ''quota-tools''.
+
<pre>
+
$ pacman -Sy quota-tools
+
</pre>
+
= Configuration =
+
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:
+
<pre>
+
/dev/hdb1 /home ext3 defaults 1 1
+
</pre>
+
we need to edit it to this
+
<pre>
+
/dev/hdb1 /home ext3 defaults,usrquota 1 1
+
</pre>
+
That's it here, so the next part is to start quota and make it index the files.
+
<pre>
+
$ mount -v -o remount /home    <-- to remount home
+
$ quotacheck -a -m            <-- to make an index over the files
+
$ quotaon -uv /home            <-- start quota
+
</pre>
+
The last line may answer with this error: ''The kernel does not support quota - you need to recompile it''<br>
+
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
+
==Installing==
 +
Disk quotas only require one package:
 +
# pacman -S quota-tools
  
= The user quotes =
+
==Enabling==
Now we shall setup how much the users quantum of space will be. That's where we use this command:
+
For journaled quotas, see the notes in [[#Journaled quotas]].
<pre>
+
$ 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
+
</pre>
+
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 quotas 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:
+
<pre>
+
Disk quotas for user quotauser (uid 500):
+
Filesystem      blocks      soft      hard    inodes    soft  hard     
+
/dev/hda2      695879      10000      15000    6741        0      0
+
</pre>
+
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:
+
<pre>
+
$ 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
+
</pre>
+
The trick about using a testuser, is that you really easy can copy the quota to all users on your system. Done by:
+
<pre>
+
$ edquota -p quotauser `awk -F: '$3 > 499 {print $1}' /etc/passwd`
+
</pre>
+
Here makes the same settings on all users with uid on 500 and above..
+
  
= The group quotes =
+
1. First, edit {{filename|/etc/fstab}} to enable the quota mount option(s) on selected file systems. Using the following line as an example:
<pre>
+
  /dev/sda1 /home ext4 defaults 1 1
/dev/hdb1 /home ext3 defaults,usrquota,grpquota 1 1
+
:edit it as follows;
</pre>
+
  /dev/sda1 /home ext4 defaults''',usrquota''' 1 1
$quotacheck -acguvm  <-- to make an index over the files
+
:or aditionally enable the group quota mount option;
 +
  /dev/sda1 /home ext4 defaults''',usrquota,grpquota''' 1 1
  
= Other interesting commands =
+
2. Create the quota files in the file-system:
There are several interesting commands, but here are some of them:
+
  # touch /home/aquota.user
<pre>
+
  # touch /home/aquota.group    # For group quota
* repquota -a      <-- shows the status on diskusage
+
 
* warnquota        <-- can be used to warn the users about their quota
+
2. The next step is to remount:
(warnquota sends mail to the users, is the files /etc/quotatab & /etc/warnquota.conf. These are used to make the messages more readable)
+
  # mount -vo remount /home
* setquota   <-- non-interactive quota setting (useful for scripting)
+
 
</pre>
+
4. Create the quota index to enable quotas:
at last the quotastats is used to give info about the quota system:
+
  # quotacheck -vgum /home
<pre>
+
:or for all partitions with the quota mount options in {{filename|/etc/mtab}};
$ quotastats
+
  # quotacheck -vguma
 +
 
 +
5. Finally, enable quotas:
 +
  # quotaon -av
 +
 
 +
{{tip|to automatically enable quotas on boot, add the previous command to {{filename|/etc/rc.local}}.}}
 +
 
 +
===Journaled quotas===
 +
Enabling journaling for disk quotas adds the same benefits journaled file-systems do for forced shutdowns; the data is less likely to become corrupt.
 +
 
 +
Setting up journaled quotas is the same as above, except for slightly different mount options:
 +
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,jqfmt=vfsv0''' 1 1
 +
or aditionally enable the group quota mount option;
 +
/dev/sda1 /home ext4 defaults''',usrjquota=aquota.user,grpjquota=aquota.grp,jqfmt=vfsv0''' 1 1
 +
 +
==Configurating==
 +
Replace {{Codeline|$USER}} as appropiate, and edit the quota as root:
 +
{{Command|name=edquota ''$USER''|output=
 +
Disk quotas for user '''$USER''' (uid 501):
 +
  Filesystem                  blocks      soft      hard    inodes    soft    hard
 +
  /dev/sda1                      1944          0          0        120        0        0
 +
}}
 +
;blocks: 1k blocks
 +
;inodes: Number of entries in directory file
 +
;soft: Max number of blocks/inodes user may have on partition before warning is issued and grace period countdown begins. If set to "0" (zero) then no limit is enforced.
 +
;hard: Max number of blocks/inodes user may have on partition. If set to "0" (zero) then no limit is enforced.
 +
{{note|to edit group quotas, use {{codeline|edquota -g $GROUP}}.}}
 +
 
 +
===Example setup===
 +
Editing the limits as below, for example:
 +
Disk quotas for user testuser (uid 500):
 +
Filesystem      blocks      soft      hard    inodes    soft  hard     
 +
/dev/sda1      695879      10000      15000    6741        0      0
 +
sets the following restrictions: the {{codeline|soft}} limit means that once testuser uses over 10MB of space, a warning gets ensued, and after a period of time, the soft limit gets enforced. The {{codeline|hard}} limit is stricter, so to speak; a user cannot go over this limit.
 +
 
 +
To alter the grace period:
 +
# edquota -t
 +
 
 +
==Managing==
 +
''Checking for quota limits and advanced operations''
 +
 
 +
===Basics===
 +
Use this command to check for quotas on a specific partition:
 +
# repquota /home
 +
 
 +
Use this command to check for all quotas that apply to a user:
 +
# quota -u $USER
 +
for groups;
 +
# quota -g $GROUP
 +
 
 +
===Copying quotas===
 +
The idea is to make a temporary user acount, modify the quota settings for that user, and then copy the generated quota files for all users to use. After setting quota settings for ''quotauser'', copy the settings:
 +
# edquota -p '''quotauser''' `awk -F: '$3 > 999 {print $1}' /etc/passwd`
 +
This applies the settings to users with a UID equal to or greater than 1000.
 +
 
 +
===Other commands===
 +
There are several useful commands, here are some of them:
 +
repquota -a      # Shows the status on diskusage
 +
warnquota        # Can be used to warn the users about their quota
 +
setquota         # Non-interactive quota setting--useful for scripting
 +
 
 +
Lasty, {{codeline|quotastats}} is used to give thorough information about the quota system:
 +
{{Command|name=quotastats|output=
 
Number of dquot lookups: 101289
 
Number of dquot lookups: 101289
 
Number of dquot drops: 101271
 
Number of dquot drops: 101271
Line 84: Line 102:
 
Number of free dquots: 2036
 
Number of free dquots: 2036
 
Number of in use dquot entries (user/group): -1946
 
Number of in use dquot entries (user/group): -1946
</pre>
+
}}
  
= More info =
+
==More resources==
 
* http://tldp.org/HOWTO/Quota.html
 
* http://tldp.org/HOWTO/Quota.html
 
* http://www.sf.net/projects/linuxquota/
 
* http://www.sf.net/projects/linuxquota/
 
+
* http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html
Please be free to edit/add comments or corrections about this page.
+
* http://www.redhat.com/docs/manuals/linux/RHL-8.0-Manual/admin-primer/s1-storage-quotas.html

Revision as of 01:11, 9 December 2009

From Wikipedia:

"A disk quota is a limit set by a system administrator that restricts certain aspects of file system usage on modern operating systems. The function of setting diskquota to disks, is to allocate limited diskspace in a reasonable way."

This article covers the installation and setup of disk quotas.

Installing

Disk quotas only require one package:

# pacman -S quota-tools

Enabling

For journaled quotas, see the notes in #Journaled quotas.

1. First, edit Template:Filename to enable the quota mount option(s) on selected file systems. Using the following line as an example:

 /dev/sda1 /home ext4 defaults 1 1
edit it as follows;
 /dev/sda1 /home ext4 defaults,usrquota 1 1
or aditionally enable the group quota mount option;
 /dev/sda1 /home ext4 defaults,usrquota,grpquota 1 1

2. Create the quota files in the file-system:

 # touch /home/aquota.user
 # touch /home/aquota.group     # For group quota

2. The next step is to remount:

 # mount -vo remount /home

4. Create the quota index to enable quotas:

 # quotacheck -vgum /home
or for all partitions with the quota mount options in Template:Filename;
 # quotacheck -vguma

5. Finally, enable quotas:

 # quotaon -av
Tip: to automatically enable quotas on boot, add the previous command to Template:Filename.

Journaled quotas

Enabling journaling for disk quotas adds the same benefits journaled file-systems do for forced shutdowns; the data is less likely to become corrupt.

Setting up journaled quotas is the same as above, except for slightly different mount options:

/dev/sda1 /home ext4 defaults,usrjquota=aquota.user,jqfmt=vfsv0 1 1

or aditionally enable the group quota mount option;

/dev/sda1 /home ext4 defaults,usrjquota=aquota.user,grpjquota=aquota.grp,jqfmt=vfsv0 1 1

Configurating

Replace Template:Codeline as appropiate, and edit the quota as root: Template:Command

blocks
1k blocks
inodes
Number of entries in directory file
soft
Max number of blocks/inodes user may have on partition before warning is issued and grace period countdown begins. If set to "0" (zero) then no limit is enforced.
hard
Max number of blocks/inodes user may have on partition. If set to "0" (zero) then no limit is enforced.
Note: to edit group quotas, use Template:Codeline.

Example setup

Editing the limits as below, for example:

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

sets the following restrictions: the Template:Codeline limit means that once testuser uses over 10MB of space, a warning gets ensued, and after a period of time, the soft limit gets enforced. The Template:Codeline limit is stricter, so to speak; a user cannot go over this limit.

To alter the grace period:

# edquota -t

Managing

Checking for quota limits and advanced operations

Basics

Use this command to check for quotas on a specific partition:

# repquota /home

Use this command to check for all quotas that apply to a user:

# quota -u $USER

for groups;

# quota -g $GROUP

Copying quotas

The idea is to make a temporary user acount, modify the quota settings for that user, and then copy the generated quota files for all users to use. After setting quota settings for quotauser, copy the settings:

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

This applies the settings to users with a UID equal to or greater than 1000.

Other commands

There are several useful commands, here are some of them:

repquota -a      # Shows the status on diskusage
warnquota        # Can be used to warn the users about their quota
setquota         # Non-interactive quota setting--useful for scripting

Lasty, Template:Codeline is used to give thorough information about the quota system: Template:Command

More resources