简介
在本实验中,我们将探索 Linux 的 quotacheck 命令及其实际应用。实验内容包括在 Ubuntu 22.04 上安装 quota 包、在文件系统上启用 quota,以及使用 quotacheck 命令检查配额信息。本实验旨在帮助系统管理员管理磁盘配额,使他们能够限制单个用户或组可以消耗的磁盘空间和 inode 数量。
在 Ubuntu 22.04 上安装 Quota 包
在这一步骤中,我们将在 Ubuntu 22.04 环境中安装 quota 包。quota 包提供了管理磁盘配额的工具,使系统管理员能够限制单个用户或组可以消耗的磁盘空间和 inode 数量。
首先,更新包索引:
sudo apt-get update
示例输出:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
接下来,安装 quota 包:
sudo apt update
sudo apt-get install quota -y
示例输出:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libquota-perl
Suggested packages:
quota-tools
The following NEW packages will be installed:
libquota-perl quota
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 123 kB of archives.
After this operation, 362 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libquota-perl amd64 1.8.0-1 [47.0 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 quota amd64 4.06-2build1 [76.0 kB]
Fetched 123 kB in 0s (1,576 kB/s)
Selecting previously unselected package libquota-perl.
(Reading database ... 16941 files and directories currently installed.)
Preparing to unpack .../libquota-perl_1.8.0-1_amd64.deb ...
Unpacking libquota-perl (1.8.0-1) ...
Selecting previously unselected package quota.
Preparing to unpack .../quota_4.06-2build1_amd64.deb ...
Unpacking quota (4.06-2build1) ...
Setting up libquota-perl (1.8.0-1) ...
Setting up quota (4.06-2build1) ...
Processing triggers for man-db (2.10.2-1) ...
quota 包现已安装在 Ubuntu 22.04 环境中。
在文件系统上启用 Quota
在这一步骤中,我们将在文件系统上启用 quota。Quota 允许你设置单个用户或组可以消耗的磁盘空间和 inode 数量的限制。
首先,为我们的文件系统创建一个新目录:
sudo mkdir /mnt/quota
接下来,我们需要在新的文件系统上启用 quota。我们将使用 quotaon 命令来完成此操作:
sudo quotaon -v /mnt/quota
示例输出:
/mnt/quota: Quotas turned on
-v 选项告诉 quotaon 显示正在启用 quota 的文件系统。
现在,让我们在 /mnt/quota 目录中创建一个新文件以测试 quota 功能:
cd /mnt/quota
sudo touch test_file.txt
示例输出:
没有输出意味着文件已成功创建。
使用 quotacheck 命令检查配额信息
在最后一步中,我们将使用 quotacheck 命令来检查 /mnt/quota 文件系统的配额信息。
首先,运行 quotacheck 命令扫描 /mnt/quota 文件系统:
sudo quotacheck -avugm /mnt/quota
示例输出:
quotacheck: Scanning /dev/mapper/ubuntu--vg-root [/]
quotacheck: Checked 23836 directories and 189324 files
quotacheck: /mnt/quota: checked 1 directories and 1 files
quotacheck 命令执行以下操作:
-a:检查所有文件系统-v:显示详细输出-u:更新配额信息文件-g:检查组配额-m:检查用户配额
接下来,使用 repquota 命令显示 /mnt/quota 文件系统的配额信息:
sudo repquota -a
示例输出:
*** Report for user quotas on device /dev/mapper/ubuntu--vg-root
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 0 0 0 1 0 0
labex -- 0 0 0 1 0 0
*** Report for group quotas on device /dev/mapper/ubuntu--vg-root
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 0 0 0 1 0 0
repquota 命令显示指定文件系统的当前配额信息。在本例中,我们使用 -a 选项来显示所有文件系统的配额信息。
总结
在本实验中,我们学习了如何在 Ubuntu 22.04 上安装 quota 包,该包提供了管理磁盘配额的工具,可以限制单个用户或组可以消耗的磁盘空间和 inode 数量。随后,我们在文件系统上启用了 quota,并使用 quotacheck 命令检查配额信息。实验步骤涵盖了安装过程、启用 quota 以及使用 quotacheck 命令检查配额数据。



