Linux高級存盤管理(LVM、VDO)
- 1.邏輯卷(LVM)
- 邏輯卷
- lvm設備建立
- lvm拉伸
- lvm縮減
- vg縮減
- lvm洗掉
- 建立lvm的快照
- 2.VDO(虛擬資料優化器)
- vdo設備的建立
- vdo設備的洗掉
1.邏輯卷(LVM)
邏輯卷
pv ##物理卷 被處理過的物理磁區 每一個
pe ##物理擴展 設定存盤最小單元 每一滴
vg ##物理卷組 捆綁pv到一個組中 大杯
lv ##邏輯卷 分配最終的使用設備 分杯

lvm設備建立
開啟監控
[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拉伸
當vg中的容量充足
[root@d ~]# lvextend -L 500M /dev/westosvg/westoslv ##拉伸設備
[root@d ~]# xfs_growfs /dev/westosvg/westoslv ##拉伸檔案系統,在rhel7中可以用設備或掛載點##在rhel8中只能用掛載點
resize2fs /dev/mapper/westosvg-westoslv ##當檔案系統為ext時使用此命令
當vg中的容量不足
[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縮減
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縮減
[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洗掉
[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
建立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(虛擬資料優化器)
vdo設備的建立
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%
vdo設備的洗掉
# 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/226995.html
標籤:其他
