How to Configure/Setup Disk Quotas in Linux

Disk space usage can be controlled by implementing disk quota on Linux.

This will allow a user to use only the allocated disk space.

Also, it keeps your partition under threshold limit.

You can set the following parameters such as soft limit, hard limit, grace period, block size and Inode number when enabling disk quota on a particular file system.

You can make the necessary changes to a specific user using the following disk quota management commands such as quotacheck, edquota, quota, repquota, quotaoff and quotaon.

Make a note: You may need to enable disk quota on a system where multiple users share the disk space such as file server or ftp server or shared hosting.

You do not need to enable this if you do not share the server with others.

Benefits of Disk Quotas

  • Users are only allowed to use the allocated disk space.
  • Hard Limit: Once the hard limit is reached, the user cannot create new files.
  • Soft Limit: When the soft limit is reached, the user can create a new file, but the user receives a warning message saying “disk quota exceeded”, but they can create a new file until it reaches the hard limit.
  • Inode Limit: Once a given inode limit is reached, the user cannot create new files.
  • Grace Period: Users are allowed to create new files during the grace period, even if they have reached a hard limit.

1) How to Install Disk Quota in Linux

The disk quota package is available in the distribution official repository, so use the package manager to install it.

For Fedora system, use DNF Command to install quota.

$ sudo dnf install quota

For Debian/Ubuntu systems, use APT-GET Command or APT Command to install quota.

$ sudo apt install quota

For Arch Linux based systems, use Pacman Command to install quota.

$ sudo pacman -S quota

For RHEL/CentOS systems, use YUM Command to install quota.

$ sudo yum install quota

For openSUSE Leap system, use Zypper Command to install quota.

$ sudo zypper install quota

2) How to Enable Disk Quota in Linux

This can be achieved by making the necessary changes to the /etc/fstab file.

To do so, edit the “/etc/fstab” file and add the “usrquota” and “grpquota” quota parameters to the specific file system to enable disk quota.

If your kernel and file system support the “journaled” quota then use accordingly.

# vi /etc/fstab

/dev/VolGroup00/LogVol00 /         ext3    defaults        1 1 
LABEL=/boot              /boot     ext3    defaults        1 2 
none                     /dev/pts  devpts  gid=5,mode=620  0 0 
none                     /dev/shm  tmpfs   defaults        0 0 
none                     /proc     proc    defaults        0 0 
none                     /sys      sysfs   defaults        0 0 
/dev/VolGroup00/LogVol02 /home     ext3    defaults,usrquota,grpquota  1 2 
/dev/VolGroup00/LogVol01 swap      swap    defaults        0 0

Once you have made the above change, restart the system or remount the associated mount point.

# shutdown -r now

If you can not reboot it due to dependency then remount it.

# mount -o remount /home

3) How to Create Quota Files on Linux Using the quotacheck Command

TThis command creates the required database files when you run them for first time.

If it is not found in the given partition, it will create “aquota.user” and “aquota.group” files.

Make a note: It’s advised to run the above command only once for each partition to create disk quota database file.

The quotacheck command is used to scan a file system for disk usage, create, check and repair quota files.

# quotacheck -cug /home

4) How to Synchronize Disk Quota on Linux Using the quotacheck Command

The default disk quota shows zero because you do not sync the disk quota database file with the current disk usage.

To do so, run the following command to collect the disk quota information.

# quotacheck -augv

quotacheck: Scanning /dev/VolGroup00/LogVol02 [/home] 
|/-|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\
.
.
|/-|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\|/-\
quotacheck: Checked 60202 directories and 495168 files

5) How to Report Disk Quota Usage for Users and Groups on Linux Using the repquota Command

Use the repquota command to check the disk quota usage for the users and groups.

# repquota /home

*** Report for user quotas on device /dev/VolGroup00/LogVol02
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --  452428       0       0            205     0     0
jpserver  --     720       0       0             76     0     0
jpssindi  --    9576       0       0            620     0     0
abodeofj  --   22488       0       0           1598     0     0
accesser  --    5452       0       0            373     0     0
adhavaca  --    2528       0       0            206     0     0
adhavacs  --    1732       0       0            201     0     0
.
.
shivanig  --  476472       0       0           3800     0     0
syosisgl  --  834604       0       0           2675     0     0

6) How to Modify Quota Information for a Specific User on Linux Using the edquota Command

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

# edquota mageshm

Disk quotas for user mageshm (uid 501):   
Filesystem                blocks     soft     hard    inodes   soft   hard   
/dev/VolGroup00/LogVol02  440436        0        0     37418      0      0

Once you modified the values, run the quota command as follows to verify them.

# quota mageshm

Disk quotas for user mageshm (uid 501):   
Filesystem                blocks     soft     hard   inodes   soft   hard   
/dev/VolGroup00/LogVol02  440436   500000   550000    37418      0      0

7) How to Modify Quota Information for a Specific Group on Linux Using the edquota Command

The Edvota command is used to modify allocation information for a specific user. Use the “-g” option with the edquota command to change the quota for a group.

# edquota -g linuxadmin

Disk quotas for user linuxadmin (uid 1001):   
Filesystem                blocks     soft     hard    inodes   soft   hard   
/dev/VolGroup00/LogVol02  840436        0        0     57418      0      0

Once you modified the values, run the quota command as follows to verify them.

# quota -g linuxadmin

8) How to Edit the Quota Grace Period in Linux Using the edquota Command

By default the grace period is set to seven days (users are allowed to use additional disk space for seven days) after which you will be denied. You can change this according to your needs.

Don’t include space between value and unit, it should be “5 days”.

For a specific user.

# edquota -T mageshm

For a specific group.

# edquota -T -g linuxadmin

For global.

# edquota -T

9) How to Disable Disk Quotas in Linux Using the quotaoff Command

To turn all user and group quotas off, use the following command.

For a specific file system.

# quotaoff -ugv /home

For all file systems.

# quotaoff -augv

10) How to Enable Disk Quotas in Linux Using the quotaon Command

To enable user and group quotas for all file systems, use the following command.

For a specific file system.

# quotaon -ugv /home

For all file systems.

# quotaon -augv

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

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