Linux quota

Most linux distributions are shipped with the quota packet installed which offers you a range of tools that can be used to manage disk quota. The majority of file systems in use today support this feature which must be enabled with the Quota Support kernel module. Most distributions have this feature enabled by default so you usually don’t have to recompile your kernel. You can check if you have the quota package installed by running the following command:

rpm -qa | grep quota

Linux quota

Linux quota

Note that you need to mount a file system with one of the following options to enable disk quota:

grpquota – when group quota is used

usrquota – when user quota is used

For example:

/dev/sda5    /opt/kits    ext4    usrquota,grpquota    1    1

A number of quota command can be used to perform quota-related tasks:

[root@localhost /home/dpopescu/test]# quota
quota quotacheck quota_nld quotaoff quotaon quotastats quotasync

quotaon and quotaoff can be used to enable/disable this feature. Note that these commands will first verify if the file system was mounted with the quota feature enabled or no so make sure you enable it in fstab before using it.

For this example I’ve created a new logical volume which has been mounted to /home:

/dev/mapper/data-home–data /home ext4 defaults,usrquota,grpquota 0 0

Disk quota

Disk quota

Once the mount point is created use the quotacheck -cug /home/ command to enable disk quota on the file system. Note that if you need, you can use the -m flag to force the command.

The three parameter in the quotacheck command will create (-c) the aquota.user (-u) and (-g) files which are used by the quota feature.

quotastats command can be used to display quota statistics for a particular location. Command will query the kernel and will receive quota information:

[root@kafka danp]# quotastats /home/
Kernel quota version: 6.5.1
Number of dquot lookups: 0
Number of dquot drops: 0
Number of dquot reads: 0
Number of dquot writes: 0
Number of quotafile syncs: 4
Number of dquot cache hits: 0
Number of allocated dquots: 0
Number of free dquots: 0
Number of in use dquot entries (user/group): 0
[root@kafka danp]#

To configure quota limits for a user account, use the edquota command just like in the following example:

edquota danp 

Disk quotas for user in Linux

Disk quotas for user in Linux

This command will display a temporary quota configuration file which contains the following:

The filesystem on which the quota is configured

The number of disk blocks in use

Disk blocks soft limit – allows the user to continue creating files either until the hard limit is reached or when the grace period is met.

Disk blocks hard limit – does not allow the user to create further files

The number of inodes in use

Inodes soft limit – similar to disk blocks soft limit, allows the user to create new files (1 inode for each file) until the hard limit is reached or the grace period is met.

Inodes hard limit – does not allow the user to create new files because the maximum number of allowed inodes has been reached.

Group quotas can be set using the same command but with the -g parameter, as follows:

edquota -g danp 

Linux group quota

Linux group quota

Entries seen in the above image have the same role and those described previously in the user quota section.

The grace period can be configured by using the edquota -t command, just like in the following example:

edquota -t

Linux quota grace period

Linux quota grace period

Whatever value suits your company best can be written and saved in the Block/Inodes grace period field.

A summary of the quota information can be viewed by using the repquota filesystem command:

repquota /home

Linux quota information

Linux quota information

The -a parameter can be used with this command to display the quota information for all file systems

That’s about it for this quota article, hope you’ve enjoyed it. Don’t hesitate to post any comments/questions in my dedicated section. Although I haven’t used this feature a lot in production environments, it’s usefully to know that it can be used with Linux systems.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s