X
    Categories: Linux

How to enable disk quota that manages the space

We can able restrict Disk space once we enable disk quota which alerts a sysadmin before a user takes too much disk space or a partition becomes full.Quotas can only be created for partitions.Quota is of two types, user and group.If we enable quota of 1 MB  is set for the partition /home, then every directory under /home or every user on the system, since each directory in /home represents an user, can use a max of 1 MB.

Follow below steps to enable disk quota:

Step 1: First of all Enable disk quota at the partition level by editing /etc/fstab file. Just edit the below line in the file as below:

/dev/sde1 /home ext4 defaults,usrjquota=aquota.user,jqfmt=vfsv0 1 2

Step 2: Remount the /home partition.

# umount /home
# mount /home

or

# mount -o remount /home

Step 3: scan /home and enable quota on it.

quotacheck -vcug /home

In some cases you may encounter below error.

quotacheck: Cannot create new quotafile /home/aquota.user.new: Permission denied

Hence to avoid above error you need to disable SELINUX . Please follow this procedure for disabling SELINUX.

Once you ran quotacheck command successfully as a result “aquota.user” file gets created under /home partition.

[root@rhel1 home]# ls -l
total 24
-rw-------. 1 root root 6144 Jan 1 16:52 aquota.user

Step 4: Turn on quota.

[root@rhel1 home]# quotaon -v /home
/dev/sde1 [/home]: user quotas turned on

Step 5: To check if quota is on or not.

[root@rhel1 foo]# repquota -a
*** Report for user quotas on device /dev/sde1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 3 0 0
foo -- 4 0 0 4 0 0

To Implement the quota follow below procedure:

Step 1: To edit quota for a user “foo”

[root@rhel1 ~]#  edquota -u foo

The above command opens editor window as below where you can change values as per your need.

In the above output:

1st column: Name of the disk or filesystem where quota is turned on

2nd column: Describes current blocks is in use.

3rd column: Soft limit on the File-system.

4th column: Hard limit on the File-system.

5th column: shows how many inodes the user is currently using.

6th and 7th column: are used to set the soft and hard inode limits for the user on the file system.

Step 2: To edit grace period for user:

[root@rhel1 ~]# edquota -t

This also opens one editor window as below:

Step 3: To copy a quota setting of one user to another user

[root@rhel1 ~]# edquota -p foo bar

This will apply foo’s settings to the user “bar”

So this how we can enable disk quota in Linux.

Related Post