Enable Quotas on CentOS 6

October 15, 2015 Jordansphere Linux

In this example I will be checking all user quotas on an LVM which is mounted as /data 

 

1)  The first  step will be to check the fstab. As we see there are no mount options for quotas

# cat /etc/fstab

#
/dev/mapper/centos-root /                       ext4    defaults        1 1
UUID=2fd24677-cf50-420b-a3dd-cea7c29aa185 /boot                   ext4    defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/VolGroupData/DataVol       /data    ext4     defaults    1 2

 

2) We want to enable user quotas on the /data directory so we need to add the usrquota mount point attribute after defaults

# vi /etc/fstab

--

/dev/VolGroupData/DataVol       /data    ext4     defaults,usrquota    1 2

--

 

2) You can umount and remount the volume if not in use. Otherwise just reboot the server. 

# reboot

 

3) Now we need to create the quota files and specify the mount point 

# quotacheck -cu /data

 

Flags:

-c, –create-files
              Don't read existing quota files. Just perform a new scan and save it to disk.  quotacheck also skips  scanning  of  old
              quota files when they are not found.

-u, –user
              Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked.  This is the default action.

 

 

 

4) Once that has completed we can run aother quotacheck which generates the usage

# quotacheck -avu
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/mapper/VolGroupData-DataVol [/data] done
quotacheck: Old group file name could not been determined. Usage will not be subtracted.
quotacheck: Checked 3 directories and 2 files

Flags:

-v, –verbose
              quotacheck reports its operation as it progresses

-u, –user
              Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked.  This is the default action.

-a, –all
              Check all mounted non-NFS filesystems in /etc/mtab

 

 

 

5)  We can then select all users to get a report.

# repquota -a
*** Report for user quotas on device /dev/mapper/VolGroupData-DataVol
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      28       0       0              4     0     0

 

At the moment we only have the root user

 

6) Add a job to the crontab  to check quotas every day. This ensures quotas are more accurate.

# vi /etc/crontab

##

0 7 * * * root /usr/sbin/quotacheck -avu

##

 

Note: By default all user quotas are set to 0 by default so you may need a script to set user limits.

centos, lvm, quota, quotacheck, repquota,

Powered by WordPress. Designed by elogi.