Linux系统磁盘配额功能的设置和管理
1. 对硬盘进行分区操作
[root@jsj ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7a02e23d.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n //创建新分区
Command action
e extended
p primary partition (1-4)
P //创建主分区
Partition number (1-4): 1 //输入主分区编号
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): 130 //分配一半空间给第一个分区
Command (m for help): n //再创建一个新分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (131-261, default 131):
Using default value 131
Last cylinder, +cylinders or +size{K,M,G} (131-261, default 261):
Using default value 261
Command (m for help): p //显示分区列表
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a02e23d
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
/dev/sdb2 131 261 1052257+ 83 Linux
Command (m for help): w //保存磁盘分区信息并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@jsj ~]# fdisk -l //查看当前系统所有磁盘信息
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a02e23d //前面在/dev/sdb磁盘上创建分区的列表信息
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
/dev/sdb2 131 261 1052257+ 83 Linux
2. 建立文件系统
[root@jsj ~]# mkfs -t ext4 /dev/sdb2 //为新创建的磁盘分区/dev/sdb2建立文件系统
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65808 inodes, 263064 blocks
13153 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
7312 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3. 编辑/etc/fstab文件实现磁盘分区的自动挂载
[root@jsj ~]# cd / //进入根目录
[root@jsj /]# mkdir disk2 //创建磁盘分区挂载目录/disk2
[root@jsj /]# ls
bin dev etc lib lost+found misc net proc sbin srv tmp var
boot disk2 home lib64 media mnt opt root selinux sys usr
[root@jsj /]# cd disk2
[root@jsj ~]# vi /etc/fstab
[root@jsj disk2]#reboot //重启系统使自动挂载设置生效
[root@jsj disk2]# ls
lost+found
4. 关闭Selinux功能(Linux7以上版本不需要)
[root@jsj disk2]# vi /etc/selinux/config
[root@jsj disk2]# reboot
5. 编辑/etc/fstab文件启动文件系统的配额功能
[root@jsj ~]# vi /etc/fstab
[root@jsj ~]# cd /disk2
[root@jsj disk2]# ls
lost+found
6. 使文件系统的磁盘配额功能生效
[root@jsj disk2]# mount -o remount /disk2 //重新启动系统,或者利用命令重新挂载增加了磁盘配额功能的文件系统,使之生效。
7. 创建quota配额文件
[root@jsj disk2]# quotacheck -cvug /dev/sdb2 //创建quota配额文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb2 [/disk2] done
quotacheck: Cannot stat old user quota file /disk2/aquota.user: 没有那个文件或目录. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /disk2/aquota.group: 没有那个文件或目录. Usage will not be substracted.
quotacheck: Cannot stat old user quota file /disk2/aquota.user: 没有那个文件或目录. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /disk2/aquota.group: 没有那个文件或目录. Usage will not be substracted.
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@jsj disk2]# ls //查看磁盘配额文件
aquota.group aquota.user lost+found
8. 添加用户账户user1
[root@jsj disk2]# useradd -d /disk2/user1 -p 111111 user1 //把新创建的用户的家目录放在启用磁盘配额功能的分区上,该例子中为/dev/sdb1分区的关在点/disk2
[root@jsj disk2]# ls
aquota.group aquota.user lost+found user1
9. 使用edquota命令为user设置磁盘配额
[root@jsj disk2]# edquota -u user1
注意:项目blocks、inodes不可修改,文件系统自动更新,blocks后面的soft和hard选项分别用来设置用户可用磁盘空间的大小,用户使用空间超过soft设置值时,系统发出警告,但是用户仍然可以使用,当用户使用空间超过hard设置的值时,系统直接拒绝用户请求并发出警告。inodes后面的soft和hard选项分别用来设置用户可创建文件的数量,用户创建文件数量超过soft设置值时,系统发出警告,但是用户仍然可以创建文件,当用户创建的文件数量超过hard设置的值时,系统直接拒绝用户请求并发出警告。
10. 使用quotaon命令启动文件系统的磁盘配额功能
[root@jsj disk2]# quotaon -avug
/dev/sdb2 [/disk2]: group quotas turned on
/dev/sdb2 [/disk2]: user quotas turned on
11. 切换到用户user1创建文件并查看磁盘配额管理情况
[root@jsj disk2]# su user1
[user1@jsj disk2]$ cd user1
[user1@jsj ~]$ touch 1
[user1@jsj ~]$ touch 2
[user1@jsj ~]$ touch 3
[user1@jsj ~]$ touch 4
sdb2: warning, user file quota exceeded.
[user1@jsj ~]$ touch 5
[user1@jsj ~]$ touch 6
sdb2: write failed, user file limit reached.
touch: 无法创建"6": 超出磁盘限额
本文来自博客园,作者:Freeland98,转载请注明原文链接:https://www.cnblogs.com/Freeland98/p/17861352.html
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出,原文链接