1.为主机增加80G SCSI 接口硬盘
磁盘 /dev/sde:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

2.划分三个各20G的主分区
[root@localhost ~]# fdisk -l /dev/sde

磁盘 /dev/sde:85.9 GB, 85899345920 字节,167772160 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x76f1cf35

设备 Boot Start End Blocks Id System
/dev/sde1 2048 41945087 20971520 83 Linux
/dev/sde2 41945088 83888127 20971520 83 Linux
/dev/sde3 83888128 125831167 20971520 83 Linux

3.将三个主分区转换为物理卷(pvcreate),扫描系统中的物理卷
[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [39.51 GiB / 44.00 MiB free]
PV /dev/sdd1 VG vg0 lvm2 [5.00 GiB / 0 free]
PV /dev/sdd2 VG vg0 lvm2 [5.00 GiB / 1.99 GiB free]
PV /dev/sde2 lvm2 [20.00 GiB]
PV /dev/sde3 lvm2 [20.00 GiB]
PV /dev/sde1 lvm2 [20.00 GiB]
Total: 6 [109.50 GiB] / in use: 3 [49.50 GiB] / in no VG: 3 [60.00 GiB]

4.使用两个物理卷创建卷组,名字为myvg,查看卷组大小
[root@localhost ~]# vgcreate myvg /dev/sde[12]
Volume group "myvg" successfully created
[root@localhost ~]# vgdisplay /dev/myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 0 / 0
Free PE / Size 10238 / 39.99 GiB
VG UUID EwnxZU-9cNM-eHQW-TqGx-Xv3g-COko-zlbGqx

5.创建逻辑卷mylv,大小为30G
[root@localhost ~]# lvcreate -L 30G -n mylv myvg
Logical volume "mylv" created.

6.将逻辑卷格式化成xfs文件系统,并挂载到/data目录上,创建文件测试

[root@localhost ~]# mkfs -t xfs /dev/myvg/mylv
meta-data=/dev/myvg/mylv isize=256 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

/dev/mapper/myvg-mylv xfs 30G 33M 30G 1% /data

7.增大逻辑卷到35G
[root@localhost ~]# lvextend -L +5G /dev/myvg/mylv
Size of logical volume myvg/mylv changed from 30.00 GiB (7680 extents) to 35.00 GiB (8960 extents).
Logical volume mylv successfully resized

[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 38G 5.0G 33G 14% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 490M 84K 490M 1% /dev/shm
tmpfs tmpfs 490M 7.0M 483M 2% /run
tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 124M 373M 25% /boot
/dev/sr0 iso9660 4.1G 4.1G 0 100% /run/media/root/CentOS 7 x86_64
/dev/mapper/myvg-mylv xfs 35G 33M 35G 1% /data

8.编辑/etc/fstab文件挂载逻辑卷,并支持磁盘配额选项
/dev/myvg/mylv /data xfs defaults 0 0
~
9.创建磁盘配额,crushlinux用户在/data目录下文件大小软限制为80M,硬限制为100M,
crushlinux用户在/data目录下文件数量软限制为80个,硬限制为100个。
[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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[root@localhost ~]# useradd curshlinux
[root@localhost ~]# ls
anaconda-ks.cfg httpd-2.2.17.tar.gz media 公共 模板 视频 图片 文档 下载 音乐 桌面
[root@localhost ~]# passwd curshlinux
更改用户 curshlinux 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。


[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sdb1 /data
[root@localhost ~]# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root xfs 38G 5.0G 33G 14% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 490M 80K 490M 1% /dev/shm
tmpfs tmpfs 490M 6.9M 483M 2% /run
tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 124M 373M 25% /boot
/dev/sdb1 ext4 4.8G 20M 4.6G 1% /data


[root@localhost ~]# mount -o remount,usrquota,grpquota /data
[root@localhost ~]# mount | grep /data
/dev/sdb1 on /data type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)
[root@localhost ~]# grep /dev/sdb1 /etc/mtab
/dev/sdb1 /data ext4 rw,seclabel,relatime,quota,usrquota,grpquota,data=ordered 0 0
[root@localhost ~]# vim /etc/fatab
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]#


[root@localhost ~]# quotacheck -avug
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/sdb1 [/data] done
quotacheck: Cannot stat old user quota file /data/aquota.user: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /data/aquota.group: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old user quota file /data/aquota.user: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /data/aquota.group: 没有那个文件或目录. Usage will not be subtracted.
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.

[root@localhost ~]# quotaon -auvg
/dev/sdb1 [/data]: group quotas turned on
/dev/sdb1 [/data]: user quotas turned on

[root@localhost ~]# chmod 777 /data
[root@localhost ~]# edquota -u curshlinux
[root@localhost ~]# quota -uvs curshlinux
Disk quotas for user curshlinux (uid 1001):
Filesystem space quota limit grace files quota limit grace
/dev/sdb1 0K 81920K 100M 0 80 100
[root@localhost ~]# su - curshlinux
[curshlinux@localhost ~]$ dd if=/dev/zero of=./cheshi bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.172492 秒,608 MB/秒

10.使用touch dd 命令在/data目录下测试
[curshlinux@localhost ~]$ dd if=/dev/zero of=/data/cheshi bs=1M count=500
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: 写入"/data/cheshi" 出错: 超出磁盘限额
记录了101+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.119916 秒,874 MB/秒
shlinux@localhost ~]$ touch /data{1..100}txt
[curshlinux@localhost ~]$ touch /data/{1..90}.txt
sdb1: warning, user file quota exceeded.

11.查看配额的使用情况:用户角度
[curshlinux@localhost ~]$ quota
Disk quotas for user curshlinux (uid 1001):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 102400* 81920 102400 6days 91* 80 100 6days


12.查看配额的使用情况:文件系统角度
[root@localhost ~]# repquota /data
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
curshlinux ++ 102400 81920 102400 6days 91 80 100 6days