FreeKB - Disk Quota
Linux Fundamentals - Disk Quota

This assumes you have installed quota using apt-get or yum.

yum install quota

 

  • Use the quotaon command to set a quota on a directory. If needed, use the edquota command to edit the quota settings.
  • Use the reqquota and quotacheck commands can be used to view information about a directories quota.

 


Math

Before we set a quota that limits how much data can be stored in the /var directory, we need to determine the total block size of /var.  Use the df command to view the total block size of /var. Let's say the the total block size of /var is 300000000. 300000000 bytes is 300 GB. This means that the /var directory can contain a total of 300 GB of data.

df

 

If repquota -a lists 4 users, to be very safe, we can divide 300,000,000 by 4, which makes 75,000,000. We should set a hard limit of 75,000,000 for each user, and a soft limit of 70,000,000. This will ensure the /var directory is never completely used.

Use the edquota command to edit the quota limit for the WebAdmins group.

edquota -u user1

 

The default limits will be 0.  A hard limit of 250000000 is reasonable. We could also set the soft limit at 2000000000 so that an alert appears before reaching 250000000. Use the repquota command to verify that the quota has taken effect.

repquota -a

 

To test quota to ensure it is working, we can set a hard limit that is 1 block. For example, lets say the used block size is currently 123,456. We can set both the hard limit and soft limit to be 123,457. This should prevent us from being able to add aditional files to /var. Use the touch command to create a new file in /var, and then add junk data to the new file.

  1. In Terminal, type cd /var
  2. Type touch test
  3. Type nano test
  4. Type a bunch of mumbo jumbo, such as adlsfkalvjalvjapiovajvoiajv[olasdvnjal'dvnas'vdlknavl'kajsvlakjva'lvjkal'kj
  5. Press Ctrl O (to save)
  6. Press Ctrl X (to exit the nano editor)

 

Use the df command to ensure the block size has not exceeded 123,456.

df

 

Use the repquota command again. If - - or - + or + - is displayed, the quota has been exceeded.

repquota -a

 

Soft limit can also be set for a user using the -T (time) option.

edquota -u username -T

 

Use the quotacheck command with the -mavug option to update the quota database.

  • -m option (run the command even if the filesystem is being used by other processes)
  • -a option (check /etc/fstab)
  • -v (verbose)
  • -u (all users)
  • -g (all groups)
quotacheck -mavug

 

A CRON job should be create to run quotacheck -mavug on an hourly basis, to resolve issues with mounting errors or filesystem errors.

  1. In Terminal, switch to the root user - su root
  2. TBD - need to create a BASH script in /etc/cron.hourly
  3. Type crontab -e
  4. TBD

 

An email can be sent to the WebAdmins once a day with a summary of the total size, used and available space on the /var directory. 

  1. In Terminal, switch to the root user - su root
  2. Type cd /etc/cron.daily
  3. Type nano diskusage and press Enter
  4. Type the following:
#!/bin/bash
sender="From: John Doe"
recipient="webadmins@example.com"
subject="Disk Usage Report"
(printf "$(df -h)") | mailx -a "$sender" -s "$subject" $recipient
  1. Press Ctrl O (to save)
  2. Press Ctrl X (to exit the nano editor)
  3. Type crontab -e
  4. Type the following: 0 1 * * * bash /etc/cron.daily/diskusage
  5. Press Ctrl O (to save)
  6. Press Ctrl X (to exit the nano editor)

 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 4065c in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |