You can add disk quotas for users, so a user can’t take up too much disk space.

Run all commands as root or with sudo.

Install the required package

First, install quota package (in some systems, it may be called quota-tools).

Set up the filesystem

Then, set up the filesystem you want to enable quotas by editing /etc/fstab file: add usrjquota=aquota.user,jqfmt=vfsv1 in the options section of the filesystem. For example:

/dev/sda3 /home ext4 defaults,usrjquota=aquota.user,jqfmt=vfsv1 0 2
  • This will allow user quotas, to allow group quotas, append grpjquota=aquota.group.
  • Be careful when editing /etc/fstab, you can make the filesystem unmountable.

Remount the filesystem, or reboot the system if it is the main filesystem.

Create a quota index for the filesystem:

quotacheck -cum <filesystem>
# quotacheck -cum /
  • Append -g parameter to create a group index.

Finally, enable disk quotas for the filesystem

quotaon -v <filesystem>
# quotaon -v /
  • You can disable quotas with quotaoff.

Create a user quota

Specify a quota for a user:

edquota <username>
# edquota ricardo
  • It will open your default text editor, and you will be able to edit the quotas.
Disk quotas for user ricardo (uid 1000):
Filesystem  blocks  soft  hard  inodes soft hard
/dev/vda1   863500  0     0     1840   0    0
  • blocks: number of 1k blocks currently used by the user.
  • soft: max number of 1k blocks allowed before a warning is issued.
  • hard: max number of 1k blocks the user can use.
  • inodes: number of inodes currently used by the user.
  • soft and hard: same as before, but with inodes.

Once edited, save the file and close it.

Grace period

You can add a “grace period” to give users a time to reduce their storage. This applies where storage is above the soft limit but below the hard limit. Type edquota -t and edit the file.

Type quota -u <username> to check user quotas.

If you have any suggestion, feel free to contact me via social media or email.