1 . The host increases 80G SCSI interface hard disk
[root@localhost ~]# fdisk -l /dev/sdb
Disk / dev / SDB : 85.9 GB , 85,899,345,920 bytes, 167.77216 million sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size ( logical / physical ) : 512 byte / 512 byte
I / O Size ( minimal / optimal ) : 512 byte / 512 byte
2 . Dividing each of three 20G primary partition
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Use of / dev / sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
The new disk label type? gpt
(parted) mkpart
Partition name? []? Sdb1
File system type? [ext2]? ext4
The starting point? 1
The end point? 20G
(parted) mkpart
Partition name? []? Sdb2
File system type? [ext2]? ext4
The starting point? 20G
The end point? 40G
(parted) mkpart
Partition name? []? Sdb3
File system type? [ext2]? ext4
The starting point? 40G
The end point? 60G
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 20.0GB 20.0GB sdb1
2 20.0GB 40.0GB 20.0GB sdb2
3 40.0GB 60.0GB 20.0GB sdb3
(parted) q
3 . Converting the three primary partitions of the physical volume ( the pvcreate ), physical volume scanning system
[root@localhost ~]# pvcreate /dev/sdb[123] && pvscan
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdb2" successfully created
Physical volume "/dev/sdb3" successfully created
PV /dev/sda2 VG centos lvm2 [39.51 GiB / 44.00 MiB free]
PV /dev/sdb3 lvm2 [18.63 GiB]
PV /dev/sdb1 lvm2 [18.62 GiB]
PV /dev/sdb2 lvm2 [18.63 GiB]
Total: 4 [95.39 GiB] / in use: 1 [39.51 GiB] / in no VG: 3 [55.88 GiB]
4 . Two physical volumes to create a volume group, the name for myvg , view the volume group size
[root@localhost ~]# vgcreate myvg /dev/sdb[12] && vgdisplay myvg
Volume group "myvg" successfully created
--- 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 37.25 GiB
PE Size 4.00 MiB
Total PE 9535
Alloc PE / Size 0 / 0
Free PE / Size 9535 / 37.25 GiB
VG UUID 3jCBJr-GfnR-XJW3-4hOV-URK2-LbLu-h7judn
5 . Create a logical volume mylv , size 30G
[root@localhost ~]# lvcreate -L 30G -n mylv myvg && lvdisplay /dev/myvg/mylv
Logical volume "mylv" created.
--- Logical volume ---
LV Path / dev / myvg / mylv
LV Name mylv
VG Name myvg
LV UUID 9BZvSc-X4NN-LQU0-540r-sP6T-tYfk-1KSWEj
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2019-08-01 19:15:52 +0800
LV Status available
# open 0
LV Size 30.00 GiB
Current LE 7680
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
6 . The logical format to xfs file system, and mount it to / data on the directory, create a file test
[root@localhost ~]# mkfs.xfs /dev/myvg/mylv && mkdir /data && mount /dev/myvg/mylv /data && touch /data/1.txt
meta-data = / dev / myvg / mylv help = 256 agcount = 4, agsize = 1966080 blks
= sectsz=512 attr=2, projid32bit=1
Crc = 0 = 0 = finobt
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
[root@localhost ~]# ls /
bin boot ceshi data dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var web
[root@localhost ~]# ls /data
1.txt
7 . Logical Volume increased to 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 ~]# xfs_growfs /dev/myvg/mylv
meta-data = / dev / mapper / myvg mylv help = 256 agcount = 4, agsize = 1966080 blks
= sectsz=512 attr=2, projid32bit=1
Crc = 0 = 0 = finobt
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7864320 to 9175040
[root@localhost ~]# df -hT
File System Types Capacity Used Available Used % loading point
/dev/mapper/centos-root xfs 38G 4.8G 33G 13% /
devtmpfs devtmpfs 481M 0 481M 0% /dev
tmpfs tmpfs 490M 80K 490M 1% /dev/shm
tmpfs tmpfs 490M 7.1M 483M 2% /run
tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 107M 391M 22% /boot
/dev/mapper/myvg-mylv xfs 35G 33M 35G 1% /data
8 . Edit / etc / fstab file to mount logical volumes, disk quotas and support options
[root@localhost ~]# echo "/dev/myvg/mylv /data xfs defaults,usrquota,grpquota 0 0">> /etc/fstab && tail -1 /etc/fstab
/dev/myvg/mylv /data xfs defaults,usrquota,grpquota 0 0
9 . Create a disk quota, crushlinux user / data directory under the file size of the soft limit is 80M , the hard limit for the 100M ,
crushlinux user / data directory soft limit the number of files to 80 th, a hard limit of 100 th.
[root@localhost ~]# umount /data
[root@localhost ~]# mount -a
root@localhost ~]# quotacheck -auvg
quotacheck: Skipping /dev/mapper/myvg-mylv [/data]
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.
[root@localhost ~]# quotaon -auvg
[root@localhost ~]# edquota -u crushlinux
Disk quotas for user crushlinux (uid 1002):
Filesystem blocks soft hard inodes soft hard
/ Dev / folders / myvg-mylv 0 819200 102400 0 80 100
10. Use touch dd command / data test directory
[crushlinux@localhost data]$ dd if=/dev/zero of=/1.txt bs=1M count=110
dd: Open the "/1.txt" failed : insufficient privileges
[crushlinux@localhost data]$ touch {1..101}.txt
touch: Unable to create "101.txt": out of disk quota
11 . View usage quotas: a user's perspective
[root@localhost ~]# quota -uvs
Disk quotas for user root (uid 0):
Filesystem space quota limit grace files quota limit grace
/ Dev / folders / myvg-mylv
0K 0K 0K 3 0 0
12 . View usage quotas: file system perspective
[root@localhost ~]# repquota -auvs
*** Report for user quotas on device /dev/mapper/myvg-mylv
Block grace time: 7days; Inode grace time: 7days
Space limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 0K 0K 0K 3 0 0
crushlinux -- 0K 0K 0K 0 80 100
*** Status for user quotas on device /dev/mapper/myvg-mylv
Accounting: ON; Enforcement: ON
Inode: #132 (2 blocks, 2 extents)
[root@localhost ~]# cat peie.sh
#!/bin/sbin
echo "n
p
+20G
n
p
+20G
n
p
+20G
p
w" | fdisk /dev/sdb
pvcreate /dev/sdb[12]
prscan
vgcreate myvg /dev/sdb[12]
vgdisplay
lvcreate -y -L 30G -n mylv myvg
lvdisplay /dev/myvg/mylv
the mkfs.xfs / dev / myvg / mylv
IF [-d "/ data"!]; the then
mkdir / data
Mount / dev / myvg / mylv / data
the else
echo "data directory exists, can be hung!"
Mount / dev / myvg / mylv / Data
Fi
touch /data/1.txt
IF [-f "/data/1.txt"]; the then
"! Mount success" echo
the else
echo "failed to mount"
fi
lvextend -L +5G /dev/myvg/mylv
xfs_growfs /dev/myvg/mylv
df -hT
echo "/dev/myvg/mylv /data xfs defaults,usrquota,grpquota 1 0">> /etc/fstab
tail -1 /etc/fstab
[root@localhost ~]# cat deljuan.sh
#!/bin/sbin
umount / data
lvremove -y / dev / myvg / mylv
vgremove -and myvg
pvremove -y / dev / sdb [12]
echo "d
d
d
p
w" | fdisk /dev/sdb
IF [-d "/ Data"]; the then
RM -fr / Data
the else
echo "! Data directory does not exist"
Fi