Quotas are an optional feature of the operating system that allow you to limit the
amount of disk space and/or the number of files a user or members of a group may allocate
on a per-file system basis. This is used most often on timesharing systems where it is
desirable to limit the amount of resources any one user or group of users may allocate.
This will prevent one user or group of users from consuming all of the available disk
space.
Before attempting to use disk quotas, it is necessary to make sure that quotas are
configured in your kernel. This is done by adding the following line to your kernel
configuration file:
options QUOTA
The stock GENERIC kernel does not have this enabled by
default, so you will have to configure, build and install a custom kernel in order to use
disk quotas. Please refer to Chapter 8 for more
information on kernel configuration.
Next you will need to enable disk quotas in /etc/rc.conf.
This is done by adding the line:
enable_quotas="YES"
For finer control over your quota startup, there is an additional configuration
variable available. Normally on bootup, the quota integrity of each file system is
checked by the quotacheck(8) program.
The quotacheck(8) facility
insures that the data in the quota database properly reflects the data on the file
system. This is a very time consuming process that will significantly affect the time
your system takes to boot. If you would like to skip this step, a variable in /etc/rc.conf is made available for the purpose:
check_quotas="NO"
Finally you will need to edit /etc/fstab to enable disk
quotas on a per-file system basis. This is where you can either enable user or group
quotas or both for all of your file systems.
To enable per-user quotas on a file system, add the userquota
option to the options field in the /etc/fstab entry for the file system you want to enable quotas on.
For example:
/dev/da1s2g /home ufs rw,userquota 1 2
Similarly, to enable group quotas, use the groupquota
option instead of userquota
. To enable both user and group
quotas, change the entry as follows:
/dev/da1s2g /home ufs rw,userquota,groupquota 1 2
By default, the quota files are stored in the root directory of the file system with
the names quota.user and quota.group
for user and group quotas respectively. See fstab(5) for more
information. Even though the fstab(5) manual page
says that you can specify an alternate location for the quota files, this is not
recommended because the various quota utilities do not seem to handle this properly.
At this point you should reboot your system with your new kernel. /etc/rc will automatically run the appropriate commands to create
the initial quota files for all of the quotas you enabled in /etc/fstab, so there is no need to manually create any zero length
quota files.
In the normal course of operations you should not be required to run the quotacheck(8), quotaon(8), or quotaoff(8) commands
manually. However, you may want to read their manual pages just to be familiar with their
operation.
Once you have configured your system to enable quotas, verify that they really are
enabled. An easy way to do this is to run:
# quota -v
You should see a one line summary of disk usage and current quota limits for each file
system that quotas are enabled on.
You are now ready to start assigning quota limits with the edquota(8)
command.
You have several options on how to enforce limits on the amount of disk space a user
or group may allocate, and how many files they may create. You may limit allocations
based on disk space (block quotas) or number of files (inode quotas) or a combination of
both. Each of these limits are further broken down into two categories: hard and soft
limits.
A hard limit may not be exceeded. Once a user reaches his hard limit he may not make
any further allocations on the file system in question. For example, if the user has a
hard limit of 500 kbytes on a file system and is currently using 490 kbytes, the user can
only allocate an additional 10 kbytes. Attempting to allocate an additional 11 kbytes
will fail.
Soft limits, on the other hand, can be exceeded for a limited amount of time. This
period of time is known as the grace period, which is one week by default. If a user
stays over his or her soft limit longer than the grace period, the soft limit will turn
into a hard limit and no further allocations will be allowed. When the user drops back
below the soft limit, the grace period will be reset.
The following is an example of what you might see when you run the edquota(8) command.
When the edquota(8) command is
invoked, you are placed into the editor specified by the EDITOR
environment variable, or in the vi editor if the EDITOR variable is not set, to allow you to edit the quota limits.
# edquota -u test
Quotas for user test:
/usr: kbytes in use: 65, limits (soft = 50, hard = 75)
inodes in use: 7, limits (soft = 50, hard = 60)
/usr/var: kbytes in use: 0, limits (soft = 50, hard = 75)
inodes in use: 0, limits (soft = 50, hard = 60)
You will normally see two lines for each file system that has quotas enabled. One line
for the block limits, and one line for inode limits. Simply change the value you want
updated to modify the quota limit. For example, to raise this user's block limit from a
soft limit of 50 and a hard limit of 75 to a soft limit of 500 and a hard limit of 600,
change:
/usr: kbytes in use: 65, limits (soft = 50, hard = 75)
to:
/usr: kbytes in use: 65, limits (soft = 500, hard = 600)
The new quota limits will be in place when you exit the editor.
Sometimes it is desirable to set quota limits on a range of UIDs. This can be done by
use of the -p
option on the edquota(8) command.
First, assign the desired quota limit to a user, and then run edquota
-p protouser startuid-enduid. For example, if user test
has the desired quota limits, the following command can be used to duplicate those quota
limits for UIDs 10,000 through 19,999:
# edquota -p test 10000-19999
For more information see edquota(8) manual
page.
You can use either the quota(1) or the repquota(8) commands
to check quota limits and disk usage. The quota(1) command can
be used to check individual user or group quotas and disk usage. A user may only examine
his own quota, and the quota of a group he is a member of. Only the super-user may view
all user and group quotas. The repquota(8) command
can be used to get a summary of all quotas and disk usage for file systems with quotas
enabled.
The following is some sample output from the quota -v command
for a user that has quota limits on two file systems.
Disk quotas for user test (uid 1002):
Filesystem usage quota limit grace files quota limit grace
/usr 65* 50 75 5days 7 50 60
/usr/var 0 50 75 0 50 60
On the /usr file system in the above example, this user is
currently 15 kbytes over the soft limit of 50 kbytes and has 5 days of the grace period
left. Note the asterisk * which indicates that the user is
currently over his quota limit.
Normally file systems that the user is not using any disk space on will not show up in
the output from the quota(1) command, even
if he has a quota limit assigned for that file system. The -v
option will display those file systems, such as the /usr/var
file system in the above example.
Quotas are enforced by the quota subsystem on the NFS server. The rpc.rquotad(8) daemon
makes quota information available to the quota(1) command on
NFS clients, allowing users on those machines to see their quota statistics.
Enable rpc.rquotad in /etc/inetd.conf like so:
rquotad/1 dgram rpc/udp wait root /usr/libexec/rpc.rquotad rpc.rquotad
Now restart inetd:
# /etc/rc.d/inetd restart