Today i am going to show you how to implement quota in LINUX. The quota is implemented for the two: users and groups.
I - IMPLEMENTING USER QUOTA
Steps to go:-
First of select a device where you want to set quota, i have created a device /dev/sda8 of 500MB for example:
1) Now, format the partition.
# mkfs.ext3 /dev/sda8
2) Create a mount point for the newly created device /dev/sda8
# mkdir /data
3) Now, checking mounting the device under /data. Can be done in 2 ways as we already discussed in previous posts. Mounting manually or making an entry in the file /etc/fstab for automounting.
# mount -t ext3 /dev/sda8 /data
or make a an entry in the file /etc/fstab and do # mount -a
4) Now, finally start implementing quota for users. Edit the file "/etc/fstab" and make a new entry or edit the existing entry(if you made an entry for mounting device /dev/sda8) as follows:
# vim /etc/fstab
/dev/sda8 /data defaults,usrquota 1 2
:wq
save and exit
5) Now, remount the device as:
# mount -o remount /data
# ls /data (just to check whether re-mounted correctly or not)
6) Now, check for existing user quota in the "/data".
# quotacheck -cu /data
7) Now, turning quota on, in the directory "/data"
# quotaon -vu /home
8) Setting quota now for a user "aman".
# setquota -u aman 100 200 0 0 /home
Here, 100 is the soft limit and 200 hard limit. The others 0s are the inode softlimit and inode hardlimit. You should read more about these limit by googling them.
9) Now, checking quota reports and see all existing quotas for the users.
# repquota -vu /data
NOTE: we have used the switch "-u" to represent that we are checking the for user quota.
10) DONE.....
Now, its time to check quota from the user for which quota is turned on.
Now, change to the other user "aman" as:
# su - aman
Now, run the following commands to check the quota:
# dd if=/dev/zero of=/data/quota1 bs=1k count=100
# dd if=/dev/zero of=/data/quota2 bs=1k count=150
NOTE: The first command will a warning but will make the file "quota1" in "/data" because soft limit is 100. But the second command will not make the file exceeding the hard limit 200.
II - IMPLEMENTING GROUP QUOTA
Group Quota is mostly similar to the User Quota. The thing is that its implemented for the users of a particular groups rather an individual user. For example: if we have some users as aman, gaurav, virender, pandey etc. belonging to a group named as "garv". Then, the quota we will set on this group, will be common for all these users belonging to the group "garv".
NOTE: I am using the same device for implementing group quota which i used for "user quota" i.e. /dev/sda8 or /data.
Steps to go:
1) Edit the file "/etc/fstab" and edit the line containing "/data":
# vim /etc/fstab
/dev/sda8 /data defaults,usrquota,grpquota 1 2
:wq
save and exit
NOTE: That we have just added a new keyword "grpquota" to setup the group quota on the particular device.
2) Now, Remount the device once again.
# mount -o remount /data
# ls /data (just to check whether device successfully remounted or not)
3) Check for existing quota in "/data":
# quotacheck -cg /data
4) Turning on the group quota in "/data":
# quotaon -vg /data
5) Setting up the group quota for the group "garv":
# setquota -g garv 100 200 0 0 /data
NOTE: The limits are same as they were in user quota above. 100 is the soft limit and 200 is hard limit Rest 0s are inode softlimit and hardlimit.
6) Checking quota reports for groups:
# repquota -vg /data
NOTE: Here we used the switch "-g" to represent that we are checking for group quota not user quota.
7) DONE.......:)
Now, again we should check the quota from the user of the group for which quotas are being implemented. So switch to any user belonging to the group "garv".
# su - aman
or
# su - gaurav
Now, run the same commands as we did in user quota with the "dd"(disk dump) utility.
# dd if=/dev/zero of=/data/quota1 bs=1k count=100
# dd if=/dev/zero of=/data/quota2 bs=1k count=150
Enjoy....Implementing Quotas on your users.......:)
No comments:
Post a Comment