Managing Disk Usage with Quotas

Disk Quotas: This feature of Linux allows the system administrator to allocate a maximum amount of disk space a user or group may use.You may eventually need to restrict the amount of disk space used on each partition by each user or group of users as your disk drives become filled with data. The disk quota feature of RedHat/Fedora Linux enables you to do this

Edit your /etc/fstab file - You'll need to add the quota option to the /etc/fstab file to let it know that you are enabling user quotas in your file system.
[root@localhost usertest]# mkdir /usertest

[root@localhost usertest]# vim /etc/fstab

/dev/hda8 /usertest ext3 defaults,quota 0 0

Remount your file system - Once you finish editing your /etc/fstab file, you have to remount your filesystem as follows :
[root@localhost usertest]# mount -o remount,quota /usertest

Use mount command for show currently mounted disk and directory :
[root@localhost usertest]# mount
/dev/hda6 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hda8 on /usertest type ext3 (rw,quota,quota)

For using quota check command we open the the database,quotacheck - scan a filesystem for disk usage, create, check and repair quota files [root@localhost usertest]# quotacheck -cM /usertest

Quotaon announces to the system that disk quotas should be enabled on one or more filesystems.

[root@localhost usertest]# quotaon /usertest

The edquota command creates and edits quotas. It creates a temporary file that contains each user's and group's current disk quotas.
[root@localhost usertest]# edquota probal
Disk quotas for user probal (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/hda8 7 70 110 7 0 0

The repquota command prints a summary of quotas and disk usage for a file system specified by the FileSystem parameter.
[root@localhost usertest]# repquota -v /usertest/*** Report for user quotas on device /dev/hda8
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 10544 0 0 4 0 0
probal -- 7 70 110 7 0 0
saiful -- 7 0 0 7 0 0

Statistics:
Total blocks: 7
Data blocks: 1
Entries: 3
Used average: 3.000000

For check quota for specific user probal we now login as probal

[root@localhost usertest]# su - probal

[probal@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=110
hda8: warning, user block quota exceeded.
hda8: write failed, user block limit reached.dd: writing `file': Disk quota exceeded
103+0 records in
102+0 records out

[probal@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=50
50+0 records in
50+0 records out51200 bytes (51 kB) copied, 0.000514527 seconds, 99.5 MB/s

[probal@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=6060+0 records in
60+0 records out
61440 bytes (61 kB) copied, 0.000604518 seconds, 102 MB/s

[probal@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=65
hda8: warning, user block quota exceeded.
65+0 records in
65+0 records out66560 bytes (67 kB) copied, 0.000754492 seconds, 88.2 MB/s

[root@localhost ~]# edquota saiful
Disk quotas for user saiful (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/hda8 7 50 80 7 0 0
~
[root@localhost ~]# repquota -v /usertest/*** Report for user quotas on device /dev/hda8
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 10544 0 0 4 0 0
probal +- 73 70 110 6days 8 0 0
saiful -- 7 50 80 7 0 0
debashish -- 7 0 0 7 0 0

Statistics:
Total blocks: 7
Data blocks: 1
Entries: 4
Used average: 4.000000

[saiful@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=40
40+0 records in
40+0 records out40960 bytes (41 kB) copied, 0.000418989 seconds, 97.8 MB/s

[saiful@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=60
hda8: warning, user block quota exceeded.
60+0 records in
60+0 records out61440 bytes (61 kB) copied, 0.00072801 seconds, 84.4 MB/s

[saiful@localhost ~]$ dd if=/dev/zero of=file bs=1024 count=80
hda8: warning, user block quota exceeded.
hda8: write failed, user block limit reached.
dd: writing `file': Disk quota exceeded73+0 records in
72+0 records out
73728 bytes (74 kB) copied, 0.0014104 seconds, 52.3 MB/s
=========================================================
[root@localhost named]mount -o (wo) remount /home
[root@localhost named]edquota -p parents username newusername (to do similar like previous user)
[root@localhost named]quotaon /home/ (to active the service)
[root@localhost named]quotaoff /home/ (to deactivate the service)
[root@localhost named]repquota /home (to see quota report)
[root@localhost named]requota -a ( to see all quotas)
[root@localhost named]edquota username/groupname
limitations for quota
soft hard inodes soft hard
4000 6000 80 100
(kb) (kb) no: of file max no: of file
warning stop warning stop
[root@localhost named]setquota -u username soft hard soft hard /home
( to provide quota by a single command )
[root@localhost named]edquota -u username soft hard soft hard /home
( to modify quota by a single command)
-------------to check--------
after log in as a quota user
[root@localhost named]dd if=/dev/zero of=bigfile bs=1m count=4