I like to use container files instead of using disk quota. It presents less overhead to the operating system and if the container file gets filled it won't interfere with the operating system. Here is what I mean. In this case I will use loop devices. It might be better to use device mapper but I am just learning about that.
- Create a file that is as large as the maximum disk usage allowed for ftp.
- Connect the container file to a loop device.
- Format the loop device for your favorite file system.
- Mount the loop device at the point that you want to locate your ftp.
Note that this is about 3/4 of the steps needed to create an encrypted ftp (or any) file system. Here again device mapper would be better than using cryptoloop so I won't do the encryption part.
I am guessing from your post that you feel that you have more space on the root partition than on the var partition so we will make the container file on the root partition. Since we can't discuss this I'm going to say that if possible you would prefer to keep your ftp in /var/ftp just so that you don't have to change any scripts but you want to use the space on the root partition to do this. So let's make the /ftp area the place that we create our container file.
Code:
$ dd if=/dev/zero of=/ftp/container.file bs=1024 count=4096
That command will create a 4 megabyte file. You can adjust the numbers to fit your requirements. Note that people have different styles regarding how the size numbers are used. Some people might say bs=4000000 count=1 to make a more or less 4 megabyte size file. It makes more sense to me to use a byte size that is the typical size of a file system block but in reality it makes not difference at all.
Anyway now we have a 4 MB file in /ftp called container.file. (/ftp/container.file) Now we connect that file to a loop device.
Code:
$ losetup /dev/loop0 /ftp/container.file
Once we connect the container file to a loop device we can treat the container file just like a disk partition when we access the file through the loop device. Now we create a file system inside the container file through the loop device.
Code:
$ /sbin/mkreiserfs /dev/loop0
Initially you will want to mount the container file at a temporary mount point in order to transfer the contents of /var/ftp into the container file. Once that is done you can mount the container file using the old ftp directory as a mount point.
First make a little helper to let you quickly know that the container file is not mounted at /var/ftp.
Code:
$ touch /var/ftp/container.file.is.not.mounted
This way if you list the /var/ftp area and if you see that file you will know that the container file is not mounted. Now we mount the ftp container file.
Code:
$ mount /dev/loop0 /var/ftp
Now your ftp users can have the /var/ftp area as it always was, which may or may not be important to any scripts. I'm thinking of system admin scripts that you may or may not have running.
Now you can put a line in /etc/fstab to automatically mount this container file at /var/ftp when the system starts.
Code:
/ftp/container.file /var/ftp auto loop,noexec,nosuid,users 0 0
I think that is basically the correct fstab line. I don't use a line in fstab because my loop file systems are encrypted and I don't automatically mount them when the system starts. You may have to play with the fstab line a bit. I don't know. Here is a line to manually mount the container file to /var/ftp.
Code:
$ mount -o loop /ftp/container.file /var/ftp
You can see that since the container file already has a file system we don't need to use the losetup utility. The -o loop option in the mount command will automatically choose the lowest numbered available loop device and make the connection to the container file for us. Of course you would want to add mount options like noexec, nosuid, noguid, and possibly others.
This approach is also possible for each individual user's home directory. If you have interactive users you can tailor each user's permitted disk space allowance without using disk quota by way of mounting a container file at each user's home directory. If a user fills up his/her container file it won't affect anybody else.