This simple tutorial explains the process of setting up User and Group quotas on Linux (tested on Fedora 9. steps may be similar for any UNIX OS).
As you know UNIX and its brother Linux is a multiple user Operating System. So, we need to check that no user abuses the system by storing large files which leads to lack of Hard Disk space. So, we have Quotas on Linux. Quotas are nothing but assigning a specific amount of Hard Disk Space to a user or a group. Linux supports limiting space as well as no. of files. While commonly used is Limiting Space, in some cases you may need limiting no. of files also. Limiting Space & No. of Files can go hand in had or they can be assigned separately i.e. both of them are independent. You can have limiting no. of files which implies that the user can have only a specified no. of files while their sizes don't matter.
So, let's come to the actual part of the tutorial.
By default in any UNIX system, users' files are stored in /home/
Here in this tutorial, we assume that you don't have a separate partition for /home, so users' files are contained the root partition under sub-directory /home. If you have such a partition just, replace things with /home where filesystem is referred to.
User Quotas
User Quotas means limiting space (or no. of files) for a user which is applicable only the user.
Step 1: Remount / with usrquota option --
# mount -v -o remount,usrquota /
This will remount your / partition with usrquota option which stands for "Enable User Quotas"
Step 2: Run quotacheck --
# quotacheck -ucvm /
Here, -ucvm has four options -
u = check user quota files
c = create quota files
v = verbose
m = don't remount the file-system to read-only
m is required because we're checking / and / cannot be mounted read-only anytime.
Step 3: Turn Quotas On --
# quotaon -vu /
Again in the options -vu; u stands for enable user quotas and v stands for verbose. Further we're not going to explain what is u and what is v.
Step 4: Set Quota for a user --
# setquota -u user_name 1024 1024 20 22
In the above command, first number 1024 stands for block-soft-limit
Block Soft Limit means this is the size in KB when a user will be warned about his disk usage nearing to quota limit, but he can still store files unless he reaches block hard-limit where he won't be allowed to write to the HDD until he frees some space.
The second number is Block-Hard Limit.
The third number is Inode soft limit. As said above we can limit the number of files, Soft Limit means he will be warned when he reaches this many number of files and won't be allowed to write when he reaches Inode Hard Limit which is the last field in the command.
To check that quotas have been implemented correctly (Disk Space):
# su -l user
$ dd if=/dev/zero bs=1k count=2048 of=bigfile
When you execute above commands then you will find a file of only 1024 KB as we set the quota of 1024 KB for user. Further if you try to add more files you will get error message.
To check no. of file type quotas:
# su -l user
$ COUNT=1; while [ $COUNT -lt 25 ]; do touch file$COUNT; let COUNT=$COUNT+1; done
Here, we have set a count of 24 files to be created. COUNT=1 sets a shell variable COUNT with value 1.
Then we use while loop to create fileN where N is replaced by the current number in COUNT which is then incremented by one after creation of fileN until COUNT variable reaches 24. Here you will receive warning message when you have created 20 files and get error when you try to create then 23rd file.
so, we have done with user quotas.
The process of setting up group quotas is very much similar except that you need to use grpquota instead of usrquota while remounting ; -g option for quotacheck and quotaon.
Then while assigning quotas to groups you need to give -g instead of -u.
All other syntax is same.
To make quotas permanent, you need to edit /etc/fstab.
Find your file system in /etc/fstab.
To find / partition in fstab, see the second field of fstab.
Some line will have ONLY and ONLY a / in the second field. This is the partition whose options in fstab need to be modified.
In my system, I have two hard disks, so I use LVM to merge them. So don't be astonished by the friendly device name.
My fstab entry is like this -
/dev/system/root / ext3 defaults 1 1
To enable user & group quotas permanently, this line should be changed so that it looks like this -
/dev/system/root / ext3 defaults,usrquota,grpquota 1 1
That's all!
Have a nice day. Comment if you get stuck somewhere or have suggestions.
Nilesh
iTech7 Site and Server Administrator
Recent comments
2 weeks 20 hours ago
2 weeks 4 days ago
3 weeks 18 hours ago
3 weeks 1 day ago
3 weeks 2 days ago
4 weeks 11 hours ago
4 weeks 12 hours ago
5 weeks 12 hours ago
5 weeks 1 day ago
5 weeks 4 days ago