On the off chance that you are the main individual who utilizes the disk, there is no compelling reason to actualize quota by any means. In any case, if there are different users who utilize a similar disk, quotas are the most ideal approaches to control the individual users from cornering whole disk space. A client restricted by disk quotas can’t utilize extra disk space past his cutoff. For instance assume there are four users; client a, client b, client c and client d. Without quota any client can utilize whole disk space, leaving no space for different users. This circumstance is exceptionally normal in shared environment, for example, web hosting, ISPs, record server, ftp server and so on. However, in the event that disk quota is empowered, no client can utilize disk space past his utmost.
In this tutorial I will explain how to setup disk quota in Linux.
There are two methods to implement disk quota on Linux:
- 1. File system base disk quota allocation
- 2. User or group based disk quota allocation
Before going ahead lets discuss abut some important factor to consider:
Hard Limit : User will not be able to create a new file after specify hard limit for example if you specify 5GB as hard limit, user will not be able to create a new file after 5GB.
Soft Limit : User will get a warning message ” Disk Quota Exceeded”, once if they reached 4GB, if you specify soft limit 4GB, but they will still be able to create a new files until they reached the hard limit.
Grace Period : If user reached their hard limit they would be allowed additional 7 days to create new files, if you specify 7 days as a grace period. During this period user try to get back to the quota limit.
Enabling Quota Check On File System
First, specify which file system are allowed for quota check. Edit the /etc/fstab and add usrquota and grpquota to the corresponding file system that you would like to monitor.
# cat /etc/fstab LABEL=/home /home ext2 defaults,usrquota,grpquota 1 2
In the above example I have enabled user and group quota check on /home file system. Reboot the server to apply changes.
Initial Quota Check on Linux Filesystem Using quotacheck
After enabling disk quota on filesystem, collect all quota information initially like below:
# quotacheck -avug quotacheck: Scanning /dev/sda2 [/home] done quotacheck: Checked 5182 directories and 31566 files quotacheck: Old file not found. quotacheck: Old file not found.
- a: Check all quota enabled filesystem
- v: Verbose mode
- u: Check for user disk quota
- g: Check for group disk quota
You can see the created aquota file for user and group under the filesystem directory after running above command.
# ls -l /home/ -rw------- 1 root root 11264 Oct 20 13:49 aquota.user -rw------- 1 root root 11264 Oct 20 13:49 aquota.group
Now enable the quota typing below command.
# quotaon /home
Set Disk Quota For User Using edquota command
Now use the edquota command like below to assign the disk quota for specific user.
For example, Set disk quota for user “sagar“, run edquota command which will open the soft and hard limit values in an editors like below.
# edquota sagar Disk quotas for user sagar (uid 500): Filesystem blocks soft hard inodes soft hard /dev/sda2 1419352 0 0 1686 0 0
Now set here soft and hard limit for disk quota size for the particular user. Soft and hard limit for the total number of inodes that are allowed for the particular user.
Check The Disk Quota Usage For Users and Groups Using repquota
Run the repquota command like below to report the disk quota usage for users and groupds.
# repquota /home *** Report for user quotas on device /dev/sda2 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 566488 0 0 5401 0 0 nobody -- 1448 0 0 30 0 0 sagar -- 1419352 0 0 1686 0 0 Faeem -- 26604 0 0 172 0 0
Quota check Report on Daily Basis
You can add the quotacheck to the daily cron job for daily quota check report on daily basis. Below command will be execute everyday and will send the output of the quotacheck command to root email id.
# cat /etc/cron.daily/quotacheck quotacheck -avug