Disk Quota for linux System Management

Source: Internet
Author: User
Article Title: Disk Quota for linux System Management. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

A. the disk quota function limits the use of disk space by ordinary users, so as not to affect the normal use of others due to personal waste;

B. Kernel support is required;

C. This function is only currently supported by the Ext2/Ext3 file system;

D. User Program quota software package is required.
Disk Quota configuration process

1) mount a partition using the usrquota and kgquota options to activate Kernel support (only available on partitions)

2) method: # mount? O usrquota, maid/dev/sdb1/mnt/d1

Or mount? O remount, usrquota, kgquota/(because the root directory has been mounted, you can re-mount it)

3), init 1 (entering the single-user environment for configuration)
4), quotacheck? Cvuga checks and creates database files with disk quotas (storage location: Under the root directory of each partition)

-C: create ;? V: More detailed description ;? U: user ;? G: group;-a: all

5), edquota? U Allocate disk space and number of nodes to a specified user

6) The quota command can be used to view the user's quota usage.

For example, [root @ localhost root] # ls/mnt

Cdrom floppy

[Root @ localhost root] # mkfs. ext3/dev/sdb1/mnt/sd1/
Mke2fs 1.32 (09-Nov-2002)

Mkfs. ext3: bad blocks count-/mnt/sd1/

[Root @ localhost root] # mkfs. ext3-f/dev/sdb1/mnt/sd1/

[Root @ localhost root] # fdisk-l
Disk/dev/sda: 5368 MB, 5368709120 bytes

255 heads, 63 sectors/track, 652 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sda1*1 652 5237158 + 83 Linux

Disk/dev/sdb: 4294 MB, 4294967296 bytes

255 heads, 63 sectors/track, 522 cylinders

Units = cylinders of 16065*512 = 8225280 bytes

Device Boot Start End Blocks Id System

/Dev/sdb1 250 522 2192872 + 83 Linux

[Root @ localhost root] # mkfs. ext3/dev/sdb1
Mke2fs 1.32 (09-Nov-2002)
Filesystem label =

OS type: Linux

Block size = 4096 (log = 2)

Fragment size = 4096 (log = 2)

274176 inodes, 548218 blocks

27410 blocks (5.00%) reserved for the super user

First data block = 0
17 block groups

32768 blocks per group, 32768 fragments per group

16128 inodes per group

Superblock backups stored on blocks:

32768,983 04, 163840,229 376, 294912

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or

180 days, whichever comes first. Use tune2fs-c or-I to override.

[Root @ localhost root] # mount/dev/sdb1/mnt/sd1-o usrquota, kgquota
[Root @ localhost root] # mount

/Dev/sda1 on/type ext3 (rw)

None on/proc type proc (rw)
Usbdevfs on/proc/bus/usb type usbdevfs (rw)

None on/dev/pts type devpts (rw, gid = 5, mode = 620)
None on/dev/shm type tmpfs (rw)

/Dev/sdb1 on/mnt/sd1 type ext3 (rw, usrquota, kgquota)

[Root @ localhost root] # more/etc/mtab

/Dev/sda1/ext3 rw 0 0

None/proc rw 0 0

Usbdevfs/proc/bus/usb usbdevfs rw 0 0

None/dev/pts devpts rw, gid = 5, mode = 620 0 0

None/dev/shm tmpfs rw 0 0

/Dev/sdb1/mnt/sd1 ext3 rw, usrquota, kgquota 0 0

[Root @ localhost root] # quotacheck? Cvuga <-------

Quotacheck: Scanning/dev/sdb1 [/mnt/sd1] done
Quotacheck: Checked 2 directories and 0 files

[Root @ localhost root] # ls/mnt/sd1/

Aquota. group aquota. user lost + found

The aquota. group and aquota. user data files are used to allocate group and user quotas.

[Root @ localhost root] # quotaon, reboot, or quotaon/dev/sdb1

[Root @ localhost root] # edquota-u redhat

Disk quotas for user redhat (uid 502 ):

Filesystem blocks soft hard inodes soft hard

/Dev/sdb1 125 10 0 80 0 10

Note: blocks indicates the number of blocks; inodes indicates the number of nodes or the number of files created;
Soft: soft limit. It can exceed this value, but there is a limit on the number of days;

Hard: hard limit, which is a value that cannot be exceeded at any time and is never possible.

[Root @ localhost root] # \ ls/mnt/sd1

Aquota. group aquota. user lost + found

[Root @ localhost root] # mkdir/mnt/sd1/redhat

[Root @ localhost root] # chown redhat/mnt/sd1/redhat/

[Root @ localhost root] # su-redhat

[Redhat @ localhost redhat] $ pwd

/Home/redhat

[Redhat @ localhost redhat] $ cd/mnt/sd1/redhat/

[Redhat @ localhost redhat] $ pwd
/Mnt/sd1/redhat

[Redhat @ localhost redhat] $ quota

Disk quotas for user redhat (uid 502 ):

Filesystem blocks quota limit grace files quota limit grace

/Dev/sdb1 4 10 0 1 0 9

[Redhat @ localhost redhat] $ ls-lh

Total 8.0 K

Drwxrwxr-x 2 redhat 4.0 K Mar 12 dir
Drwxrwxr-x 2 redhat 4.0 K Mar 12 dir1

[Redhat @ localhost redhat] $ ls-ld

Drwxr-xr-x 4 redhat root 4096 Mar 12.

[Redhat @ localhost redhat] $ dd if =/dev/zero of = file1 bs = 1 k count = 1024

1024 + 0 records in

1024 + 0 records out

[Redhat @ localhost redhat] $ quota-u redhat

Disk quotas for user redhat (uid 502 ):

Filesystem blocks quota limit grace files quota limit grace

/Dev/sdb1 1040*10 0 6 days 4 0 9
[Redhat @ localhost redhat] $ touch file1

[Redhat @ localhost redhat] $ touch file2

[Redhat @ localhost redhat] $ touch file3

[Redhat @ localhost redhat] $ touch file4

[Redhat @ localhost redhat] $ touch file5

[Redhat @ localhost redhat] $ ls

File1 file2 file3 file4 file5
[Redhat @ localhost redhat] $ quota-u redhat

Disk quotas for user redhat (uid 502 ):

Filesystem blocks quota limit grace files quota limit grace

/Dev/sdb1 1032*10 0 6 days 6 0 9
[Redhat @ localhost redhat] $ touch file6

[Redhat @ localhost redhat] $ touch file7

[Redhat @ localhost redhat] $ touch file8

[Redhat @ localhost redhat] $ touch file9

Sd (8, 17): write failed, user file limit reached.

Touch: creating 'file9': Disk quota exceeded

[Redhat @ localhost redhat] $ touch file10

Touch: creating 'file10': Disk quota exceeded
[Redhat @ localhost redhat] $ quota-u redhat

Disk quotas for user redhat (uid 502 ):

Filesystem blocks quota limit grace files quota limit grace

/Dev/sdb1 1032*10 0 6 days 9*0 9

[Redhat @ localhost redhat] $ cat/etc/fstab

LABEL = // ext3 defaults 1 1

None/dev/pts devpts gid = 5, mode = 620 0 0

None/proc defaults 0 0

None/dev/shm tmpfs defaults 0 0

/Dev/cdrom/mnt/cdrom udf, iso9660 noauto, owner, kudzu, ro 0 0
/Dev/fd0/mnt/floppy auto noauto, owner, kudzu 0 0

/Dev/sdb5/mnt/sdb5 ext3 defaults 0 0

[Root @ localhost root] # repquota-

* ** Report for user quotas on device/dev/sdb1

Block grace time: 7 days; Inode grace time: 7 days

Block limits File limits
User used soft hard grace

----------------------------------------------------------------------

Root -- 20 0 0 2 0 0

Redhat +-1032 10 0 7 days 9 0 9

# Quotaoff/mnt/sdb1

# Edquota? U redhat
If you want to use the quota permanently, You can manually edit/etc/fstab to add:

/Dev/sdb1/mnt/sb1 ext3 defaults, usrquota, kgquota 0 0

Save and exit!

How to cancel Disk Quota:

1) Use the quotaoff command? A. Disable the quota file 2), editable/etc/fstab file 3), and two database files aquota. usr and aquota. group under the/mnt/sd1 directory.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.