the commands used for xfs are different. this is only valid for ext3/ext4.

preparation: you should move your /home to a separate partition.

Warning! You will need to have “physical” access to the server’s console in order to perform these steps – remote login via ssh won’t be enough (init 1 – no ssh in rescue mode)

lets go

will configure a disk-quota for user “user” on ext3 partition /dev/sdb1 mounted as /home

[cc lang=”bash” escaped=”true” width=”600″]

su; # become root
apt-get update; # update repo
apt-get install quota quotatool; # install software

vim /etc/fstab; # open up mount config file
/dev/sdb1 /home ext3 quota,usrquota,relatime,errors=remount-ro 0 1
\_add this \_and that
init 1; # single-user, maintenance mode, all networking and ssh will be stopped
[/cc]

type in root password to get a promt/shell/terminal:

this sub-window can be scrolled!

[cc lang=”bash” escaped=”true” width=”600″]

umount /home; # try to unmount home
“target is busy”
lsof|grep home; # check processes using /home
bash 1305
kill -9 1305; # kill all processes using /home

umount /home; # try to unmount home, again, should work now
mount -a; # remount according to fstab with quota enabled

mount |grep home; # you now should see
/dev/sdb1 on /home type ext3 (rw,relatime,quota,usrquota,errors=remount-ro,data=ordered)
\______\___partition was mounted with quota-feature enabled
quotacheck -aug; # generate /home/aquota.user /home/aquota.group (if you want group-wise-quota, also needs to be put into fstab)

/etc/init.d/quota restart; # restart quota service

blockdev –getbsz /dev/sdb1; # view blocksize of partition
4096 (ext3 default size 4KByte)

edquota -u user; # set quota for user “user”

Disk quotas for user user (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 1548 100.000 120.000 159 0 0
\_ in use \ by user right now
\_soft limit / hard limit 120.000 Blocks ~120 MByte

edquota -p user `awk -F: ‘$3 > 1000 {print $1}’ /etc/passwd`; # if you want the same quota settings for all other users with UID larger than 1000

edquota -t; # change grace period

quotaon -a; # switch quota on – whatever this does

quotacheck -avugm; # whatever this does 😀
[/cc]

view quotas:

[cc lang=”bash” escaped=”true” width=”600″]
root@debian:~# 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 — 56 0 0 9 0 0
user — 1536 100000 120000 158 0 0
maria — 20 100000 120000 5 0 0

# reboot, test and be happy! 😀

[/cc]

test quota

[cc lang=”bash” escaped=”true” width=”600″]

# as non-root user “user” try to exhaust your quota by generating a 1GByte test file
user@debian:~$ dd if=/dev/urandom of=1GBybe.testfile bs=64M count=16 iflag=fullblock; # generate 1GByte test file that

contains random data
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: error writing ‘1GBybe.testfile’: Disk quota exceeded
2+0 records in
1+0 records out
121184256 bytes (121 MB) copied, 11.9736 s, 10.1 MB/s

# the user itself can check – if a quota is set – and status of his/her quota
user@debian:~$ quota
Disk quotas for user user (uid 1000):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 120000* 100000 120000 7days 159 0 0
\___ hard limit of quota reached

user@debian:~$ rm 1GBybe.testfile; # remove test file

user@debian:~$ quota
Disk quotas for user user (uid 1000):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 1536 100000 120000 157 0 0
\______\___ 98464 blocks of space left, before soft-quota is reached

dd if=/dev/urandom of=64MByte.testfile bs=64M count=1 iflag=fullblock; # generate 1GByte test file that

user@debian:~$ stat 64MByte.testfile
File: ‘64MByte.testfile’
Size: 67108864 Blocks: 131208 IO Block: 4096 regular file
Device: 811h/2065d Inode: 262207 Links: 1

# 67108864/131208 = on average 511Bytes per 1x4096Byte-Block is used. what a waste 😀

[/cc]

YEAH! WORKS! 🙂

soft-quota and hard-quota

soft-quota is a soft-limit – user will be warned that he/she is over quota – but can continue writing to disk until hard-limit is reached.

grace time of 7 days means – if the user stays over soft-quota for 7 days – user’s soft limit will become user’s hard limit.

it is possible that without Administrator – user can not login anymore. (no space left to write to)

manpages:

quotacheck.man

quotaoff.man

quotaon.man

repquota.man

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin