如何在 Linux 中设置目录大小限制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8148715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set limit on directory size in Linux?
提问by user710818
I have read about limiting size of directory - like creating big files, formatting,mount,.. etc. But this all very complicated. Does exist utility or something else to set limit on already existing directory?
我已经阅读了限制目录大小的内容——比如创建大文件、格式化、挂载等。但这一切都非常复杂。是否存在实用程序或其他东西来设置对现有目录的限制?
采纳答案by Sergei Nikulov
Quota is based upon filesystems, but you can always create a virtual filesystem and mount it on a specific (empty) directory with the usrquota and/or grpquota flags.
配额基于文件系统,但您始终可以创建一个虚拟文件系统,并将其挂载到具有 usrquota 和/或 grpquota 标志的特定(空)目录中。
In steps this will be:
在步骤中,这将是:
- create the mount point
- create a file full of /dev/zero, large enough to the maximum size you want to reserve for the virtual filesystem
- format this file with an ext3 filesystem (you can format a disk space even if it is not a block device, but double check the syntax of every - dangerous - formatting command)
- mount the newly formatted disk space in the directory you've created as mount point, e.g.
Code:
mount -o loop,rw,usrquota,grpquota /path/to/the/formatted/disk/space /path/of/mount/point
- Set proper permissions
- Set quotas and the trick is done.
- 创建挂载点
- 创建一个充满 /dev/zero 的文件,该文件足够大到您希望为虚拟文件系统保留的最大大小
- 使用 ext3 文件系统格式化此文件(即使它不是块设备,您也可以格式化磁盘空间,但请仔细检查每个 - 危险 - 格式化命令的语法)
- 在您创建的目录中挂载新格式化的磁盘空间作为挂载点,例如代码:
mount -o loop,rw,usrquota,grpquota /path/to/the/formatted/disk/space /path/of/mount/point
- 设置适当的权限
- 设置配额,诀窍就完成了。