I have following scenarios:
Single partition mounted as /, with lots of disk space.
There is a range of directories (/pg/tbs1, /pg/tbs2, /pg/tbs3 and so on), and I would like to limit total size of these directories.
One option is to make some big files, and then mkfs them, and mount over loopback, and then set quota, but this makes expansion a bit problematic.
Is there any other way to make the quota work per directory?
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:
Growing the project filesystems is easy:
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.
Yes. Look at XFS filesystem and project quota. Other filesystem do not offer this feature.
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.
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.
I am not aware of any method to set quotes per directory.
But along your idea of creating file-systems with a limited size. This might be a place where lvm would be a good solution.
You could backup/reinstall and use lvm, only allocating the minimum amount of space needed to your logical volumes. It is very easy to extend lvm logical volumes.