5

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?

terdon
  • 104,119

1 Answers1

8

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.

b_laoshi
  • 4,868
  • 4
  • 26
  • 49