Chapter 23. Limiting storage space usage on ext4 with quotas
You have to enable disk quotas on your system before you can assign them. You can assign disk quotas per user, per group or per project. However, if there is a soft limit set, you can exceed these quotas for a configurable period of time, known as the grace period.
23.1. Installing the quota tool Copiar o linkLink copiado para a área de transferência!
You must install the quota RPM package to implement disk quotas.
Procedure
Install the
quotapackage:yum install quota
# yum install quotaCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.2. Enabling quota feature on file system creation Copiar o linkLink copiado para a área de transferência!
Enable quotas on file system creation.
Procedure
Enable quotas on file system creation:
mkfs.ext4 -O quota /dev/sda
# mkfs.ext4 -O quota /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteOnly user and group quotas are enabled and initialized by default.
Change the defaults on file system creation:
mkfs.ext4 -O quota -E quotatype=usrquota:grpquota:prjquota /dev/sda
# mkfs.ext4 -O quota -E quotatype=usrquota:grpquota:prjquota /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the file system:
mount /dev/sda
# mount /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.3. Enabling quota feature on existing file systems Copiar o linkLink copiado para a área de transferência!
Enable the quota feature on existing file system by using the tune2fs command.
Procedure
Unmount the file system:
umount /dev/sda
# umount /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable quotas on existing file system:
tune2fs -O quota /dev/sda
# tune2fs -O quota /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteOnly user and group quotas are initialized by default.
Change the defaults:
tune2fs -Q usrquota,grpquota,prjquota /dev/sda
# tune2fs -Q usrquota,grpquota,prjquota /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Mount the file system:
mount /dev/sda
# mount /dev/sdaCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.4. Enabling quota enforcement Copiar o linkLink copiado para a área de transferência!
The quota accounting is enabled by default after mounting the file system without any additional options, but quota enforcement is not.
Prerequisites
- Quota feature is enabled and the default quotas are initialized.
Procedure
Enable quota enforcement by
quotaonfor the user quota:mount /dev/sda /mnt
# mount /dev/sda /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow quotaon /mnt
# quotaon /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThe quota enforcement can be enabled at mount time using
usrquota,grpquota, orprjquotamount options.mount -o usrquota,grpquota,prjquota /dev/sda /mnt
# mount -o usrquota,grpquota,prjquota /dev/sda /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable user, group, and project quotas for all file systems:
quotaon -vaugP
# quotaon -vaugPCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
If neither of the
-u,-g, or-Poptions are specified, only the user quotas are enabled. -
If only
-goption is specified, only group quotas are enabled. -
If only
-Poption is specified, only project quotas are enabled.
-
If neither of the
Enable quotas for a specific file system, such as
/home:quotaon -vugP /home
# quotaon -vugP /homeCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.5. Assigning quotas per user Copiar o linkLink copiado para a área de transferência!
The disk quotas are assigned to users with the edquota command.
The text editor defined by the EDITOR environment variable is used by edquota. To change the editor, set the EDITOR environment variable in your ~/.bash_profile file to the full path of the editor of your choice.
Prerequisites
- User must exist prior to setting the user quota.
Procedure
Assign the quota for a user:
edquota username
# edquota usernameCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace username with the user to which you want to assign the quotas.
For example, if you enable a quota for the
/dev/sdapartition and execute the commandedquota testuser, the following is displayed in the default editor configured on the system:Disk quotas for user testuser (uid 501): Filesystem blocks soft hard inodes soft hard /dev/sda 44043 0 0 37418 0 0
Disk quotas for user testuser (uid 501): Filesystem blocks soft hard inodes soft hard /dev/sda 44043 0 0 37418 0 0Copy to Clipboard Copied! Toggle word wrap Toggle overflow Change the desired limits.
If any of the values are set to 0, limit is not set. Change them in the text editor.
For example, the following shows the soft and hard block limits for the testuser have been set to 50000 and 55000 respectively.
Disk quotas for user testuser (uid 501): Filesystem blocks soft hard inodes soft hard /dev/sda 44043 50000 55000 37418 0 0
Disk quotas for user testuser (uid 501): Filesystem blocks soft hard inodes soft hard /dev/sda 44043 50000 55000 37418 0 0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The first column is the name of the file system that has a quota enabled for it.
- The second column shows how many blocks the user is currently using.
- The next two columns are used to set soft and hard block limits for the user on the file system.
-
The
inodescolumn shows how many inodes the user is currently using. The last two columns are used to set the soft and hard inode limits for the user on the file system.
- The hard block limit is the absolute maximum amount of disk space that a user or group can use. Once this limit is reached, no further disk space can be used.
- The soft block limit defines the maximum amount of disk space that can be used. However, unlike the hard limit, the soft limit can be exceeded for a certain amount of time. That time is known as the grace period. The grace period can be expressed in seconds, minutes, hours, days, weeks, or months.
Verification
Verify that the quota for the user has been set:
quota -v testuser
# quota -v testuser Disk quotas for user testuser: Filesystem blocks quota limit grace files quota limit grace /dev/sda 1000* 1000 1000 0 0 0Copy to Clipboard Copied! Toggle word wrap Toggle overflow
23.6. Assigning quotas per group Copiar o linkLink copiado para a área de transferência!
You can assign quotas on a per-group basis.
Prerequisites
- Group must exist prior to setting the group quota.
Procedure
Set a group quota:
edquota -g groupname
# edquota -g groupnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, to set a group quota for the
develgroup:edquota -g devel
# edquota -g develCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command displays the existing quota for the group in the text editor:
Disk quotas for group devel (gid 505): Filesystem blocks soft hard inodes soft hard /dev/sda 440400 0 0 37418 0 0
Disk quotas for group devel (gid 505): Filesystem blocks soft hard inodes soft hard /dev/sda 440400 0 0 37418 0 0Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Modify the limits and save the file.
Verification
Verify that the group quota is set:
quota -vg groupname
# quota -vg groupnameCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.7. Assigning quotas per project Copiar o linkLink copiado para a área de transferência!
You can assign quotas per project.
Prerequisites
- Project quota is enabled on your file system.
Procedure
Add the project-controlled directories to
/etc/projects. For example, the following adds the/var/logpath with a unique ID of 11 to/etc/projects. Your project ID can be any numerical value mapped to your project.echo 11:/var/log >> /etc/projects
# echo 11:/var/log >> /etc/projectsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add project names to
/etc/projidto map project IDs to project names. For example, the following associates a project calledLogswith the project ID of 11 as defined in the previous step.echo Logs:11 >> /etc/projid
# echo Logs:11 >> /etc/projidCopy to Clipboard Copied! Toggle word wrap Toggle overflow Set the desired limits:
edquota -P 11
# edquota -P 11Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can choose the project either by its project ID (
11in this case), or by its name (Logsin this case).Using
quotaon, enable quota enforcement:
Verification
Verify that the project quota is set:
quota -vP 11
# quota -vP 11Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteYou can verify either by the project ID, or by the project name.
23.8. Setting the grace period for soft limits Copiar o linkLink copiado para a área de transferência!
If a given quota has soft limits, you can edit the grace period, which is the amount of time for which a soft limit can be exceeded. You can set the grace period for users, groups, or projects.
Procedure
Edit the grace period:
edquota -t
# edquota -tCopy to Clipboard Copied! Toggle word wrap Toggle overflow
While other edquota commands operate on quotas for a particular user, group, or project, the -t option operates on every file system with quotas enabled.
23.9. Turning file system quotas off Copiar o linkLink copiado para a área de transferência!
Use quotaoff to turn disk quota enforcement off on the specified file systems. Quota accounting stays enabled after executing this command.
Procedure
To turn all user and group quotas off:
quotaoff -vaugP
# quotaoff -vaugPCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
If neither of the
-u,-g, or-Poptions are specified, only the user quotas are disabled. -
If only
-goption is specified, only group quotas are disabled. -
If only
-Poption is specified, only project quotas are disabled. -
The
-vswitch causes verbose status information to display as the command executes.
-
If neither of the
23.10. Reporting on disk quotas Copiar o linkLink copiado para a área de transferência!
Create a disk quota report by using the repquota utility.
Procedure
Run the
repquotacommand:repquota
# repquotaCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example, the command
repquota /dev/sdaproduces this output:Copy to Clipboard Copied! Toggle word wrap Toggle overflow View the disk usage report for all quota-enabled file systems:
repquota -augP
# repquota -augPCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The -- symbol displayed after each user determines whether the block or inode limits have been exceeded. If either soft limit is exceeded, a + character appears in place of the corresponding - character. The first - character represents the block limit, and the second represents the inode limit.
The grace columns are normally blank. If a soft limit has been exceeded, the column contains a time specification equal to the amount of time remaining on the grace period. If the grace period has expired, none appears in its place.