Search code examples
linuxdirectorysizelimit

How to set limit on directory size in Linux?


I have read about limiting size of directory - like creating big files, formatting, mount,.. etc. But this is all very complicated. Does a utility or something else exist to set a limit on an already existing directory?


Solution

  • Quota is based upon filesystems, but you can always create a virtual filesystem and mount it on a specific (empty) directory with the usrquota and/or grpquota flags.

    In steps this will be:

    1. create the mount point
    2. create a file full of /dev/zero, large enough to the maximum size you want to reserve for the virtual filesystem
    3. format this file with an ext3 filesystem (you can format a disk space even if it is not a block device, but double check the syntax of every - dangerous - formatting command)
    4. mount the newly formatted disk space in the directory you've created as mount point, e.g. Code: mount -o loop,rw,usrquota,grpquota /path/to/the/formatted/disk/space /path/of/mount/point
    5. Set proper permissions
    6. Set quotas and the trick is done.

    Tutorial here. Original answer here