Disk quota
lastmod 2025-02-17created 2023-07-064 edits
Per-user and per-group storage management
Guide to reserving directory space and restricting R/W on Linux
On Linux, there are several ways to reserve a large amount of space in a specific directory in advance and then prevent users from reading and writing that space.
The main methods are below:
Disabling the directory for specific users/groups (permission settings)
Create the directory and reserve space:
- The command above reserves 10GB of space in advance under the name dummy_file.
Set directory permissions:
-
chmod 000removes read, write, and execute permissions on the directory for all users.
Allow access for a specific user only (optional):
- To restrict access to the root user only, set it as above.
Allocating a file system and mounting it
Create a virtual disk image:
- Creates a 10GB virtual disk as the
disk.imgfile.
Create the file system:
Mount the file and restrict permissions:
-
/mnt/secured_diris now a 10GB space that cannot be read or written.
Limiting directory capacity with the Quota system
To let users access a specific directory but apply write limits, you can set up the Quota system.
Enable file system Quota:
Add the setting below to /etc/fstab:
Configure Quota:
Apply limits to a specific user
- Set the per-user storage limits here.
Blocking R/W with a loopback device
Create a file and set up the loopback device:
dd if=/dev/zero of=/path/to/loopback.img bs=1G count=10
losetup /dev/loop0 /path/to/loopback.img
mkfs.ext4 /dev/loop0
Mount the loopback device, then block it:
- See losetup or Korean: 루프 장치 for details.
Applying a custom SELinux policy (when SELinux is enabled)
Set the directory's SELinux context:
Block user access:
semanage fcontext -a -t unconfined_u:object_r:default_t:s0 /path/to/directory
restorecon -R /path/to/directory
See also
- Linux
- Managing Disk Space - Notes on issues when disk space runs low.
Favorite site
- Disk quota - Wikipedia
- How to limit Linux user storage with quota - IT Opening
- Complete guide to the concept and usage of Quota, the Linux storage limit management system
- Linux, per-user and per-group disk usage limits.. : Naver Blog