Configuring File System Quota

Category: Linux
Created: 2019-10-31

It’s recommended to enable file system quota on web servers, to check and to limit the disk space used by webhosting subscriptions. If a server is running just as a database server or as mail server, there’s no need for file system quota.

LiveConfig uses the so-called group quota - the disk space is limited per group.

Install quota system

Install the package “quota”, depending on your distribution:

  • Debian/Ubuntu:

    root@srv:~# apt install quota
  • CentOS / Red Hat Enterprise Linux:

    root@srv:~# yum install quota
  • openSUSE:

    root@srv:~# zypper install quota

Enable file system quota

  • on ext3/ext4 file systems add the options,jqfmt=vfsv0 to /etc/fstab, e.g.:

    UUID=[...]  /  ext4  errors=remount-ro,,jqfmt=vfsv0  0  1

    Then remount the file system:

    root@srv:~# mount -vo remount <file system>

    After this, recalculate the current quota usage:

    root@srv:~# quotacheck -vgm <file system>

    Finally, you can enable the quota:

    root@srv:~# quotaon -vg <file system>
  • on XFS file systems it depends if quota has to be enabled on the root file system (/) or on any other file system. If you want to enable it on a non-root file system, just add the option grpquota to /etc/fstab and remount it:

    UUID=[...]  /var  xfs  errors=remount-ro,grpjquota  0  1
    root@srv:~# mount -vo remount <file system>

    If quota should be enabled on the root file system, you need to add the option rootflags=grpquota to the boot flags of your kernel. If the server is using a boot loader like e.g. Grub, add this option to the corresponding configuration file; when booting a virtual machine this might be added to its host configuration file (with Xen for example using the option extra = 'rootflags=grpquota').

  • on Virtuozzo-/OpenVZ containers the so-called second level quota has to be enabled for the corresponding container, which can only be done by the administrator of the host system. You can find more informations on this in the Virtuozzo documentation or in the OpenVZ Wiki.

    Set the option quotaugidlimit to the maximal number of users and groups in the container, including all system users and groups. After this, reboot the container to apply the new settings.

    This example shows how quota is enabled for the container 101 with at most 500 users/groups:

    root@srv:~# vzctl set 101 --quotaugidlimit 500 --save
    Unable to apply new quota values: ugid quota not initialized
    Saved parameters for CT 101
    root@srv:~# vzctl restart 101
    Restarting container
    Stopping container ...
    Container was stopped
    Container is unmounted
    Starting container ...
    Container is mounted
    Adding IP address(es):
    Setting CPU units: 1000
    Configure meminfo: 65536
    File resolv.conf was modified
    Container start in progress...

Check file system quota

You can check with repquota -ag if group quota is successfully enabled:

root@srv:~# repquota -ag
*** Report for group quotas on device /dev/disk/by-uuid/[...]
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
root      -- 1203900       0       0          51406     0     0