Difference between revisions of "Disk quota"

From ArchWiki
Jump to: navigation, search
m (The user quotes: (Corrected typo))
m (Enabling: link to relevant article)
(37 intermediate revisions by 15 users not shown)
Line 1: Line 1:
[[Category: Security (English)]]
+
[[Category:Security]]
[[Category:HOWTOs (English)]]
+
[[Category:File systems]]
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 quotas to disks is to allocate limited disk-space 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 quota.
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 quota only requires 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 quota, see the notes in [[#Journaled quota]].''
<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 {{ic|/etc/fstab}} to enable the quota mount option(s) on selected file systems:
<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
</pre>
+
 
at last the quotastats is used to give info about the quota system:
+
4. Create the quota index:
<pre>
+
  # quotacheck -vgum /home
$ quotastats
+
:or for all partitions with the quota mount options in {{ic|/etc/mtab}};
 +
  # quotacheck -vguma
 +
{{tip|If you end up with the output "[...]Quotafile $FILE was probably truncated. Cannot save quota settings..." you can try removing the previously created files aquota*}}
 +
{{tip|If you get the output "quotacheck: Mountpoint (or device) /home not found or has no quota enabled.<br>
 +
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option." and you are using a custom kernel, make sure quota support is enabled in your kernel.}}
 +
{{tip|In Addition you can try to use "-F vfsold" and "-F vfsv0" afterwards <b>NOTE:</b> As of 3.1.6-1, Arch does not support "vfsv1"}}
 +
 
 +
5. Finally, enable quotas:
 +
  # quotaon -av
 +
Consider adding this command to your start-up, see [[Autostarting]].
 +
 
 +
===Journaled quota===
 +
Enabling journaling for disk quota adds the same benefits journaled file systems do for forced shutdowns, meaning that data is less likely to become corrupt.
 +
 
 +
Setting up journaled quota is the same as above, except for the 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.group,jqfmt=vfsv0''' 1 1
 +
 
 +
==Configuring==
 +
{{Note|To find out how  many '''1k''' blocks are there for a partition use '''# df'''}}
 +
Replace {{ic|$USER}} as appropriate and edit the quota as root:
 +
{{hc|$ edquota ''$USER''|
 +
Disk quotas for user '''$USER''' (uid 1000):
 +
  Filesystem                  blocks      soft      hard    inodes    soft    hard
 +
  /dev/sda1                      1944          0          0        120        0        0
 +
}}
 +
{{note|to edit group quotas, use {{ic|edquota -g $GROUP}}.}}
 +
;blocks: Number of 1k blocks currently used by {{ic|$USER}}
 +
;inodes: Number of entries by {{ic|$USER}} in directory file
 +
;soft: Max number of blocks/inodes {{ic|$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 {{ic|$USER}} may have on partition. If set to "0" (zero) then no limit is enforced.
 +
 
 +
Example configuration:
 +
Disk quotas for user testuser (uid 1000):
 +
Filesystem      blocks      soft      hard    inodes    soft  hard     
 +
/dev/sda1      695879      10000      15000    6741        0      0
 +
 
 +
The {{ic|soft}} limit means that once ''testuser'' uses over 10MB of space a warning email gets ensued, and after a period of time the soft limit gets enforced.
 +
 
 +
The {{ic|hard}} limit is stricter, so to speak; a user cannot go over this limit.
 +
 
 +
Next configure the {{ic|soft}} limit 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 quota settings===
 +
To copy quota from one user or group to the other, use this command:
 +
# edquota -p user1 user2
 +
User1 is the user you copy from, user2 is the user you copy quota to. Of course you can replace user with group, when necessary.
 +
 
 +
====Multiple users====
 +
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:
 +
repquota -a      # Shows the status on disk usage
 +
warnquota        # Can be used to warn the users about their quota, configuration in /etc/warnquota.conf
 +
setquota        # Non-interactive quota setting--useful for scripting
 +
 
 +
Lasty, {{ic|quotastats}} is used to give thorough information about the quota system:
 +
{{hc|$ quotastats|
 
Number of dquot lookups: 101289
 
Number of dquot lookups: 101289
 
Number of dquot drops: 101271
 
Number of dquot drops: 101271
Line 83: Line 113:
 
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://www.linuxdoc.org/HOWTO/mini/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 04:07, 24 November 2013

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 quotas to disks is to allocate limited disk-space in a reasonable way."

This article covers the installation and setup of disk quota.

Installing

Disk quota only requires one package:

# pacman -S quota-tools

Enabling

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

1. First, edit /etc/fstab to enable the quota mount option(s) on selected file systems:

 /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:

 # quotacheck -vgum /home
or for all partitions with the quota mount options in /etc/mtab;
 # quotacheck -vguma
Tip: If you end up with the output "[...]Quotafile $FILE was probably truncated. Cannot save quota settings..." you can try removing the previously created files aquota*
Tip: If you get the output "quotacheck: Mountpoint (or device) /home not found or has no quota enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option." and you are using a custom kernel, make sure quota support is enabled in your kernel.
Tip: In Addition you can try to use "-F vfsold" and "-F vfsv0" afterwards NOTE: As of 3.1.6-1, Arch does not support "vfsv1"

5. Finally, enable quotas:

 # quotaon -av

Consider adding this command to your start-up, see Autostarting.

Journaled quota

Enabling journaling for disk quota adds the same benefits journaled file systems do for forced shutdowns, meaning that data is less likely to become corrupt.

Setting up journaled quota is the same as above, except for the 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.group,jqfmt=vfsv0 1 1

Configuring

Note: To find out how many 1k blocks are there for a partition use # df

Replace $USER as appropriate and edit the quota as root:

$ edquota $USER
Disk quotas for user $USER (uid 1000):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda1                      1944          0          0        120        0        0
Note: to edit group quotas, use edquota -g $GROUP.
blocks
Number of 1k blocks currently used by $USER
inodes
Number of entries by $USER 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.

Example configuration:

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

The soft limit means that once testuser uses over 10MB of space a warning email gets ensued, and after a period of time the soft limit gets enforced.

The hard limit is stricter, so to speak; a user cannot go over this limit.

Next configure the soft limit 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 quota settings

To copy quota from one user or group to the other, use this command:

# edquota -p user1 user2

User1 is the user you copy from, user2 is the user you copy quota to. Of course you can replace user with group, when necessary.

Multiple users

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:

repquota -a      # Shows the status on disk usage
warnquota        # Can be used to warn the users about their quota, configuration in /etc/warnquota.conf
setquota         # Non-interactive quota setting--useful for scripting

Lasty, quotastats is used to give thorough information 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 resources