Linux 练习题16.1 磁盘配额

Linux 练习题16.1 磁盘配额

欢迎扫码关注微信公众号 野心与家,获取更多相关内容

●前期准备:有user1用户,有/dev/sdb1分区,且分区文件系统为ext4,新建目录/mnt/mountpoint1

[root@localhost ~]# useradd user1
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xb4c67292 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):1
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):
命令(输入 m 获取帮助):w				//保存重要
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# mkdir /mnt/mountpoint1
[root@localhost ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000
Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

● 启动vi编辑/etc/fstab文件。把/etc/fstab文件中的/dev/sdb1分区挂载到/mnt/mountpoint1,添加用户和组的磁盘限额。重新启动系统。

[root@localhost ~]# vi /etc/fstab
/dev/sdb1	/mnt/mountpoint1 ext4 defaults,usrquota,grpquota 0 0
##查询是否挂载
[root@localhost aoian]# mount | grep sdb
/dev/sdb1 on /mnt/mountpoint1 type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)

● 用quotacheck命令创建aquota.user和aquota.group文件。

[root@localhost aoian]# quotacheck -ug /dev/sdb1
[root@localhost aoian]# cd /mnt/mountpoint1
[root@localhost mountpoint1]# ls
aquota.group  aquota.user  lost+found

● 利用edquota –u user1命令给用户user1设置磁盘限额功能。将其blocks的soft设置为5000,hard设置为10000。编辑完成后保存并退出。

[root@localhost aoian]# edquota –u user1
Disk quotas for user user1 ( uid 1001) :
Filesystem 	 blocks 	soft 	hard 	inodes 	soft 	hard 
/dev/sdb1        0  	5000    10000      0      0		  0

● 用quotaon命令启用quota功能。

[root@localhost aoian]# quotaon -ug /mnt/mountpoint

●查看磁盘限额及使用情况。

[root@localhost aoian]# df -h /dev/sdb1
# -h 作用显示单位便于查看

● 尝试复制大小分别超过磁盘限额软限制和硬限制的文件到用户的主目录下,检验一下磁盘限额功能是否起作用。

[root@RHEL7-1 ~] # chmod 777 /mnt/mountpoint1
root@RHEL7- 1 ~] # su user1
[ user1@RHEL7- 1 root]$ dd if=/dev/zero of=/mnt/mountpoint1/file1 bs=6000 count=1
sdb1: warning,user block quota exceeded.
记录了1+0的读入
记录了1+0的写出
6000000字节(6.0 MB)已复制,0. 0240897秒,249 MB/秒
[user1@RHEL7-1 root]$ dd if=/dev/zero of=/mnt/mountpoint1/file2 bs=6000 count=1
sdb1: write failed, user block limit reached.
dd: 写入"/mnt/mountpoint1/file2" 出错:超出磁盘限额
记录了1+0的读入
记录了0+0的写出
4239360字节(4.2 MB)已复制,0. 015877秒,267 MB/秒

● 请自己尝试设置文件数量软限制2个,硬限制4个,检验一下磁盘限额功能是否起作用。

[root@RHEL7-1 ~]# su user1
[user1@RHEL7-1 root] $ cd /mnt/ mountpoint1
[user1@RHEL7-1 mountpoint1]$ touch file1
[user1@RHEL7-1 mountpoint1] $ touch file2
[user1@RHEL7-1 mountpoint1]$ touch file3
sdb1: warning, user file quota exceeded.
[user1@RHEL7-1 mountpoint1] $ touch file4
[user1@RHEL7-1 mountpoint1] $ touch file5
sdb1: write failed,user file limit reached.
touch:无法创建"file5":超出磁盘限额

猜你喜欢

转载自blog.csdn.net/m0_46653702/article/details/110638345
今日推荐