1. Home
  2. Linux
  3. Install and Configure User and Group Disk quota on Ubuntu and Debian

Install and Configure User and Group Disk quota on Ubuntu and Debian

Most of the time, the user keeps all of his junk/unwanted files in his home directory and never bothers to clear it. This might block the usage of storage to other genuine users. So, quotas are used to limit the amount of disk space a user/group can use on the system. To implement quotas, a quota tool is used to dynamically manage the disk quota of a user/group. Advantage of using quota tool is the ability to change the quotas on the fly without any complicated disk resizing!

This step by step tutorial will show you how to install the quota tool and focuses on the configuring User and Group quotas.

Set user/group quota ubuntu

Step 1: Installing Quota tool on Ubuntu system

#apt-get install quota

Step 2: Enable quota check on filesystem

a. Before applying the user specific quotas, the mount options of the filesystem has to be edited. So, open the /etc/fstab as shown below.

#vim /etc/fstab

By adding the keywords usrquota (for user specific quotas) and/or grpquota (for quotas on groups) to the mounting options, you can enable the quotas. You may add the keyword usrquota/grpquota as shown below in  fstab file with desired drive to be used under quota.

LABEL=cloudimg-rootfs   /        ext4   defaults,usrquota,grpquota        0 0

Save the file and quit.

b. Enable the new mount options by remounting the file system:

#mount -o remount /

c. After enabling the quota and remounting the file system, the system is capable of working with disk quotas. However the file system itself is not yet ready to support quotas. The following command will create a  quota file in the root directory of the file system for user and group. This is an index file used by the quota tool for keeping track of the user’s disk size. It also contains the limits on usable disk size for the particular user.

#quotachek -cum /

The command consists of the following three parameters:

c: Create new Quotas file
u: Check for user disk quota
m: do not remount filesystem read-only
#ls -l /
-rw------- 1 root root 7168 Jun 15 09:30 aquota.group
-rw------- 1 root root 7168 Jun 15 09:31 aquota.user

Step 3: Configure User and Group Disk Quotas

The user/group quotas are configured using the utility edquota, following the username or group name, as shown in the below command:

#edquota ubuntu

The command will open the text editor with default configured values. For example, to set the disk quota of 10Mb for user ‘ubuntu‘ as shown below:

Disk quotas for user ubuntu (uid 1000):
 Filesystem          blocks           soft           hard       inodes        soft          hard
 /dev/vda1             32            10000          10240            9           0             0

The text editor shows 7 different columns as explained:

1. Name of the file system
2. Total blocks used by the user
3. Soft block limit for the user on the filesystem
4. Hard block limit for the user on the filesystem
5. Total iNodes used by the user
6. Soft inode limit for the user on the filesystem
7. Hard inode limit for the user on the filesystem
Blocks refer to the amount of disk space
inodes refer to the number of files/folders that can be used,

Most of the time, block amount will be used to set quota. The Hard block limit is the absolute max amount of disk space that a user or group can use, after which no files can be created. Whereas, soft block limit defines the max amount of disk space, however, soft limit can be exceeded for a certain amount of time which is configurable as grace period. By default the grace period is of 7 days and to edit the grace period run the below command:

#edquota -t
Grace period before enforcing soft limits for users:
 Time units may be: days, hours, minutes, or seconds
 Filesystem          Block grace period        Inode grace period
 /dev/vda1                  7days                    7days

You can also use the below command to set quota for the user:

#setquota -u ubuntu 10000 10240 0 0 -a /

Step 4: Generating reports on user quotas

At once you can generate the report of disk quota usage for the user’s using the below command:

# repquota -a
*** Report for user quotas on device /dev/vda1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
root         -- 1404912       0       0          65583     0     0
ubuntu    +-         32       10      11  6days       9     0     0

Note, the user ‘ubuntu‘ has only exceeded his block limit and not the file limit indicated by +- sign.

Step 5: How to turn on and turn off Linux disk quota using quotaon and quotaoff commands

You can enable the disk quotas for an already mounted filesystem by using the following command:

# quotaon -vug /
 /dev/vda1 [/]: group quotas turned on
 /dev/vda1 [/]: user quotas turned on

In case, if you get an error message “quotaon: Quota format not supported in kernel”, then click here to fix the issue.

Similarly, you can disable the disk quotas using the following command:

# quotaoff -vug /
 /dev/vda1 [/]: group quotas turned off
 /dev/vda1 [/]: user quotas turned off

Related Content
Updated on September 4, 2017

Was this article helpful?

Related Articles

Add A Comment