Linux - quota per directory?

Solution 1:

If you're forced to use ext3, then using LVM is probably your best solution. Create a new filesystem per project. That would look something like this:

# Create a 10g filesystem for "project1" in volume group "vg0"
lvcreate -L 10g -n project1 vg0

# Create an ext3 filesystem.
mke2fs -j /dev/vg0/project1

# Mount it (obviously you would want this in /etc/fstab)
mount /dev/vg0/project1 /projects/project1

Growing the project filesystems is easy:

# Add 2GB to the volume.
lvextend -L +2g /dev/vg0/project1

# Grow the filesystem.
resize2fs /dev/vg0/project1

Solution 2:

If you don't rely on group permissions, you can use a different UNIX group for each "quota directory", then set sgid bit on each directory (so created files and directories will belong to the group of the directory instead of the primary group of the creator user), and use group quotas.

Solution 3:

Yes. Look at XFS filesystem and project quota. Other filesystem do not offer this feature.

Solution 4:

I've actually wanted to do this for a while because I didn't want to have to make system users for all of my virtual mail users. ZFS filesystems with quotas would be great, and zfs-fuse makes progress every day, but what I wanted was a very lightweight solution. Finally I decided to write a FUSE filesystem that I could mount as a layer over another filesystem (any base directory will work actually). It has a utility for managing quotas that can be scripted with easily and since quota values are just stored as xattrs on directories or files, one mountpoint can provide support for an arbitrary number of quotas.

I've been testing it on a mail server for a while and recently decided it had reached adolescence and was ready to release into the wild. If you're curious, you can check it out at http://code.google.com/p/fusequota/. I would greatly appreciate any feedback.

Solution 5:

New filesystem for each shared folder is IMHO overkill. Just make new group for each shared folder, set owner group of shared folder to this group, set a sticky bit to group (so that every new file and directory has this group as owner )and for permissions on files and folders use acl lists. Then set quotas for these groups.