Disk Quota
Disk Quotas are used to limit a user's or a group of users' ability to consume disk space. This prevents a small group of users from monopolizing disk capacity and potentially interfering with other users or the entire system.Disk quotas are commonly used by ISPs, by Web hosting companies, on FTP sites, and on corporate file servers to ensure continued availability of their systems. Using disk quota administrator can restrict user in two ways :-
1. Restricting user or group by creating files in a specific location.
2. Restricting user or group by the disk space in a specific location.
Disk Quota Terms
1. Soft Link = Disk space a user can use
2. Hard Link = Absolute limit a user can use
3. Grace Periods = Time duration till user can use hard limit space
4. 1 inode = 1KB
5. dd = used to create a blank file of specific size
6. required RPM = quata-*
7. /etc/fstab option = userquota, grpquota
8. Quota files = aquota.user. aquota.group
9. Necessary Commands = mount, quotarun, quotacheck, edquota, quotaoff, quotaon
1. To set quota on user.
[root@server1 ~]#useradd usr1
[root@server1~]# passwd usr1
Changing password for user username.
New password: * * * * *
BAD PASSWORD: it is based on a directory word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication token updated successfully.
[root@server1 ~]#vi /etc/fstab
UUID=2f3r7yf8-bd9h-56tf-h8gt-45df12g74fdv /home ext4 defaults,usrquota 1 2
:wq!
[root@server1 ~]#mount
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7on /home type ext4 (rw)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /example type ext4 (rw)
[root@server1 ~]#mount -o remount /home
[root@server1 ~]#mount
dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7on /home type ext4 (rw,usrquota)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /example type ext4 (rw)
[root@server1 ~]#touch /home/aquota.user
[root@server1 ~]#quotacheck -vc /home
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 0 0 8 0 0 0
usr2 -- 32 0 0 8 0 0 0
usr3 -- 32 0 0 8 0 0 0
[root@server1 ~]#quotacheck -vc /home
[root@server1 ~]#quotaon -v /home
[root@server1 ~]#setquota –u usr1 256 512 0 0 /home
Username Mini Maxi Mini Maxi Mount Point
Block Block File File to set Quota
Limit Limit Limit Limit
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 256 512 8 0 0 0
usr2 -- 32 0 0 8 0 0 0
usr3 -- 32 0 0 8 0 0 0
[root@server1 ~]#
Now login with that user3 from another console.
Server1 Login : usr1
Password: ******
[use3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=100
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.000875702 s, 117 MB/s
[use3@server1 ~]$ll
-rw-rw-r--. 1 usr1 usr1 102400 Jun 20 07:05 file1
[use3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=300
300+0 records in
300+0 records out
307200 bytes (307 kB) copied, 0.0142128 s, 21.6 MB/s
[use3@server1 ~]$ll
-rw-rw-r--. 1 usr1 usr1 307200 Jun 20 07:05 file1
[use3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=500
Dd: writing ‘file1’ : Disk quota exceeded
477+0 records in
476+0 records out
487424 bytes (487 kB) copied, 0.0057277 s, 85.1 MB/s
[use3@server1 ~]$ll
-rw-rw-r--. 1 usr1 usr1 487424 Jun 20 07:05 file1
[use3@server1 ~]$
CTRL+D ……..to log out from usr1
Server1 Login :root
Password: ******
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 256 512 6days 0 0 0
usr2 -- 32 0 0 8 0 0 0
usr3 -- 32 0 0 8 0 0 0
2. To set same quota limit on multiple user.
[root@server1 ~]#useradd usr2
[root@server1~]# passwd usr2
Changing password for user username.
New password: * * * * *
BAD PASSWORD: it is based on a directory word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication token updated successfully.
[root@server1 ~]#useradd usr3
[root@server1~]# passwd usr3
Changing password for user username.
New password: * * * * *
BAD PASSWORD: it is based on a directory word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication token updated successfully.
[root@server1 ~]#vi /etc/fstab
UUID=2f3r7yf8-bd9h-56tf-h8gt-45df12g74fdv /home ext4 defaults,usrquota 1 2
:wq!
[root@server1 ~]#mount
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7on /home type ext4 (rw)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /example type ext4 (rw)
[root@server1 ~]#mount -o remount /home
[root@server1 ~]#mount
dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7on /home type ext4 (rw,usrquota)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /example type ext4 (rw)
[root@server1 ~]#touch /home/aquota.user
[root@server1 ~]#quotacheck -vc home
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 0 0 8 0 0 0
usr2 -- 32 0 0 8 0 0 0
usr3 -- 32 0 0 8 0 0 0
[root@server1 ~]#quotacheck -vc /home
[root@server1 ~]#quotaon -v /home
/dev/sda7 [/home]: user quotas turned on
[root@server1 ~]#setquota –u usr2 256 512 0 0 /home
Username Mini Maxi Mini Maxi Mount Point
Block Block File File to set Quota
Limit Limit Limit Limit
[root@server1 ~]#edquota –p usr2 usr3
Username another
to whome userto
quota is set same
set quota as user2
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 0 0 8 0 0 0
usr2 -- 32 256 512 8 0 0 0
usr3 -- 32 256 512 8 0 0 0
[root@server1 ~]#
Now login with that usr2 from another console.
Server1 Login : usr2
Password: ******
[usr2@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=100
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.000875702 s, 117 MB/s
[usr2@server1 ~]$ll
-rw-rw-r--. 1 usr2 usr2 102400 Jun 20 07:05 file1
[usr2@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=300
300+0 records in
300+0 records out
307200 bytes (307 kB) copied, 0.0142128 s, 21.6 MB/s
[usr2@server1 ~]$ll
-rw-rw-r--. 1 usr2 usr2 307200 Jun 20 07:05 file1
[usr2@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=500 ………
Dd: writing ‘file1’ : Disk quota exceeded
477+0 records in
476+0 records out
487424 bytes (487 kB) copied, 0.0057277 s, 85.1 MB/s
[usr2@server1 ~]$ll
-rw-rw-r--. 1 usr2 usr2 487424 Jun 20 07:05 file1
[use2@server1 ~]$
CTRL+D ……..to log out from usr2
Now login with that usr3.
Server1 Login : usr3
Password: ******
[usr3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=100
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.000875702 s, 117 MB/s
[usr3@server1 ~]$ll
-rw-rw-r--. 1 usr3 usr3 102400 Jun 20 07:05 file1
[use3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=300
300+0 records in
300+0 records out
307200 bytes (307 kB) copied, 0.0142128 s, 21.6 MB/s
[usr3@server1 ~]$ll
-rw-rw-r--. 1 usr3 usr3 307200 Jun 20 07:05 file1
[usr3@server1 ~]$dd if=/dev/zero of=file1 bs=1K count=500
Dd: writing ‘file1’ : Disk quota exceeded
477+0 records in
476+0 records out
487424 bytes (487 kB) copied, 0.0057277 s, 85.1 MB/s
[usr3@server1 ~]$ll
-rw-rw-r--. 1 usr3 usr3 487424 Jun 20 07:05 file1
[usr3@server1 ~]$
CTRL+D ……..to log out from usr3
Now login with root.
Server1 Login : root
Password: ******
[root@server1 ~]#repquota -a
Block Limits File Limits
User used soft hard grace used soft hard grace
root -- 24 0 0 3 0 0 0
cms -- 36 0 0 9 0 0 0
usr1 -- 32 0 0 8 0 0 0
usr2 -- 32 256 512 6days 0 0 0
usr3 -- 32 256 512 6days 0 0 0