🌐 🇵🇱 Polski · 🇬🇧 EN
Quota, or disk limits, are a tool designed for better and more organized management of disk resources in operating systems. In the Linux environment, this feature has been available since the introduction of kernel version 2.2. Disk limits become useful in situations where a system is used by many users, each having their own home directory to store files, or if users have space for a website or store files on FTP accounts, etc. It is easy for a seemingly large disk to become filled, which can lead to many problems. Limits imposed on users prevent the system from being overwhelmed, thereby preventing the destabilization of the operating system. However, to ensure that limits are also user-friendly, the "quota" tool offers the ability to warn the user about reaching the available space limit by notifying them with an appropriate message.
To start, it is worth checking if the "quota" tool exists on our system:
quota-3.17-16.el6.i686
If not, it should be installed:
# yum install – y quota
To ensure that the system kernel we are working on supports the "quota" tool, we run the command:
# grep -i config_quota /boot/config-`uname -r` the result will be:
CONFIG_QUOTA=y
CONFIG_QUOTA_NETLINK_INTERFACE=y
# CONFIG_QUOTA_DEBUG is not set
CONFIG_QUOTA_TREE=y
CONFIG_QUOTACTL=y
Quota settings - quota
- quoaton - Enables quota limits
- quoataoff - Disables quota limits
- edquota - Edits quota settings for a specific user
- quota - Allows users to check their own disk resource usage
- repquota - Generates a disk resource usage report
- quotacheck - Initializes the quota database
Now, to start setting limits, a given file system must have a setting indicating the possibility of establishing limits, which is configured in the /etc/fstab file (remember to create a backup before editing). Limits can apply to users, groups, or both at once.
We check which file systems are mounted according to the entries in the /etc/fstab file (creating and mounting partitions was discussed in previous topics):
# cat /etc/fstab
Among others, there will be an entry like this, for example:
/dev/sdb1 /opt/data ext3 defaults 0 0
It means that the file system from the /dev/sdb1 partition is mounted to the /opt/data directory.
To enable the use of quota limits on this file system, we modify this entry:
/dev/sdb1 /opt/data ext3 defaults,usrquota,grpquota 1 2
Then we save the changes.
To put the changes into effect, we remount the file system.
# mount -o remount /opt/data/
Now we can check the changes made:
# mount | grep data
/dev/sdb1 on /opt/data type ext3 (rw,usrquota,grpquota)
After performing the above steps, you can proceed to configure limits for users.
We have two files at our disposal where limits for users and groups are configured.
- aquota.user - User quota file
- aquota.group - Group quota file
These files are created automatically in the root directory of the file system for which disk space limiting has been enabled. In the example presented here, the limits apply to the file system for the /opt/data location; to begin with, it is worth learning the quotacheck command.
Command syntax: quotacheck [options] <partition>
-c - Do not read existing quota files
-u - Check user quotas
-g - Check group quotas
-m - Do not remount read-only file systems
-v - Display more information
To create the quota files, we issue the command:
# quotacheck -ugm /opt/data/ or # quotacheck -cug /opt/data/
It may happen that creating the files is not possible and is blocked by SELinux. We can then set the correct context with the command:
# restorecon -Rv * or disable SELinux with the command: # setenforce 0
If everything is done correctly, the appropriate files should be in the /opt/data/ directory:
ls /opt/data/
aquota.group aquota.user lost+found
Enabling Quotas
Normally, to apply space limiting, we use the quotaon and quotaoff commands. The quota tool is also automatically started during system boot. We can also perform a manual start to ensure that limiting has been enabled:
# quotaon -v /opt/data/
/dev/sdb1 [/opt/data]: group quotas turned on
/dev/sdb1 [/opt/data]: user quotas turned on
There are two different limits that we can use in the "quota" tool: Soft Limit and Hard Limit.
Soft Limit - This can be described as a time-based limit, meaning that the user can exceed this limit any number of times, but must remember to reduce their files to the appropriate size within the set time (grace period). Thanks to this setting, the user has the ability to temporarily store a larger amount of data. However, if they do not organize their files within the specified time, they will be truncated to the size limit that the user has.
Hard limit - This is the value defining the maximum size of the disk resource made available to the user, which cannot be exceeded.
Understanding the existence and operation of the above limits, you can proceed to configure limits for users. To set limits, we use the edquota command. For practice, let's create a space limit for a selected user (in my case, it will be: "max") of 20MB, while giving the possibility to store 5MB more for a specified time, but no more than 25MB.
Command syntax: # edquota [ -u | -g ] [username | groupname]
Quota settings for user "max"
We issue the command:
# edquota -u max
and enter the appropriate modifications:
We issue the command:
# edquota -u max
and enter the appropriate modifications:
Disk quotas for user max (uid 505):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 20000 25000 0 0 0
We save and close the file. From this moment, the user "max" has disk space limits on the /dev/sdb1 file system, which is mounted at the /opt/data location.
Now we will also set the time during which it is possible to exceed the soft limit. We set the soft limit grace period with the command:
# edquota -t
By default, the time limit is 7 days, but for exercise purposes, we will change the time period to 2 days.
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/sdb1 2days 2days
Now we will also set the time during which it is possible to exceed the soft limit. We set the soft limit grace period with the command:
# edquota -t
By default, the time limit is 7 days, but for exercise purposes, we will change the time period to 2 days.
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/sdb1 2days 2days
We close the file, saving the changes.
Command syntax: # repquota [options] <partition>
Options:
-a - Report on all non-NFS file systems where quotas are enabled
-u - Report on user quotas
-g - Report on group quotas
-v - Detailed information
Let's check the quotas for /opt/data/ :
# repquota -uv /opt/data/
*** Report for user quotas on device /dev/sdb1
Block grace time: 2days; Inode grace time: 2days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 68708 0 0 4 0 0
max -- 0 20000 25000 0 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
We can review the detailed information where the limits for user "max", the soft limit grace period, and the hard limit are visible.
If user "max" wants to check their limits, they run the quota command:
$ quota
Disk quotas for user max (uid 505):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 8 20000 25000 1 0 0
Quota - reporting
To find out about the existing quota settings in the system, we can use the # repquota command.Command syntax: # repquota [options] <partition>
Options:
-a - Report on all non-NFS file systems where quotas are enabled
-u - Report on user quotas
-g - Report on group quotas
-v - Detailed information
Let's check the quotas for /opt/data/ :
# repquota -uv /opt/data/
*** Report for user quotas on device /dev/sdb1
Block grace time: 2days; Inode grace time: 2days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 68708 0 0 4 0 0
max -- 0 20000 25000 0 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
We can review the detailed information where the limits for user "max", the soft limit grace period, and the hard limit are visible.
If user "max" wants to check their limits, they run the quota command:
$ quota
Disk quotas for user max (uid 505):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 8 20000 25000 1 0 0
In case they exceed the file size, they will get the message:
Disk quota exceeded
Comments