How to enable User and Group Disk Quota on CentOS 7 / RHEL 7

As a Linux system admin we generally face low disk space issues. By implementing the user and group disk quota on the file system we can resolve the space issue.

Quota restricts the users to use only allowed disk and inodes on the particular file system. In this post we will discuss how to enable user & group disk quota on /home File system on CentOS 7 & RHEL 7

Step:1 Add usrquota & grpquota option on /home in /etc/fstab file.
[[email protected] ~]# vi /etc/fstab

home-quota

Save & exit the file.

In this example i have add user and group quota options on /home

Step:2 Remount  /home file system via  mount command
[[email protected] ~]# mount -o remount /home

Now recheck the /home file system whether Quota is enable or not.

[[email protected] ~]# mount | grep /home
/dev/mapper/centos-home on /home type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)
Step:3 Create Quota Database Files using quotacheck
[[email protected] home]# quotacheck -cugv /home

Whereas :

-c : create quota file and don’t use the existing file
-v : verbose ouput
-u : user disk quota
-g : group disk quota

Above Command will create aquota.user & aquota.group files under /home

Turn on quota on /home using below command :

[[email protected] ~]# quotaon /home/
Step:4 Assign user & group disk quota via edquota commands

Syntax # edquota -u <User_Name>

# edquota -g <Group_Name>

[[email protected] ~]# edquota -u jack

edquota

[[email protected] ~]# edquota -g sys_admin

group-quota

As shown above we have two kind of Disk quota limits :

soft : It will warn the users if the soft limit of disk quota reached ( size is in KB), in above example for jack user soft limit is 5500 KB ( approx 5.5MB )

hard : It will not allow the users to create new files once the hard limit is reached. ( Size in KB ), in above example hard limit for jack user is 6000 KB ( approx 6 MB )

Note : We can also set the Quota on the basis of the inodes ( i.e numbers of files that the user can create on particular file system)

Let’s take an example , login as jack user and try to create a file of 8MB.

[[email protected] ~]# su - jack

[[email protected] ~]$ dd if=/dev/zero of=bgfile bs=1M count=8
dm-2: warning, user block quota exceeded.
dm-2: write failed, user block limit reached.
dd: error writing ‘bgfile’: Disk quota exceeded
6+0 records in
5+0 records out
6144000 bytes (6.1 MB) copied, 0.00711317 s, 864 MB/s

As we see above soft & hard limit is exceeded for jack user. Now onwards user jack can’t create new files.

Step:5 Display Quota report for Users in human readable
[[email protected] ~]# repquota -as
repquota
Step:6 Configure Grace Period for Soft Limit

Grace period is the amount of time during which soft limit can can be exceeded, once the grace period reached then soft limit will become the hard limit.

Use the edquota command to set Grace period .

[[email protected] ~]# edquota -t

Soft-limit-grace-period

Please don’t hesitate to share your feedback and comments on this post 🙂

10 Responses

  1. Mk says:

    Tnq..Good article…

  2. Dany says:

    Remarkable article.
    What happened when grace period for soft quota is reached?

  3. vikas says:

    informative indeed.. easy to understand

  4. Paul Whitney says:

    What about troubleshooting? I added entries to fstab, remounted, and when I do the grep still shows “noquota”

  5. Santosh says:

    Excellent info. let me know, how can we assign inodes and inodes calculation

  6. Bruce says:

    What would happen if you added quota to /home when its still part of /? Would the quota only affect that specific directory or the whole root file system?

  7. Buddhika Karunanayaka says:

    Dear Pradeep,

    I got following output when edit fstab and after remount

    cat /etc/fstab
    /dev/mapper/centos_ns2-home /home xfs defaults,usrquota,grpquota 1 2

    [[email protected] ~]# mount -o remount /home
    [[email protected] ~]# mount | grep /home
    /dev/mapper/centos_ns2-home on /home type xfs (rw,relatime,attr2,inode64,noquota)

    [[email protected] ~]# quotacheck -cugv /home
    quotacheck: Mountpoint (or device) /home not found or has no quota enabled.
    quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.

    What is the reason pls expalin in order to activate quota

    • Pradeep Kumar says:

      Hi Buddhika,

      Steps mentioned in tutorial is for ext4/ext3 file system but you are trying these steps on xfs file system that’s why you are getting errors.

      We will shortly write an article on XFS quota.

Leave a Reply to Pradeep Cancel reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest