How to Configure and Administrate Disk Quota in Linux?

In this Tutorial, I will explain how to configure Disk Quota in Linux Servers with all the basic concepts (Soft Limit, Hard Limit, Grace Period, blocks and inodes and many more)

The concept of Disk Quota:

1. In Production Servers, if there is a requirement to restrict the amount of disk space used on a partition by each and every user,  we can accomplish that by using the Disk Quota Features

2. If the Disk is being used by a single user(only one user) then there is no need of configuring the disk quota, when there are more numbers of users accessing a single partition, one or more users can upload files on an FTP server to the point of filling a file system. Eventually, other users are denied to upload access to the disk (Since the partition size is full).

3. With the Disk Quota Method in Linux, we can restrict or limit a user or group of users ability to consume disk space

Note1: User’s with quota enabled are not allowed to use additional disk space beyond his/her quota  Limit.

Note:2 Disk Quota methods are mostly used  by ISP’s by Web Hosting companies, On FTP sites (Google Drive, One drive and many more cloud services)and also on corporate file servers to make sure continuity availability on their file systems

 

How to Configure Disk Quota in RedHat Servers

In this Lab I use the regular partition for the demo setup, you can also add additional disk and then by creating one partition can enable the quota on that.

Note: Use the partition which doesn’t contain any important data in it.

Create a User and Assign a password

#useradd  Vasanth

#passwd Vasanth

Check the quota package is installed on your server

#rpm  -qa quota

Before we configure the quota we must know some of the important concepts we use it in Disk Quota.

1)Inode Number

Configuring Disk quota can be done to a user or group users based on the inode number or block size. The inode number is nothing but, it contains the entire information about the file(UID, GID, Size, Modify time, Access time etc) all these information are stored in the inode table. So every file uses one unique Inode number which contains the metadata about that file.

To control the size of the file ,we  should configure the quota based on the block size and if you want to control the number of files then we use inode number to configure disk quota, if you want to control both means, you need to configure the disk quota based on the block size and inode number.

a)For Example, if the quota is configured based on the inode number, Example 50 inode number is assigned to a user called NIRMAL, Since we haven’t assigned the block size, the user NIRMAL can create 50 files, no matter how big or small size they are, NIRMAL can create very large files,for instance NIRMAL can create a file of 50GB in size(ext4 file system supports 16Tib individual file size). here there is no control for the size of the files, the user can abuse the system.

b)For Example, if the quota is configured based on the block size, for instance, a 2GB quota is configured based on the block size for the user JOHN, Now JOHN can create files until the entire 2GB space is not filled up. But he can crash the inode tables by creating some 20000 files with each one with the size of 1kb, which means 200000 inode entries in inode table, Only with this 2GB  the user JOHN can crash the inode table.

 

c)If the quota is configured by Inode number and block size, for instance, 2GB Block size and 50 Inode numbers  are configured for a user “VASANTH”,now this user he cant crash the inode table or can abuse the disk space,coz he is not allowed to create more than 50 files and not allowed to use the disk space more than 2GB,

So I highly recommend you to use both inode number and block size while assigning a quota to a user.

Procedure to create the Disk quota:

1)Should Enable the quota

2)Remount the filesystem with quota

3)Create quota files

4)Configure inode or block-based policies.

Step:1  Save the quota details inside /etc/fstab file

In Linux,/etc/fstab file contains all the file system details to mount automatically at the time of booting. This file has the information about where it is mounted, the type of file system, permission and many more attributes.

In this example, I will use the partition /dev/sda2 to enable the quota.

#vi  /etc/fstab

To Enable the quota we should add “usrquota” in the fourth field, So from the above output, we have successfully enabled the quota on the partition /dev/sda2.

Note: Any changes made in the /etc/fstab file will not take update until next time reboots. This update can be done in two ways one is “reboot” the server and the second one is remount the partition with the quota options, In production servers, it is not advisable to reboot the server, so the second option would be better to update the /etc/fstab file changes.

Step:2  Remount the File System

Syntax:

#mount   -o  <option>   <filesystem or mount point dir>
  #mount  -o remount,usrquota   /home

As you can see from the above output we have successfully remounted the partition with quota, if the partition is remounted without any error which says the quota option is successfully applied.

Step:3  Create the Quota Files

To create the quota files run the following command,

Syntax:

#quotacheck   -cu  <quota enabled Partition >

quotacheck = Used to check the quota implementation

-c = To create the quota files in the partition

-u = To check the user quota

As you can see from the above output the “usrquota” file has been created under the partition mount point directory /home.

Step:4  Sync the disk quota database file with the current disk usage

#quotacheck -avu

-a = To check all quota enabled partitions

-v = To display the verbose output (i.e Real-time output)

-u = Check user disk quota  details

As you can see from the above output, quota database files successfully synchronized.

Step:5  Configure the Quota Limits for users

In order to configure the quota for users, we need to assign three values

1.Soft Limit

2)Hard Limit

3)Grace Period

SoftLimit= This is the maximum amount of space a user can have on that partition, If you set a grace period then this will act as an alarm, User will be notified he/she is in quota violation

HradLimit= It is Necessary only when you are using grace periods. If the grace period is enabled then this will be the absolute limit a user can use, any attempt to consume resources beyond this limit will be denied

 

Let us assign a quota for user JAS

To configure quota we need to use the command“edquota” followed by the username

#eduota   JAS

As you can see from the above output, the user “JAS” is allowed to  consume the maximum disk space is 100MB,once the user reaches the soft limit the grace period will start running and the user can use the size up to 100MB, After reaching the size 100MB, user will receive “quota exceed” message  on his screen.

Tips: Default Block size is 1kb(1block=1kb)

To check the assigned quota details  run the following command

#repquota -a

As you can see from the above output you can check the quota assigned to all the users.

The user “JAS” is allowed to consume the maximum disk space of 100MB, and the default grace period is 7 days, once the user reaches the soft limit, the grace period will start running.

Now let me log in to the JAS account and try to create some files with the size more than 50 or 100 MB

#su - JAS

$

As you can see from the above output, when JAS try to create a file with the size above 100MB  he is denied to consume the disk space beyond his limit, This is how the disk quota works.

Useful Commands:

To check the quota details for an individual user run the following command

#quota  JAS

Tips:

1)If the Soft Limit and Hard Limit are same then grace period is not required

2)If the Soft Limit and Hard Limit are  different then grace period is  required

3)Hard Limit size should be higher than the soft Limit

4)Once the grace period is expired, then users are not allowed to use any additional spaces

5)Grace period timer will be removed automatically, once the user brings the consumption below the soft Limit

***********************************************************************************************************************************

I hope you have enjoyed this article, if it was please share it with your friends, hit the Subscribe button below and be sure to share among with your friends.

###########################################################################################

If you found this article useful, Kindly Subscribe here 👉  Click this link to Subscribe

Never miss an article Do like my official  FB page 👉 Learn Linux in an easier way

For More Videos Subscribe My Youtube Channel    https://youtu.be/A7a72pmPa5o

############################################################################################