Linux advanced storage management (LVM, VDO)
1. Logical Volume (LVM)
Logical volume
pv ##Physical volume processed physical partitions for each
pe ##Physical expansion setting storage minimum unit for each drop of
vg ##Physical volume group bundling PV into a group
lv ##Logical volume allocation final use device points cup
lvm device establishment
开启监控
[root@d ~]# watch -n 1 "pvs;echo ====;vgs;echo =====;lvs;echo =====;df -H /westos"
[root@d ~]# fdisk /dev/vdb #管理分区 +1G t 8e
[root@d ~]# udevadm settle #同步分区表
[root@d ~]# blkid ##设备管理方式及设备id
[root@d ~]# pvcreate /dev/vdb1 ##创建pv
[root@d ~]# vgcreate westosvg /dev/vdb1 (-s 2M /dev/vdb1) ##创建vg -s设定pe大小位2M
[root@d ~]# lvcreate -L 100M -n westoslv westosvg ##创建lvm -L指定大小 -n指定名称
[root@d ~]# mkfs.xfs /dev/mapper/westosvg-westoslv ##格式化
[root@d ~]# mount /dev/westosvg/westoslv /westos ##挂载
lvm stretch
When the capacity in vg is sufficient
[root@d ~]# lvextend -L 500M /dev/westosvg/westoslv ##拉伸设备
[root@d ~]# xfs_growfs /dev/westosvg/westoslv ##拉伸文件系统,在rhel7中可以用设备或挂载点##在rhel8中只能用挂载点
resize2fs /dev/mapper/westosvg-westoslv ##当文件系统为ext时使用此命令
When the capacity in vg is insufficient
[root@d ~]# fdisk /dev/vdb #管理分区 +1G t 8e
[root@d ~]# pvcreate /dev/vdb2
[root@d ~]# vgextend westosvg /dev/vdb2
[root@d ~]# lvextend -L 1500M /dev/westosvg/westoslv
[root@d ~]# xfs_growfs /dev/westosvg/westoslv
lvm reduction
xfs文件系统不支持缩减ext文件系统可以
mkfs.ext4 /dev/westosvg/westoslv
ext4文件系统拉伸:
resize2fs /dev/mapper/westosvg-westoslv
[root@d ~]# umount /westos
[root@d ~]# mkfs.ext4 /dev/westosvg/westoslv
[root@d ~]# udevadm settle
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# lvextend -L 1800M /dev/westosvg/westoslv
[root@d ~]# umount /westos
[root@d ~]# e2fsck -f /dev/westosvg/westoslv
[root@d ~]# resize2fs /dev/westosvg/westoslv 500M
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# lvreduce -L 500M /dev/westosvg/westoslv
vg reduction
[root@d ~]# vgreduce westosvg /dev/vdb2
[root@d ~]# vgextend westosvg /dev/vdb2
[root@d ~]# pvmove /dev/vdb1 /dev/vdb2
[root@d ~]# vgreduce westosvg /dev/vdb1
[root@d ~]# pvremove /dev/vdb1
lvm delete
[root@d ~]# umount /westos
[root@d ~]# lvremove /dev/westosvg/westoslv-bak
[root@d ~]# lvremove /dev/westosvg/westoslv
[root@d ~]# vgremove westosvg
[root@d ~]# pvremove /dev/vdb2
Create a snapshot of lvm
[root@d ~]# cd /westos
[root@d westos]# ls
lost+found
[root@d westos]# touch file{1..3}
[root@d westos]# cd
[root@d ~]# umount /westos
[root@d ~]# cd /westos
[root@d westos]# ls
[root@d ~]# lvcreate -L 50M -n westoslv-bak -s /dev/westosvg/westoslv
[root@d ~]# mount /dev/westosvg/westoslv /westos
[root@d ~]# cd /westos
[root@d westos]# ls
file1 file2 file3 lost+found
[root@d westos]# rm -rf *
[root@d westos]# cd
[root@d ~]# umount /westos
[root@d ~]# lvremove /dev/westosvg/westoslv-bak
[root@d ~]# lvcreate -L 50M -n westoslv-bak -s /dev/westosvg/westoslv
[root@d ~]# mount /dev/westosvg/westoslv-bak /westos
[root@d ~]# cd /westos
[root@d westos]# ls
2. VDO (Virtual Data Optimizer)
The establishment of vdo equipment
dnf install vdo -y
vdo create --name=westos_vdo --device=/dev/vdb
vdo status --name=westos_vdo | less
Deduplication: enabled ##vdo检测并删除重复数据的功能时开启的
Compression: enabled ##vdo数据压缩功能开启
[root@d ~]# mkfs.xfs -K /dev/mapper/westos_vdo -f
[root@d ~]# blkid
[root@d ~]# mkdir /westos_vdo
[root@d ~]# mount /dev/mapper/westos_vdo /westos_vdo
[root@d ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/westos_vdo 10.0G 4.0G 6.0G 40% 98%
[root@d ~]# find / -size +100M
[root@d ~]# cp /usr/lib64/firefox/libxul.so /westos_vdo/file1
[root@d ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/westos_vdo 10.0G 4.0G 6.0G 40% 26%
[root@d ~]# cp /usr/lib64/firefox/libxul.so /westos_vdo/file2
[root@d ~]# vdostats --human-readable
Device Size Used Available Use% Space saving%
/dev/mapper/westos_vdo 10.0G 4.1G 5.9G 41% 72%
Deletion of vdo device
# man vdo
x-systemd.requires=vdo.service 0 0
# vim /etc/fstab
/dev/mapper/westos_vdo1 /westos xfs defaults,x-systemd.requires=vdo.service 0 0 ##开机自动挂载
[root@d ~]# vdo remove --name=westos_vdo