A filesystem quota is a system-level setting that is used to limit the amount of disk space or inode usage that a user or group can consume on a Linux filesystem. Quotas are commonly used in shared hosting environments to ensure that individual users do not use more than their allocated share of disk space and inodes.
In this article, we will show you how to set filesystem quotas on Debian 10 (also known as “Buster”). We will be using the command line for this tutorial, so you will need to have a basic understanding of how to use the Linux command line.
Before we begin, there are a few prerequisites that you will need to have in place in order to set filesystem quotas on your system:
- A server running Debian 10
- A user account with sudo privileges
- A filesystem that supports quotas (such as ext4)
To check if your filesystem supports quotas, run the following command:
sudo tune2fs -l /dev/<filesystem-device> | grep -i "has_journal"
Replace <filesystem-device>
with the device name of your filesystem (such as /dev/sda1
). This will display whether the filesystem has a journal, which is required for quotas to work.
If your filesystem does not support quotas, you will need to create a new filesystem that does. For more information on how to do this.
- Install the quota package
To use quotas on your system, you will need to install the quota package. This package provides the tools and utilities that are needed to manage and enforce quotas on your filesystem.
To install the quota package, run the following command:
sudo apt install quota
This will install the quota package and all of the required dependencies.
- Enable quotas on the filesystem
To enable quotas on your filesystem, you will need to edit the /etc/fstab
file, which defines the available filesystems and their mount options.
To edit the /etc/fstab
file, run the following command:
sudo nano /etc/fstab
This will open the /etc/fstab
file in the nano text editor.
Locate the line that defines the filesystem that you want to enable quotas on, and add the “usrquota
” and “grpquota
” options to the “options” field. For example:
/dev/sda1 / ext4 defaults,usrquota,grpquota 0 1
The “usrquota
” and “grpquota
” options enable user and group quotas, respectively, on the filesystem.
Save the file and exit the editor.
To apply the changes, you will need to remount the filesystem. To do this, run the following command:
sudo mount -o remount /dev/<filesystem-device>
Replace <filesystem-device>
with the device name of your filesystem (such as /dev/sda1
).
This will remount the filesystem and apply the changes that you made to the /etc/fstab
file.
- Create quota files
To enable quotas on a filesystem, you will need to create quota files for each user and group that you want to apply.
To create quota files, run the following command:
sudo quotacheck -augm
This will create quota files for all users and groups on the filesystem. The “-a
” option specifies that the command should be applied to all mounted filesystems, while the “-u
” and “-g
” options specify that user and group quotas should be enabled, respectively. The “-m
” option specifies that the command should be run in maintenance mode, which allows it to be run on a live filesystem without causing errors.
- Edit the quota configuration file
To set the limits for user and group quotas, you will need to edit the /etc/quota.conf
file. This file contains the default settings for user and group quotas on the system.
To edit the /etc/quota.conf
file, run the following command:
sudo nano /etc/quota.conf
This will open the /etc/quota.conf
file in the nano text editor.
To set the default limits for user and group quotas, locate the “DEFAULT
” section in the file and edit the “USRQUOTA
” and “GRPQUOTA
” settings. For example:
DEFAULT
USRQUOTA=2048000
GRPQUOTA=2048000
This sets the default user and group quotas to 2048000 kilobytes (2GB).
Save the file and exit the editor.
- Enable quotas
To enable quotas on the system, you will need to edit the /etc/default/quota
file. This file contains the default settings for the quota system on the system.
To edit the /etc/default/quota
file, run the following command:
sudo nano /etc/default/quota
This will open the /etc/default/quota
file in the nano text editor.
To enable quotas on the system, set the “QUOTA
” variable to “on
“. For example:
QUOTA=on
Save the file and exit the editor.
To apply the changes, you will need to restart the quota service. To do this, run the following command:
sudo service quota restart
This will restart the quota service and apply the changes that you made to the configuration files.
Conclusion
In this article, we showed you how to set filesystem quotas on Debian 10. We covered all of the necessary steps, including installing the quota package, enabling quotas on the filesystem, creating quota files, editing the quota configuration file, and enabling quotas on the system. With filesystem quotas set up on your system, you can ensure that individual users and groups do not consume more than their allocated share of disk space and inodes.