27.5 UFS Disk Quotas
Disk quotas can be used to limit the amount of disk space or number of files that a user or group can allocate on each UFS file system, thereby preventing any single user or group from consuming all available disk space.
Verifying Kernel Support
The default FreeBSD kernel provides support for disk quotas. You can verify this by running the following command:
$ sysctl kern.features.ufs_quota
kern.features.ufs_quota: 1If the output is 0, it indicates that you may be using a custom kernel that does not support the disk quota module. You should add the kernel option options QUOTA to your kernel configuration file and then recompile the kernel.
Enabling Disk Quotas
Set disk quotas to enable at boot:
# service quota enableEnable disk quotas immediately:
# service quota startAt startup, the system checks the quota integrity of each file system through quotacheck(8). This program ensures that the data in the quota database correctly reflects the data in the file system. This process takes a considerable amount of time and can significantly affect system startup time. To skip this step, add the following variable to /etc/rc.conf:
check_quotas="NO"You must add quota options to /etc/fstab to enable per-user or per-group disk quotas. To enable per-user quotas, add userquota to the options field of the file system's /etc/fstab configuration line. For example:
/dev/nda0p2 / ufs rw,userquota 1 1To enable group quotas, use groupquota instead. To enable both user and group quotas, separate the options with a comma:
After configuration, restart the system. /etc/rc will automatically run the appropriate commands to create initial quota files for all quotas enabled in /etc/fstab.
By default, quota files are stored in the root directory of the file system, named quota.user and quota.group.
Setting Quota Limits
To verify that quotas are enabled, run the following command:
At this point, the system is ready to set quota limits using edquota.
Quota limits can be based on disk space (block quotas), file count (inode quotas), or a combination of both. Each type of limit is further divided into two categories: hard limits and soft limits.
A hard limit cannot be exceeded. When a user reaches a hard limit, they can no longer allocate any space on that file system. For example, if a user has a hard limit of 500 KB on a file system and is currently using 490 KB, the user can only allocate an additional 10 KB. Attempting to allocate an additional 11 KB will fail.
A soft limit can be exceeded for a certain period of time, known as the grace period, which defaults to one week. If a user exceeds the soft limit and the grace period has expired, the soft limit becomes a hard limit and no further space allocation is allowed. When the user drops below the soft limit, the grace period resets.
In the following example, edit the quota for the ykla account. When edquota is invoked, it opens the editor specified by the EDITOR environment variable to edit the quota limits. The default editor is vi(1).
You can change the block quota and inode quota to configure quota limits. For example, to increase the block limit for / to a soft limit of 100 and a hard limit of 120, change the values on that line to:
After exiting the editor, the new quota limits take effect. Users can only check their own quotas and the quotas of groups they belong to. Only the superuser can view quotas for all users and groups.
Typically, if a user has not used any disk space on a file system, that file system will not appear in the output of quota(1), even if quotas are set for it.
In some scenarios, you may need to set the same quota limits for a batch of users. You can first assign the desired quota limits to one user, then use the -p option to copy those quotas to users within a specified UID range. The following command copies the quota limits to users with UIDs from 10000 to 19999:
Last updated