Linux edquota Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Linux edquota command and learn how to manage disk quotas on a Linux file system. We will start by understanding the concept of disk quota, which allows system administrators to limit the amount of disk space that a user or group can consume. Then, we will learn how to enable disk quota on a Linux file system and use the edquota command to set and manage user disk quotas. This lab will provide practical examples and step-by-step instructions to help you effectively manage disk space usage in your Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/UserandGroupManagementGroup -.-> linux/useradd("`User Adding`") linux/UserandGroupManagementGroup -.-> linux/usermod("`User Modifying`") linux/BasicFileOperationsGroup -.-> linux/chown("`Ownership Changing`") linux/SystemInformationandMonitoringGroup -.-> linux/df("`Disk Space Reporting`") linux/SystemInformationandMonitoringGroup -.-> linux/du("`File Space Estimating`") linux/SystemInformationandMonitoringGroup -.-> linux/mount("`File System Mounting`") subgraph Lab Skills linux/mkdir -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/useradd -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/usermod -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/chown -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/df -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/du -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} linux/mount -.-> lab-422658{{"`Linux edquota Command with Practical Examples`"}} end

Understanding Disk Quota Concept

In this step, we will explore the concept of disk quota in Linux. Disk quota is a system that allows system administrators to limit the amount of disk space that a user or group can consume on a file system.

Disk quota is typically used in shared environments, such as web hosting or cloud computing, where multiple users or applications are using the same storage resources. By setting disk quotas, system administrators can ensure that no single user or application can monopolize the available storage, and that all users have a fair share of the resources.

To understand the disk quota concept, let's consider the following scenario:

Imagine you have a file system with a total capacity of 100 GB. You have three users, Alice, Bob, and Charlie, who are all using this file system. Without disk quota, each user could potentially use up the entire 100 GB of storage, leaving the other two users with no space to work with.

With disk quota, you can set a limit on the amount of storage each user can consume. For example, you could set a quota of 30 GB for Alice, 30 GB for Bob, and 40 GB for Charlie. This ensures that each user has a fair share of the available storage, and no single user can monopolize the resources.

Disk quota can be set at the user level, group level, or both. System administrators can also set soft and hard limits for each user or group. A soft limit is a warning threshold, where the user is notified when they are approaching their quota. A hard limit is a strict limit that the user cannot exceed, even if they try to do so.

In the next step, we will learn how to enable disk quota on a Linux file system and manage user disk quotas using the edquota command.

Enabling Disk Quota on a Linux Filesystem

In this step, we will learn how to enable disk quota on a Linux file system.

First, let's create a new directory for our file system and mount it:

sudo mkdir /quota_fs
sudo mount -t ext4 -o usrquota,grpquota /dev/vdb1 /quota_fs

The usrquota and grpquota options enable user and group quotas, respectively, on the file system.

Next, we need to create the necessary quota files:

sudo quotacheck -cum /quota_fs

This command creates the aquota.user and aquota.group files in the root of the file system, which are used to store the quota information.

Now, we need to enable the quota system:

sudo quotaon -a

This command enables the quota system for all file systems that have quota enabled.

To verify that the quota system is enabled, we can use the repquota command:

sudo repquota /quota_fs

Example output:

*** Report for user quotas on device /quota_fs
-----------------------------------------------------------------------------
User            used    soft    hard  grace
-----------------------------------------------------------------------------
root      --      0       0       0
labex     --      0       0       0

The output shows that the quota system is enabled, and there are no current quotas set for the root and labex users.

In the next step, we will learn how to manage user disk quotas using the edquota command.

Managing User Disk Quota with edquota Command

In this step, we will learn how to manage user disk quotas using the edquota command.

First, let's create a new user named alice and add her to the file system we created in the previous step:

sudo useradd -m alice
sudo usermod -a -G labex alice
sudo chown -R alice:labex /quota_fs

Now, we can use the edquota command to set disk quotas for the alice user:

sudo edquota -u alice

This will open the quota editor in the default text editor (usually nano). You should see something like this:

Disk quotas for user alice (uid 1001):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /quota_fs                        0       50000      60000          0       500       600

Here, we can set the following quota limits for the alice user:

  • Soft block limit: 50,000 blocks
  • Hard block limit: 60,000 blocks
  • Soft inode limit: 500 inodes
  • Hard inode limit: 600 inodes

After making the changes, save and exit the editor.

To verify the quota settings, we can use the repquota command:

sudo repquota /quota_fs

Example output:

*** Report for user quotas on device /quota_fs
-----------------------------------------------------------------------------
User            used    soft    hard  grace
-----------------------------------------------------------------------------
root      --      0       0       0
alice     --      0   50000   60000
labex     --      0       0       0

The output shows that the alice user has a soft limit of 50,000 blocks and a hard limit of 60,000 blocks.

In the next step, we will verify the steps you have learned in this lab.

Summary

In this lab, we learned about the concept of disk quota 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 on a Linux file system by mounting it with the appropriate options. Finally, we explored how to manage user disk quotas using the edquota command.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like