Linux user disk quota setting method _linux

Source: Internet
Author: User
Tags disk usage

One: Support quota in the kernel:

[Root@localhost/]# grep config_quota/boot/config-3.10.0-123.el7.x86_64
config_quota=y
CONFIG_QUOTA_ Netlink_interface=y
# Config_quota_debug is not set
config_quota_tree=y
config_quotactl=y
config_ Quotactl_compat=y

If there are outputs listed above, the current kernel already supports quota.

II: Modify/ETC/FSTAB Join Quota support:

[Root@localhost/]# Vim/etc/fstab
/dev/sdb1/dvd XFS Defaults,usrquota,grpquota 1 2

Three: Initialize the quota database using Quotacheck:

Because Quotacheck searches the file system based on/etc/mtab, you will want to mount the newly modified/DEV/SDB1 again

[Root@localhost/]# mount/dvd-o remount [root@localhost/]# mount proc on/proc type proc (rw,nosuid,nodev,noexec,r Elatime) Sysfs On/sys type Sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) Devtmpfs On/dev type DEVTMPFS (rw,nosuid,sec label,size=926912k,nr_inodes=231728,mode=755) Securityfs on/sys/kernel/security type SECURITYFS (Rw,nosuid,nodev, Noexec,relatime) Tmpfs on/dev/shm type TMPFS (rw,nosuid,nodev,seclabel) devpts on/dev/pts type devpts (rw,nosuid,noexec, relatime,seclabel,gid=5,mode=620,ptmxmode=000) Tmpfs on/run type TMPFS (rw,nosuid,nodev,seclabel,mode=755) Tmpfs on/ Sys/fs/cgroup type TMPFS (rw,nosuid,nodev,noexec,seclabel,mode=755) cgroup on/sys/fs/cgroup/systemd type Cgroup (rw, NOSUID,NODEV,NOEXEC,RELATIME,XATTR,RELEASE_AGENT=/USR/LIB/SYSTEMD/SYSTEMD-CGROUPS-AGENT,NAME=SYSTEMD) Pstore on/ Sys/fs/pstore type Pstore (rw,nosuid,nodev,noexec,relatime) cgroup on/sys/fs/cgroup/cpuset type Cgroup (Rw,nosuid, Nodev,noexec,relatime,cpuset) Cgroup ON/SYS/FS/CGROUP/CPU,CPUACCT type Cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu) cgroup on/sys/fs/cgroup/memory type Cgroup (rw, nosuid,nodev,noexec,relatime,memory) Cgroup on/sys/fs/cgroup/devices type Cgroup (Rw,nosuid,nodev,noexec,relatime, Devices) Cgroup On/sys/fs/cgroup/freezer type Cgroup (rw,nosuid,nodev,noexec,relatime,freezer) Cgroup on/sys/fs/ CGROUP/NET_CLS type Cgroup (rw,nosuid,nodev,noexec,relatime,net_cls) cgroup On/sys/fs/cgroup/blkio type Cgroup (rw, Nosuid,nodev,noexec,relatime,blkio) Cgroup on/sys/fs/cgroup/perf_event type Cgroup (rw,nosuid,nodev,noexec,relatime , perf_event) cgroup on/sys/fs/cgroup/hugetlb type Cgroup rw,nosuid,nodev,noexec,relatime,hugetlb Configfs Kernel/config type Configfs (rw,relatime)/dev/sda3 on/type xfs (Rw,relatime,seclabel,attr2,inode64,noquota) selinuxfs On/sys/fs/selinux type SELINUXFS (rw,relatime) systemd-1 on/proc/sys/fs/binfmt_misc type AutoFS (rw,relatime,fd=32, Pgrp=1,timeout=300,minproto=5,maxproto=5,direct) Hugetlbfs on/dev/hUgepages type HUGETLBFS (rw,relatime,seclabel) Debugfs on/sys/kernel/debug type Debugfs (rw,relatime) Mqueue On/dev/mque UE type Mqueue (rw,relatime,seclabel) sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) Sunrpc on/proc/fs/n FSD type NFSD (rw,relatime)/dev/sda1 on/boot type XFS (Rw,relatime,seclabel,attr2,inode64,noquota),/DEV/SDB1 On/dvd  E ext2 (Rw,relatime,seclabel,quota,usrquota,grpquota) [root@localhost/]# quotacheck-avug Quotacheck:quota for users are
Enabled on Mountpoint/dvd so Quotacheck might damage the file.
Please turn quotas out or use-f to force checking. -A: Scans all file systems that open quota in/etc/mtab-V: Show scanning process-u: Scan all user quotas (Usrquota)-G: Scan all group quotas (Grpquota)

Four: Start quota: (Quotaon for startup Quotaoff for shutdown)

[Root@localhost/]# quotaon-avug
/dev/sdb1 [/dvd]: Group quotas turned on
/dev/sdb1 [/dvd]: User quotas turned on -
A: Turn on all quota settings,/etc/mtab set-
V: Display information when quota is turned on

Five: Edit user disk quotas:

This set user quota maximum use capacity of 20M, when used to 10M will be a warning request to reduce to 10M can create up to 10 files, when the creation of 5 files will be a warning request to reduce to 5 files

[Root@localhost/]# edquota-u Redhat (redhat for System user name)
Disk quotas for user Redhat (UID 1000):
 filesystem          Blocks    soft    hard   inodes   soft hard/dev/sdb1             0       0     0      0       0    0

To

Disk quotas for user Redhat (UID 1000):
 filesystem          blocks    soft   hard inodes soft
 /dev/sdb1             0     10240   20480    0     5     10

-U: Edit User's quota
-G: Edit Group Quota
-T: Editing a wide-limit room
-P: Copy quota data to another user

Blocks: Current user (quota:uid=5011) space used in/DEV/HDA7, Unit: KB (do not modify)

Soft:soft Limit Disk Space Limited unit: KB (required)
Hard:hard Limit Disk Space Limited unit: KB (required)

Inodes: The current user uses the Inodes, because it is not easy to use inode control, so do not modify it.

Soft:soft Limit file limit (modified as needed)
Hard:hard Limit file limit (modified as needed)

Soft limit: Minimum limit capacity, within the grace period (grace period), the use of capacity can exceed soft limit, but must be within the grace period to reduce the use of capacity to soft limit below.

Hard limit: Ultimate limit capacity, if the user continues to write data within the grace period, the arrival of the hard limit will no longer be writable.

Grace Time: Use more than soft limit, grace time to start automatically, the user will reduce the capacity to soft limit below, grace time automatically shut down, if the user does not in the grace time to reduce the capacity to soft limit, then he will not be able to write data, Even if the use capacity did not reach hard limit

Six. Set the grace period:

[Root@localhost dvd]# edquota-t
Grace period before enforcing soft for users: Time
limits may units, be:days RS, minutes, or seconds
 filesystem block       grace period   Inode grace period
 /dev/sdb1           7days         7days
[root@localhost dvd]# quota-uv Redhat (-u: Displays user. -V: Show quota value)
Disk quotas for user Redhat (UID 1000): FileSystem blocks Quota limit  Grace  files  Quota  limit  Grace
   /dev/sdb1    0  10240  20480        0      5    10    

Seven. Copy quota data to another user using the-p parameter:

[Root@localhost dvd]# edquota-p redhat aaa 
[root@localhost dvd]# quota-uv AAA
Disk quotas for user aaa (UID 1001 ):
   filesystem blocks  Quota  limit  Grace  files  quota  limit  Grace
   /dev/sdb1    0   10240  20480        0     5    

Copy to multiple users at the same time:

[root@localhost DVD] #edquota-P Redhat ' Awk-f: ' $ >499 {print $} '/etc/passwd '

This copies the quota disk quota data to all UID >499 users (users with a UID of more than 500 are usually real users)

Eight. Automatic activation of quota when the system starts:

You can add a line to the end of/etc/rc.d/rc.sysinit or/etc/rc.d/rc.local:/usr/sbin/quotaon-aug

Also remember to add a statement to close quota in the system shutdown/restart script (/etc/rc.d/rc[0,6]/):/usr/sbin/quotaoff-aug

Nine. Query disk quotas:

[Root@localhost dvd]# repquota-a
* * * for user quotas on DEVICE/DEV/SDB1 block
Grace Time:24:00; Inode Grace Time:7days block
            limits        File limits
User      used  soft  hard grace  used soft hard Grace
----------------------------------------------------------------------
Root   --   20     0    0            2   0   0    

10. Scheduled Task Quotcheck:

Quotcheck is used to scan the file system for disk usage, update aquota.user,aquota.group keep quota log to the latest state. It is therefore best to execute at system startup or periodically through Cron:

Once every Saturday Seven o'clock: 0 7 * * 6/sbin/quotacheck-avug

The above is a small series for everyone to bring the Linux user disk quota settings method All content, I hope that we support cloud-Habitat Community ~

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.