LINUX-16 DISK
QUOTA (RHEL-6)
A way to limit the users to eat disk space.
Quota can be implemented on behalf of,
·
Block size: limit by block size
·
Inode no: limit by inode/no of files
Limit is also differentiated in,
·
Soft Limit: For warnings, it’s like a
barrier means if you jump the barrier you will be notified about the jumping incident.
·
Hard Limit: No way, you jumped the barrier
and we notify about your
daredevil act. Now we can allow you to cross
the limits.
Quota is File system based tool. So we need to enable it on FS first
to apply on users.
Quota can be implemented on users and groups.
How to check quota is implemented on FS or not…??
[root@localhost /]# quotacheck -vug /home
quotacheck: Mountpoint (or device) /home not found or has no quota
enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted
with quota option.
a: Check all quota-enabled file system
v: Verbose mode
u: Check for user disk quota
g: Check for group disk quota
No quota implemented on /home.
I made following modification in /etc/fstab at /home entry.
[root@localhost /]# grep home /etc/fstab
UUID=0e375c48-ff14-4570-9e8d-d0a5851175cb
/home ext4 defaults,usrquota,grpquota 1 2
[root@localhost /]# mount -o remount,rw /home
[root@localhost /]# quotacheck -vug /home
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/home] done
quotacheck: Cannot stat old user quota file: No such file or
directory
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Cannot stat old user quota file: No such file or
directory
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Checked 12 directories and 8 files
quotacheck: Cannot create new quotafile /home/aquota.user.new:
Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
quotacheck: Cannot create new quotafile /home/aquota.group.new:
Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
Well… quota is unable to create quota DB files by itself, let’s help
[root@localhost /]# touch /home/aquota.user
[root@localhost /]# touch /home/aquota.group
[root@localhost /]# chmod 600 /home/aquota.user
[root@localhost /]# chmod 600 /home/aquota.group
[root@localhost /]# ls -ltr /home
total 44
drwx------. 4 raman raman 4096 Jan 10 22:30 raman
drwx------. 2 root root 16384 Jan 10 22:45 lost+found
drwx------. 4 anurag anurag
4096 Jan 10 22:48 anurag
-rw-------. 1 root root 0 Jan 10 22:59 aquota.user
-rw-------. 1 root root 0 Jan 10 23:00 aquota.group
[root@localhost /]# quotacheck -avug
quotacheck: Cannot guess format from filename on /dev/sdb1. Please
specify format on commandline.
quotacheck: Cannot find filesystem to check or filesystem not mounted
with quota option.
[root@localhost /]# quotacheck -vug /home
quotacheck: Cannot guess format from filename on /dev/sdb1. Please
specify format on commandline.
quotacheck: Cannot find filesystem to check or filesystem not mounted
with quota option.
[root@localhost /]# quotacheck -F vfsv0 -avum
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: WARNING -
Quotafile /home/aquota.user was probably truncated. Cannot save quota
settings...
[root@localhost home]# quotacheck -cfmvF vfsv0 /home
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/home] done
quotacheck: Cannot stat old user quota file: No such file or
directory
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Checked 12 directories and 8 files
quotacheck: Cannot create new quotafile /home/aquota.user.new:
Permission denied
quotacheck: Cannot initialize IO on new quotafile: Permission denied
[root@localhost home]# rm aquota.user aquota.group
rm: remove regular empty file `aquota.user'? y
rm: remove regular empty file `aquota.group'? y
Culprit is SELINUX….
[root@localhost home]# setenforce 0
[root@localhost home]# quotacheck -cfmvF vfsv0 /home
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/home] done
quotacheck: Cannot stat old user quota file: No such file or
directory
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Checked 12 directories and 8 files
quotacheck: Old file not found.
quotacheck : Command.
c : create the aquota.user file.
f : Forces checking and writing of new quota files on
filesystems with
quotas enabled.
m : This flag forces checking of filesystem in read-write
mode if a remount fails Do this only when you are sure no
process will write to a filesystem while scanning.
v : Display verbose status information as the quota check
proceeds.
F : Format Name.
vfsv0 : quota version.
[root@localhost home]# quotacheck -avug
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/home] done
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Cannot stat old group quota file: No such file or
directory
quotacheck: Checked 12 directories and 9 files
quotacheck: Old file not found.
[root@localhost /]# mount -o remount,rw /home
[root@localhost /]# quotacheck -avug
quotacheck: Your kernel probably supports journaled quota but you are
not using it. Consider switching to journaled quota to avoid running quotacheck
after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/home] done
quotacheck: Checked 12 directories and 10 files
[root@localhost /]# ls -l /home
total 60
drwx------. 4 anurag anurag
4096 Jan 10 22:48 anurag
-rw-------. 1 root root 7168 Jan 10 23:14 aquota.group
-rw-------. 1 root root 7168 Jan 10 23:14 aquota.user
drwx------. 2 root root 16384 Jan 10 22:45 lost+found
drwx------. 4 raman raman 4096 Jan 10 22:30 raman
Now the QUOTA DB files are created.
Time to turn the quota ON…………..
[root@localhost /]# quotaon -v /home
/dev/sdb1 [/home]: group quotas turned on
/dev/sdb1 [/home]: user quotas turned on
[root@localhost ~]# mount |grep /home
/dev/sdb1 on /home type ext4 (rw,usrquota,grpquota)
Now time to assign quota to user/group………..
[root@localhost /]# edquota user1
Disk quotas for user
user1 (uid 502):
Filesystem blocks soft hard
inodes soft hard
/dev/sdb1 32 0 0 8 0
0
Field description………….
Blocks: 1k blocks
Inodes: Number of entries in directory file
Soft: Max number of
blocks/inodes user may have on partition before warning is issued and
grace persiod countdown begins.
If set to "0"
(zero) then no limit is enforced.
Hard: Max number of
blocks/inodes user may have on partition.
If set to "0"
(zero) then no limit is enforced.
[root@localhost /]# edquota user1
Disk quotas for user
user1 (uid 502):
Filesystem blocks soft hard
inodes soft hard
/dev/sdb1 0 20000
25000 0 0
0
Check the status of quota on particular FS…………………………
[root@localhost ~]# quotaon -p /home
group quota on /home (/dev/sdb1) is on
user quota on /home (/dev/sdb1) is on
How to set quota for particular user………………….
[root@localhost ~]# edquota raman
Disk quotas for user
raman (uid 501):
Filesystem blocks soft hard
inodes soft hard
/dev/sdb1
0 10000 15000 0
0 0
How to check the per user quota status on a FS…………………………..
[root@localhost ~]# repquota /home
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block
limits File limits
User used soft
hard grace used
soft hard grace
----------------------------------------------------------------------
root --
40 0 0 3 0
0
anurag -- 36
0 0 9 0
0
raman -- 32
10000 15000 8 0
0
user1 -- 32
20000 25000 8 0
0
[raman@localhost ~]$ dd if=/dev/zero of=f1 bs=1024
count=9000
9000+0 records in
9000+0 records out
9216000 bytes (9.2 MB) copied, 0.116678 s, 79.0 MB/s
[raman@localhost ~]$ dd if=/dev/zero of=f2 bs=1024
count=3000
sdb1: warning, user block quota exceeded. çSoft Limit Warning
3000+0 records in
3000+0 records out
3072000 bytes (3.1 MB) copied, 0.0555907 s, 55.3 MB/s
[raman@localhost ~]$ ls -lh
total 12M
-rw-rw-r--. 1 raman raman 8.8M Jan 11 22:19 f1
-rw-rw-r--. 1 raman raman 3.0M Jan 11 22:20 f2
[raman@localhost ~]$ dd if=/dev/zero of=f3 bs=1024
count=6000
sdb1: write failed, user block limit reached.
dd: writing `f3': Disk quota exceeded çHard limit warning
2969+0 records in
2968+0 records out
3039232 bytes (3.0 MB) copied, 0.065144 s, 46.7 MB/s
[raman@localhost ~]$ ls -lh
total 15M
-rw-rw-r--. 1 raman raman 8.8M Jan 11 22:19 f1
-rw-rw-r--. 1 raman raman 3.0M Jan 11 22:20 f2
-rw-rw-r--. 1 raman raman 2.9M Jan 11 22:20 f3 çcheck the size
[raman@localhost ~]$
Checking quota report…………………………………………..
[root@localhost ~]# quota -u raman
Disk quotas for user raman (uid 501):
Filesystem blocks
quota limit grace
files quota limit
grace
/dev/sdb1 15000*
10000 15000 6days
12 0 0
[root@localhost ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block
limits File limits
User used soft
hard grace used
soft hard grace
----------------------------------------------------------------------
root -- 40
0 0 3 0
0
anurag -- 36
0 0 9 0
0
raman +- 15000
10000 15000 6days
12 0 0
user1 -- 32
20000 25000 8 0
0
Grace Period…………………………………..
[root@localhost ~]# edquota -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sdb1 7days 7days
[root@localhost ~]# edquota -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sdb1 2days 7days
[root@localhost ~]# quota -u raman
Disk quotas for
user raman (uid 501):
Filesystem
blocks quota limit
grace files quota
limit grace
/dev/sdb1 15000*
10000 15000 6days
12 0 0
[root@localhost ~]# edquota -T raman
Times to enforce softlimit for user raman (uid 501):
Time units may be: days, hours, minutes, or seconds
Filesystem block grace inode grace
/dev/sdb1 2days unset
INTELLIGENT MOVE…………REALLY……??
I wanted to implement the grace period to be effective right now.
[root@localhost ~]# quotacheck -cugm /home
quotacheck: Quota for users is enabled on mountpoint /home so
quotacheck might damage the file.
Please turn quotas off or use -f to force checking.
Flag Meaning………….
-c Performs a new scan.
-v Performs a verbose scan.
-u Scans for user quotas.
-g Scans for group quotas.
-m Remounts the scanned filesystem.
Then I used “-f”
[root@localhost ~]# quotacheck -cugmf /home
[root@localhost ~]# quota -u raman
Disk quotas for user raman (uid 501): none è???????????
[root@localhost ~]# repquota -a
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block
limits File limits
User used soft
hard grace used
soft hard grace
----------------------------------------------------------------------
root -- 40
0 0 3 0
0
anurag -- 36
0 0 9 0
0
raman -- 15000
0 0 12 0
0
user1 -- 32
0 0 8 0
0
ALL GONE……………………..
Read carefully the warning msg given in o/p of “quotacheck -cugm
/home”
TURN OFF QUOTA……………
Remove the quota related entries from /etc/fstab.
[root@localhost ~]# quotaoff -auvg
/dev/sdb1 [/home]: group quotas turned off
/dev/sdb1 [/home]: user quotas turned off
No comments:
Post a Comment