How to set disk quotas on Linux

王林
Release: 2023-07-04 23:33:47
Original
2373 people have browsed it

How to set disk quotas on Linux

In Linux systems, disk quotas are an effective management tool that can limit the amount of disk space used by users. By setting disk quotas, system administrators can control users' disk usage and prevent disk space from being misused. This article explains how to set disk quotas on Linux and provides corresponding code examples.

  1. Check the kernel module

First, we need to ensure that the disk quota function is enabled in the system kernel. Open the terminal and use the following command to check whether the corresponding kernel module has been loaded:

$ sudo modprobe quota_v1 $ sudo modprobe quota_v2
Copy after login

If no error message is reported and the command is executed successfully, the kernel module has been loaded correctly.

  1. Prepare the file system

Before setting the disk quota, we need to enable the quota function on the file system. Find the partition or disk device on which the quota function is to be enabled, and then use the following command to mount the partition or device:

$ sudo mount -o remount,usrquota,grpquota /dev/sda1
Copy after login

Here/dev/sda1is the partition device on which the quota function is to be enabled, Modify according to actual situation.

  1. Create a quota database

After enabling the quota function, we need to create a quota database. Use the following command to create a quota database:

$ sudo quotacheck -cug /dev/sda1
Copy after login

In the above command,/dev/sda1is the name of the partition device where the quota database is to be created.

  1. Enable quota function

After creating the quota database, we can use the following command to enable the quota function:

$ sudo quotaon /dev/sda1
Copy after login

Here/dev/ sda1is the partition device for which the quota function is to be enabled. Modify it according to the actual situation.

  1. Set user quota

Next, we can set quota limits for users using the following command:

$ sudo edquota -u username
Copy after login

replaceusernameReplace with the name of the user whose quota you want to set. After executing the above command, an editor will open where you can set the disk quota limit for the user. For example, you can set soft and hard limits that represent the maximum disk space a user can use. An example is as follows:

Disk quotas for user username (uid xxx): Filesystem blocks soft hard inodes soft hard /dev/sda1 10 10 15 3 0 0
Copy after login

In the above example, the soft limit is 10 blocks and the hard limit is 15 blocks, that is, the user can use up to 15 blocks of disk space.

After setting the user quota, save and close the editor.

  1. Check quota usage

Use the following command to check user quota usage:

$ sudo repquota -a
Copy after login

The above command will display the quota usage of all users, Includes used disk space and quota limits.

  1. Testing Quotas

To verify that the quota settings are taking effect, you can try to create a file or directory within the set quota limits. If the quota limit is exceeded, the system will display the appropriate error message.

Summary

By setting disk quotas, we can effectively manage disk usage on the system and avoid disk space being abused. This article describes how to set disk quotas on Linux and provides corresponding code examples. Hope this article is helpful to you.

The above is the detailed content of How to set disk quotas on Linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!