Create disk quotas on Linux

Source: Internet
Author: User

Overview and management of disk quotas

Why do I create a disk Amount

When the disk space on the Linux root partition is exhausted, Linux will no longer be able to create new files (including temporary files that the program runs), causing the service program to crash and the system to fail to boot.

To avoid similar problems, you can set the Enable disk quotas feature to limit the amount of disk space and number of files used by users in the specified file system (partition) to prevent individual users from using large amounts of disk space maliciously or unintentionally, thus guaranteeing the stability and continuous availability of the system's storage space.


Prerequisites for using disk quotas

To set disk quotas, you need to install the Quota software package to configure and manage disk quotas, and in Rhel 6, the system installs the quota package by default.


Scope of disk quotas

The disk quota feature set by the quota software is only valid within the specified file system (partition) and will not be restricted when users use other file systems that do not have quotas set.


Limit objects for disk quotas

Quota mainly for the designated user account in the system, group account restrictions, users or groups that are not set limits will not be affected. When you set quotas on a group account, the sum of the disk capacity and the number of files used by all members of the group cannot exceed the limit.


Limit type of disk quotas

# Disk Capacity: limits the size of disk space that users can use, with the default unit of KB

# Number of files: limit the number of files a user can use


How to limit disk quotas

# Soft limit: Specify a soft quota value (such as 100MB of disk space, 80 files), allow exceeding this limit within a fixed grace period (seven days by default), but the system will give a warning message

# Hard limit: Specify a hard quota value (such as 120MB of disk space, 100 files), is absolutely prohibit the user to exceed the limit value, when the hard limit value is reached, the system will give a warning message and prohibit continue to write data. The hard limit quota value should be greater than the soft limit value, otherwise the soft limit will expire


Experiment:

Next, mount the Yang logical volume/dev/ysf/yang created in the previous article to the/mailbox directory, and then configure the implement disk quotas feature in the file.


1. mount the file system in a way that supports disk quota functionality

Writes the Usrquota, grpquota mount parameter to the "/etc/fstab" file.

# chmod 777/mailbox//For subsequent testing convenience, allowing any user to write data

# Vim/etc/fstab//Modify mount Configuration of Yang logical volume

/dev/ysf/yang/mailbox ext4 defaules,usrquota,grpquota 0 0


2. detect disk quotas and generate quota files

You can use the quotacheck command to perform disk quota detection on a specified file system, or to establish a quota file to save user, group quota settings for that partition

For example, do the following to scan all file systems in the system and establish quota files in the file system that supports quotas

# QUOTACHECK-AUGCV

- a means that all partitions are scanned, and if not used, a partition or mount point directory must be specified as the command parameter

-U indicates detection of user quota information

-G indicates detection group quota information

-C means creating a new quota file

-V indicates that details are displayed during command execution

# ls-l/mailbox/aquota.*

You can see the newly created configuration file, including "Aquota.user", "aquota.group", respectively, to save the user, group quota settings, the configuration file is saved under the root of the file system, the default permissions are 600


3. Edit quota settings for user and group accounts

Use the edquota command with the-u,-G option to edit the quota settings for users and groups (by default call VI as an editor), you can set the disk capacity, the file size of the soft, hard limit values.

For example, you can do the following to edit a user's Zhangsan quota

# edquota-u Zhangsan

Filesystem blocks soft hard inodes soft hard

/dev/mapper/ysf-yang 0 0 0 0 0 0

Filesystem: Indicates the file system (partition) of the bank's configuration record file, that is, the scope of the quota

Blocks: Indicates the disk capacity that the user has used, the default unit is KB

Inodes: Indicates the number of files currently owned by the user

Soft: The 3rd column corresponds to the disk capacity of the soft limit value, in kilobytes, 6th column corresponding file number soft limit value, unit

Hard: The 3rd column corresponds to the disk capacity of the number of rigid limits, in kilobytes, 6th column corresponding to the number of files hard limit value, units of


For example: To set a quota for Zhangsan, the disk capacity soft limit is 80MB, the hard limit is 100MB, the number of files soft limit 40, hard limit 40, you can do the following

# edquota-u Zhangsan

Filesystem blocks soft hard inodes soft hard

/dev/mapper/ysf-yang 0 80000 100000 0


You can set the grace period for soft limits, which is 7 days by default and can be modified.

For example, you can change the grace period to 10 days.

# edquota-t

Filesystem Block grace period Inode grace period

/dev/mapper/ysf-yang 10days 10days


4. Start the disk quotas feature of the file system

The disk quota feature for starting and shutting down the file system is performed using the quotaon, Quotaoff command, which requires specifying the device file name or the mount point of the file system as the parameter. The Quotaon command uses the same options as the quotacheck option.

For example, do the following to enable the user, group disk quota feature for the/mailbox file system, and to display procedural information for the command execution.

# Quotaon-ugv/mailbox


5. View quota usage for users or partitions

You can use the Quota command, the Repquota command, where the quota command can view the quota usage of the specified users and groups, respectively, with the-u,-g option, while the Repquota command primarily specifies the file system output quota usage report, combined with-a option to view the Quota usage report for all available partitions.

Example: View user account Zhangsan, group account users quota usage

# quota-u Zhangsan

# QUOTA-G Users


View quota usage for the/mailmox file system

# Repquota/mailmox


6. Verify the disk quotas feature

You can use the DD conversion tool, the DD command is the device conversion and copy command

For example: Write a test file named A.txt to the/mailmox directory with a size of 10MB (10 reads, each 1MB), and copy the source to the device/dev/zero

# dd If=/dev/zero of=/mailmox/a.txt bs=1m count=10

If= specifying input devices (or files)

Of= specifying an output device (or file)

bs= Specifies the size of the read data block

count= Specifies the number of read data blocks


This article is from the "Yang Shufan" blog, make sure to keep this source http://yangshufan.blog.51cto.com/13004230/1948873

Create disk quotas on Linux

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.