How can I set quota on folders?

15,724

One of many options: Creating a sparse file, formatting it with a file system, mounting it, and sharing it.

There are a few ways to go about it. Some require a bit of configuration. Here's a simple approach that won't require installing any special quota management software. Basically, we set up a 10GB container that we format as ext4 (or whatever), mount, and share.

  • Decide where you want to save her 10GB file. Open a terminal and cd to that directory.
  • Create a 10GB sparse file. This will actually start out with a real size of zero (reported by ls as 10GB though) and grow (du command can show real size) as she adds data

    dd if=/dev/zero of=10GB_Container.img bs=10G count=0 seek=1
    
  • Format the sparse file

    mkfs.ext4  10GB_Container.img
    
  • Create an empty folder somewhere on your computer where you'll mount the sparse file.

    mkdir /your/path/to/mount/point
    
  • Open /etc/fstab for editing and at the very bottom, add an entry to automatically mount your sparse file. Add the following line, changing the paths. The mount will take place automatically on successive boots.

    /path/to/10GB_Container.img    /your/path/to/mount/point    ext4    defaults,loop    0    2
    
  • If you don't want to reboot at this point, mount the sparse file

    sudo mount /your/path/to/mount/point
    
  • Point the file sharing server for your sister's directory to /your/path/to/mount/point.

Now your sister will be limited to 10GB, because the sparse file you created can't grow beyond that size. If she looks to see how much space she has available to her, the limit will be 10GB regardless of the size that the sparse file actually uses on your disk.

Like I said, there are other ways to go about this. I leave other approaches for others to post in separate answers.

Share:
15,724

Related videos on Youtube

houseofkraft
Author by

houseofkraft

Updated on September 18, 2022

Comments

  • houseofkraft
    houseofkraft over 1 year

    I just set up a file server using Ubuntu 17.04 and my sister wants to use it. I want my sister to have a quota of 10GB of data. I am using samba to setup the file server.

    How can I limit my sister's user to only 10 GB of space?

    • nullmeta
      nullmeta about 7 years
      Do you happen to be using lvm or zfs? If lvm you can create a 10GB volume and share that to your sisters user. Zfs you can quota a specific filesystem inside the zfs pool.
  • JayEye
    JayEye almost 7 years
    Using a loopback-mounted filesystem is way too wasteful.
  • b_laoshi
    b_laoshi almost 7 years
    @JayEye, care to elaborate or at least provide a link with information detailing the waste? You've got me curious to know how since a quick search on overhead for loopback devices didn't turn up anything indicative of waste.
  • Isaac Rabinovitch
    Isaac Rabinovitch almost 3 years
    This looks very good, and I will definitely give it a try. But you keep reminding us that there are other ways to do this, and I'd surely like to hear some of them.
  • b_laoshi
    b_laoshi almost 3 years
    It's been a while since I dived into this, but here's a link to another way that I've used in the past.