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?

link|improve this question

74% accept rate
Mounting files via loopback doesn't really present an expansion problem. You would simply extend the underlying file and then use resize2fs to grow the filesystem. I think using LVM is a better solution, but the one you proposed does not have the limitations you think it does. – larsks Jan 7 '11 at 16:12
feedback

5 Answers

up vote 10 down vote accepted

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
link|improve this answer
feedback

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

link|improve this answer
Unfortunately I can't change underlying fs. But it's good to know that XFS has this capability. – depesz Jan 7 '10 at 21:21
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.