The establishment of lvm
Establish an experimental environment and monitor with monitoring commands
mkdir /weixindata
watch -n 1 "df -h /weixindata;echo ===;pvs;echo =====;vgs;echo ===;lvs"
fdisk /dev/sdb Divide 3 primary partitions, and 2, 3 partition label is written as 8e (sticker lvm label) wq exit save
pvcreate /dev/sdb2
pvcreate /dev/sdb3 Create physical partition
vgcreate westos_vg0 /dev/sdb3 Pour orange juice into a large container
lvcreate -L 200M -n westos_
lv0 westos_vg0
mkfs.xfs /dev/westos_vg0/westos_lv0
mount /dev/westos_vg0/westos_lv0 /weixindata/ format the separated lvm logical volume to mount
Stretch a logical volume lvm
lvextend -L 500M /dev/westos_vg0/westos_lv0 stretch the size of lvm
xfs_growfs /weixindata/ The size of the synchronized file system
When the divided primary partition /dev/vdb1 is not enough (I want to stretch the lvm to 2500M), first divide a primary partition out of /dev/vdb2, and then stretch
pvcreate /dev/sdb2
vgextend westos_vg0 /dev/sdb2
lvextend -L 2500M /dev/westos_vg0/westos_lv0
xfs_growfs /weixindata/
Stretch and shrink the devices of the ext4 file system
1. Stretch
umount /weixindata
mkfs.ext4 /dev/westos_vg0/westos_lv0 format the device as ext4 file system
mount /dev/westos_vg0/westos_lv0 /weixindata/ mount
lvextend -L 2800M /dev/westos_vg0/westos_lv0 stretch
resize2fs /dev/westos_vg0/westos_lv0 stretch the file system
2. Reduce
umount /weixindata
e2fsck -f /dev/westos_vg0/westos_lv0 Scan the contents of this device, otherwise direct reduction will cause damage
resize2fs /dev/westos_vg0/westos_lv0 1500M Reduce file system
lvreduce -L 1500M /dev/westos_vg0/westos_lv0 Reduce the lvm device
mount /dev/westos_vg0/westos_lv0 /weixindata/
pvmove /dev/sdb3 /dev/sdb2 Move the things under /dev/vdb3 to /dev/vdb2, and then free /dev/vdb3
vgreduce westos_vg0 /dev/sdb3
pvremove /dev/sdb3
Create a snapshot of lvm
mount /dev/westos_vg0/westos_lv0 /weixindata/
touch /weixindata/file{1…10}
ls /weixindata/
umount /weixindata Unmount first and then take snapshot
ls /weixindata/
lvcreate -L 50M -n westos_lv0.bak -s /dev/westos_vg0/westos_lv0 take a snapshot
mount /dev/westos_vg0/westos_lv0.bak /weixindata/ mount snapshot
cd /weixindata/
ls
rm -fr *
umount /weixindata
lvremove /dev/westos_vg0/westos_lv0.bak
lvcreate -L 50M -n westos_lv0.bak -s /dev/westos_vg0/westos_lv0 Then take the photo again, remount the file to restore
mount /dev/westos_vg0/westos_lv0.bak /weixindata/
ls /weixindata/
How to delete lvm device failure
pvcreate /dev/sdb3
vgextend westos_vg0 /dev/sdb3
fdisk /dev/sdb
vgdisplay
pvs
vgreduce --removemissing westos_vg0
vgs
pvs
Deletion of LVM
umount /weixindata
lvremove /dev/westos_vg0/westos_lv0
vgremove westos_vg0
pvremove /dev/sdb2
fdisk /dev/sdb
partprobe
vdo virtual data optimizer
vdo build
vdo create --name=westos_vdo1 --device=/dev/sdb
vdo status --name=westos_vdo1 | less
Deduplication: enabled vdo to detect and delete duplicate data is enabled
Compression: enabled vdo data compression function is enabled
Use vdo device
mkfs.xfs -K /dev/mapper/westos_vdo1
mkdir /westos_vdo
mount /dev/mapper/westos_vdo1 /westos_vdo/
Test vdo performance
cp /westos/images/install.img / westos_vdo /
vdostats --human-readable
cp /westos/images/install.img /westos_vdo/install.img.1
vdostats --human-readable
Delete vdo
vdo remove --name=westos_vdo1