25

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?

2
  • 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, 2011 at 16:12
  • also btrfs and zfs
    – hanshenrik
    Apr 16, 2016 at 11:04

6 Answers 6

20

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
9

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.

0
6

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

1
  • Unfortunately I can't change underlying fs. But it's good to know that XFS has this capability.
    – user13185
    Jan 7, 2010 at 21:21
6

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.

2
3

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.

2

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.

You must log in to answer this question.