Setting folder size limits in CentOS

Creating folders with quotas primarily utilizes loop devices in Linux.

In Linux, there is a special type of block device called a loop device. A loop device is a virtual block device created by mapping a normal file on the operating system. In other words, a loop device is a virtual device used to treat a file as a virtual disk medium. After association, the loop can be formatted; this essentially involves performing certain operations on the associated file, allowing it to be mounted and used like a disk.

In other words, a circular device can virtualize files as block devices to simulate the entire file system, so that users can treat it as a hard drive, CD-ROM drive, or floppy drive and mount it as a directory.

Here are the specific steps to create a quota folder:

1. First, use the dd command to create a quota file of 20MB.

dd if=/dev/zero ibs=2M count=10 of=/usr/local/test.img

if=/dev/zero: indicates that the input file is /dev/zero; /dev/null can also be used.

ibs=2M: IBlockSize indicates that the block size is 2M.
of=/usr/local/test.img: Output file

2. Associate the test.img file with the loop device.

losetup /dev/loop0 /usr/local/test.img

3. Creating a file system on the virtual device is actually an operation on test.img, because it has already been associated with /dev/loop0.

mkfs /dev/loop0

4. Mount the file device to the target folder to complete the quota function for the folder (/usr/local/test02).

mount /dev/loop0 /usr/local/test02

5. Resources need to be released when no longer in use.

umount /usr/local/test02 losetup -d /dev/loop0

6. Add the command to start the program to the /etc/rc.d/rc.sysinit file.

The script `/etc/rc.d/rc.sysinit` starts system services, such as setting system environment variables, setting the system clock, loading fonts, checking and loading file systems, and generating system startup log files.

We can use the losetup command to check the number of loop block devices that are already in use.

  losetup -a |wc -l

This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:

Original author:Jake Tao,source:"Setting a limit on folder size in CentOS"

222
0 0 222

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top