Introduction
In this lab, we will explore the Linux quotaon command and its practical applications for managing disk quotas. The lab covers the introduction to disk quota management, enabling disk quota on a file system, and monitoring and managing user disk quotas. We will learn how to set up and configure disk quota management, as well as how to monitor and manage user disk usage on a Linux system. The lab provides step-by-step instructions and practical examples to help you understand and apply disk quota management effectively.
Introduction to Disk Quota Management
In this step, we will explore the concept of disk quota management in Linux. Disk quotas are a system that allows system administrators to limit the amount of disk space that a user or group can consume on a file system.
First, let's check the current disk usage on the file system:
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
overlay 39G 16G 22G 42% /
tmpfs 64M 0 64M 0% /dev
tmpfs 16G 0 16G 0% /sys/fs/cgroup
shm 64M 0 64M 0% /dev/shm
/dev/sda1 39G 16G 22G 42% /
tmpfs 16G 0 16G 0% /run
tmpfs 16G 0 16G 0% /var/run
tmpfs 16G 0 16G 0% /var/lib/docker
overlay 39G 16G 22G 42% /var/lib/docker/overlay2
tmpfs 16G 0 16G 0% /sys/fs/cgroup
The output shows the current disk usage on the file system. In this example, the root file system (/) is using 42% of the available disk space.
Next, let's enable disk quota management on the root file system:
sudo apt-get update
sudo apt-get install -y quota
sudo quotacheck -cug /
sudo quotaon -a
The quotacheck command scans a file system, builds a table of the current disk usage, and stores it in the file system's kernel memory. The quotaon command enables disk quota management on the specified file system.
Now, let's verify that disk quota management is enabled:
sudo quotaon -a
Example output:
/: quotas turned on
The output confirms that disk quota management is enabled on the root file system (/).
Enabling Disk Quota on a File System
In this step, we will learn how to enable disk quota on a specific file system.
First, let's create a new directory and mount it as a separate file system:
sudo mkdir /data
sudo mount -t tmpfs tmpfs /data
Now, let's enable disk quota management on the /data file system:
sudo quotacheck -cug /data
sudo quotaon /data
The quotacheck command scans the /data file system, builds a table of the current disk usage, and stores it in the file system's kernel memory. The quotaon command enables disk quota management on the /data file system.
Let's verify that disk quota management is enabled on the /data file system:
sudo quotaon -a
Example output:
/: quotas turned on
/data: quotas turned on
The output confirms that disk quota management is enabled on both the root file system (/) and the /data file system.
Next, let's set disk quota limits for a user. In this example, we'll use the labex user:
sudo edquota labex
This will open the quota editor, where you can set the soft and hard limits for the user's disk usage. For example:
Disk quotas for user labex (uid 1000):
Filesystem blocks soft hard inodes soft hard
/data 0 5000 6000 0 0 0
In this example, the soft limit for the /data file system is set to 5000 blocks, and the hard limit is set to 6000 blocks.
Monitoring and Managing User Disk Quotas
In this final step, we will learn how to monitor and manage user disk quotas.
First, let's check the current disk quota usage for the labex user:
sudo repquota /data
Example output:
*** Report for user quotas on device /data
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
---------------------------------------------------------------------
labex -- 0 5000 6000 0 0 0
The repquota command displays the current disk quota usage for the specified file system. In this example, the labex user has used 0 blocks out of the 5000 block soft limit and 6000 block hard limit on the /data file system.
Now, let's simulate a scenario where the labex user exceeds their disk quota:
dd if=/dev/zero of=/data/bigfile.txt bs=1M count=6000
This command creates a 6000 MB file in the /data directory, which will exceed the labex user's disk quota.
Let's check the disk quota usage again:
sudo repquota /data
Example output:
*** Report for user quotas on device /data
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
---------------------------------------------------------------------
labex * 6000 5000 6000 1day 0 0 0
The output shows that the labex user has exceeded their soft limit of 5000 blocks, and is now in a grace period of 1 day to reduce their disk usage.
To manage the user's disk quota, you can use the following commands:
sudo edquota labex ## Edit the user's disk quota limits
sudo quota -v labex ## Display the user's current disk quota usage
sudo quota -l labex ## Display the user's disk quota limits
The edquota command allows you to modify the user's disk quota limits, while the quota command allows you to view the user's current disk quota usage and limits.
Summary
In this lab, we first explored the concept of disk quota management in Linux, which allows system administrators to limit the amount of disk space that a user or group can consume on a file system. We then learned how to enable disk quota management on the root file system by installing the necessary packages, running the quotacheck command to build a table of the current disk usage, and enabling disk quota management with the quotaon command. Finally, we learned how to enable disk quota management on a separate file system by creating a new directory, mounting it as a separate file system, and enabling disk quota management on that file system.



