5 Steps to Setup User and Group Disk Quota on UNIX / Linux

by Ramesh Natarajan on July 21, 2010

On Linux, you can setup disk quota using one of the following methods:

  • File system base disk quota allocation
  • User or group based disk quota allocation


On the user or group based quota, following are three important factors to consider:

  • Hard limit – For example, if you specify 2GB as hard limit, user will not be able to create new files after 2GB
  • Soft limit – For example, if you specify 1GB as soft limit, user will get a warning message “disk quota exceeded”, once they reach 1GB limit. But, they’ll still be able to create new files until they reach the hard limit
  • Grace Period – For example, if you specify 10 days as a grace period, after user reach their hard limit, they would be allowed additional 10 days to create new files. In that time period, they should try to get back to the quota limit.

1. Enable quota check on filesystem

First, you should specify which filesystem are allowed for quota check.

Modify the /etc/fstab, and add the keyword usrquota and grpquota to the corresponding filesystem that you would like to monitor.

The following example indicates that both user and group quota check is enabled on /home filesystem

# cat /etc/fstab
LABEL=/home    /home   ext2   defaults,usrquota,grpquota  1 2

Reboot the server after the above change.

2. Initial quota check on Linux filesystem using quotacheck

Once you’ve enabled disk quota check on the filesystem, collect all quota information initially as shown below.

# quotacheck -avug
quotacheck: Scanning /dev/sda3 [/home] done
quotacheck: Checked 5182 directories and 31566 files
quotacheck: Old file not found.
quotacheck: Old file not found.

In the above command:

  • a: Check all quota-enabled filesystem
  • v: Verbose mode
  • u: Check for user disk quota
  • g: Check for group disk quota

The above command will create a aquota file for user and group under the filesystem directory as shown below.

# ls -l /home/

-rw-------    1 root     root        11264 Jun 21 14:49 aquota.user
-rw-------    1 root     root        11264 Jun 21 14:49 aquota.group

3. Assign disk quota to a user using edquota command

Use the edquota command as shown below, to edit the quota information for a specific user.

For example, to change the disk quota for user ‘ramesh’, use edquota command, which will open the soft, hard limit values in an editor as shown below.

# edquota ramesh

Disk quotas for user ramesh (uid 500):
  Filesystem           blocks       soft       hard     inodes     soft     hard
  /dev/sda3           1419352          0          0       1686        0        0

Once the edquota command opens the quota settings for the specific user in a editor, you can set the following limits:

  • soft and hard limit for disk quota size for the particular user.
  • soft and hard limit for the total number of inodes that are allowed for the particular user.

4. Report the disk quota usage for users and group using repquota

Use the repquota command as shown below to report the disk quota usage for the users and groups.

# repquota /home
*** Report for user quotas on device /dev/sda3
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --  566488       0       0           5401     0     0
nobody    --    1448       0       0             30     0     0
ramesh    -- 1419352       0       0           1686     0     0
john      --   26604       0       0            172     0     0

5. Add quotacheck to daily cron job

Add the quotacheck to the daily cron job. Create a quotacheck file as shown below under the /etc/cron.daily directory, that will run the quotacheck command everyday. This will send the output of the quotacheck command to root email address.

# cat /etc/cron.daily/quotacheck
quotacheck -avug

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 10 comments… read them below or add one }

1 susant August 27, 2010 at 1:52 pm

yeah thanks for this great information can i know what is the difference between vi editor and cat ?????

2 Anto January 31, 2011 at 4:02 am

How to setup quota for users who already used some space in the machine ?

3 Rinku July 20, 2011 at 12:37 am

Hello Sir one question please help to understand this question
Q1.How can i connect with remote pc with in private network i mean my private network is A and his private network B with public ip ?
Q2.How can i connect from private network A to private network B with his central sever that has public ?

Please Help sir ,I know sir you can help because your every article on this website is awesome

4 raz October 26, 2011 at 3:17 pm

Great article. Thanks for writing it.
You can also pipe your output to an email – it’s low end – for sure but it keeps you in the loop without having to login to the server.

btw- those other comments on this article… OMG. really? :)

5 D M R April 30, 2012 at 5:49 am

thanks for u r quotas configuration information

6 Dammu Mohana Rao April 30, 2012 at 5:52 am

How to setup quota for users who already used some space in the machine ?
and in which situation the quotas implementation is useful.

7 Nishaj June 7, 2012 at 4:52 am

Hi,

Do we need to add a quotacheck -avug on cron jobs?
I guess it should be repquota?

8 Senthil October 15, 2013 at 1:51 am

In step1, we don’t have to reboot the server after making fstab change. just remount is enough.

9 James February 4, 2014 at 10:46 pm

@Senthil, using Debian wheezy, I need to reboot in order for the kernel to be aware of the file system changes. Mount -a doesn’t cut it for me.

10 Biswa March 18, 2014 at 10:11 pm

Good article.

Leave a Comment

Previous post:

Next post: