Disk Quota settings and usage

Source: Internet
Author: User

Disk Quota settings and usage

When the disk space in the Linux Root partition is exhausted, the Linux system will not be able to create new files, resulting in service program crash, system failure, and other failures. To avoid this problem, can I set the disk quota function to limit the disk space and file quantity used by users in the specified file system to prevent users from occupying a large amount of disk space, so that our system storage space can be used stably.

I. Disk Quota Glossary:
The disk quota is an object-type hard disk partition, And the Linux kernel must support the disk quota technology.

The disk quota is only valid for general users and does not work for administrators.
Soft limit: soft: the minimum limit capacity, which can be exceeded, but there is a warning that the excess part will be saved to the grace period expiration.
Hard limit: hard: cannot exceed the limit.
Grace period: when the user's space exceeds the soft limit but does not reach the hard limit, the data that exceeds the limit must be lowered to the soft limit before the expiration time, (the default value is 7 days). When the grace period expires, the system automatically clears the data that exceeds the limit.

1. Check whether the quota program has been installed in our system.

Root@bkjia.com ~ # Rpm-q quota
Quota-4.01-11.el7.x86_64
Root@bkjia.com ~ # Rpm-ql quota
/Usr/bin/quota
/Usr/bin/quotasync
/Usr/sbin/convertquota
/Usr/sbin/edquota
/Usr/sbin/quot
/Usr/sbin/quotacheck
/Usr/sbin/quotaoff
/Usr/sbin/quotaon
/Usr/sbin/quotastats
/Usr/sbin/repquota
/Usr/sbin/rpc. rquotad
/Usr/sbin/setquota
/Usr/sbin/xqmstats
/Usr/share/doc/quota-4.01
/Usr/share/doc/quota-4.01/Changelog
/Usr/share/man/man1/quota.1.gz
/Usr/share/man/man1/quotasync.1.gz
/Usr/share/man/man8/convertquota.8.gz
/Usr/share/man/man8/edquota.8.gz
/Usr/share/man/man8/quot.8.gz
/Usr/share/man/man8/quotacheck.8.gz
/Usr/share/man/man8/quotaoff.8.gz
/Usr/share/man/man8/quotaon.8.gz
/Usr/share/man/man8/quotastats.8.gz
/Usr/share/man/man8/repquota.8.gz
/Usr/share/man/man8/rpc.rquotad.8.gz
/Usr/share/man/man8/setquota.8.gz
/Usr/share/man/man8/xqmstats.8.gz

2. Mount the file system in a way that supports the quota Function
Root@bkjia.com ~ # Mount/dev/sdd1/quotadir/### mount my partition to a directory for ease of use
Root@bkjia.com ~ # Chmod 777/quotadir/### change the directory permission so that we can write the test code later.
Root@bkjia.com ~ #
Root@bkjia.com ~ # Mount-o remount, usrquota, kgquota/dev/sdd1/quotadir/
# This is a temporary mount. You can also use the automatic mounting method at startup:

Root@bkjia.com ~ # Vim/etc/fstab
/Dev/sdd1/quotadir ext4 defaults, usrquota, kgquota 0 0

Root@bkjia.com ~ # Mount-
Root@bkjia.com ~ # Mount

Tmpfs on/run/user/0 type tmpfs (rw, nosuid, nodev, relatime, seclabel, size = 100136 k, mode = 700)
/Dev/mapper/vg0-lv0 on/tmp/backup type ext4 (rw, relatime, seclabel, data = ordered)
/Dev/sdd1 on/quotadir type ext4 (rw, relatime, seclabel, quota, usrquota, kgquota, data = ordered) # You can see that the mounting is successful.

3. Create a disk quota configuration file
Quotacheck:
-V: displays the scanning process.
-U: Creates aquota. user for user scanning.

-G: creates an aquota. group for the scan group.

-C: Create a new quota File

-A: scan all partitions.

Root@bkjia.com ~ # Quotacheck-ugc/dev/sdd1
Root@bkjia.com ~ # Ls-l/quotadir/
Total 32
-Rw -------. 1 root 6144 Jun 4 18:25 aquota. group
-Rw -------. 1 root 6144 Jun 4 18:25 aquota. user
Drwx ------. 2 root 16384 Jun 418:11 lost + found
# The Directory mounted to the partition will automatically generate two configuration files.

Iv. Restrictions on disk cooperation:
Edquota
-U User: specify a user to set a quota
-T: Change the grace period

Here I need to create a common user for testing.
Root@bkjia.com ~ # Useradd ma
Root@bkjia.com ~ # Passwd ma
Changing password for user ma.
New password:
Bad password: The password is shorter than 8 characters
Retype new password:
Passwd: all authentication tokens updated successfully.

12345 [root@bkjia.com ~] # Edquota-u ma ### set the user's ma quota
Disk quotas for user ma (uid 1001 ):
Filesystem blocks soft hard inodes soft hard
/Dev/sdd1 0 10 20 0 3 5
~

5. Enable the quota Function
Root@bkjia.com ~ # Quotaon/quotadir/
Okay. Let me test it.

Ma@bkjia.com ~ $ Dd if =/dev/zero of =/quotadir/test1 bs = 1 k count = 8
8 + 0 records in
8 + 0 records out
8192 bytes (8.2 kB) copied, 0.000230902 s, 35.5 MB/s
#8 K data is written normally, and no error is reported


Ma@bkjia.com ~ $ Dd if =/dev/zero of =/quotadir/test1 bs = 1 k count = 10
Sdd1: warning, user block quota exceeded.
10 + 0 records in
10 + 0 records out
10240 bytes (10 kB) copied, 0.0009096 s, 11.3 MB/s

[Ma@bkjia.com quotadir] $ ll-h/quotadir/
Total 44 K
-Rw -------. 1 root 7.0 K Jun 4 aquota. group
-Rw -------. 1 root 7.0 K Jun 4 18:38 aquota. user
Drwx ------. 2 root 16 K Jun 418:11 lost + found
-Rw-r --. 1 ma 10 K Jun 4 test1 # Here we can see that the size of our test1 file is 10 k


### We have written 10 KB of data to see what changes will happen?
[Ma@bkjia.com quotadir] $ dd if =/dev/zero of =/quotadir/test2 bs = 1 k count = 10
Sdd1: write failed, user block limit reached.
Dd: error writing '/quotadir/test2': Disk quota exceeded
9 + 0 records in
8 + 0 records out # Only 8 k is written
8192 bytes (8.2 kB) copied, 0.000170428 s, 48.1 MB/s

# Next we will test the number of files written to the table:
[Ma@bkjia.com quotadir] $ mkdir a1
Mkdir: cannot create directory 'a1': Disk quota exceeded # error

6. Check the quota of our users:

[Ma@bkjia.com root] $ quota-ugv
Disk quotas for user ma (uid 1001 ):
Filesystem blocks quota limit grace files quota limit grace
/Dev/sdd1 20*10 20 6 days 2 3 5
Disk quotas for group ma (gid 1001 ):
Filesystem blocks quota limit grace files quota limit grace
/Dev/sdd1 20 0 0 2 0 0

VII. Disable Disk Quota
Root@bkjia.com ~ # Quotaoff/quotadir/### disable the disk quota of a single disk
Root@bkjia.com ~ # Quotaoff-a ### disable all enabled quotas of the system
Root@bkjia.com ~ #
Root@bkjia.com ~ # Rm-rf/quotadir/aquota. * # if not, delete the configuration file.
Root@bkjia.com ~ # Delete the automatic mounting in/etc/fstab.

 

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.