lvm之vg缩容

lvm技术主要用于系统盘,一般不会进行vg缩容操作,

但也不排除有例外情况,这种时候需要咋操作?

注:严重怀疑市面上某些不愿让人看到底层操作系统的存储设备,其底层运用的就是类似的技术,或者压根儿就是lvm2。

 

移除不是用pvremove命令直接移除就行,因为要移除的硬盘上很有可能有数据存在,所以移除前需要把硬盘上的数据转移到其他硬盘,转移成功后在移除。步骤如下:

1,先查看硬盘上是否有PE被用
-------------------------------------------------------------------------
root@debian:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vg0 lvm2 a-- 2.00g 1020.00m
/dev/sdb2 vg0 lvm2 a-- 3.00g 0 #/dev/sdb上有2个分区都存在PE,因为PFree小于PSize
/dev/sdc vg0 lvm2 a-- 5.00g 4.99g

root@debian:~# pvdisplay -m      #更直观的查看
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 255
Allocated PE 256          #以用PE数
PV UUID Q9L0el-2PXV-bLy4-eVck-MsWm-1bBL-ODGByA

--- Physical Segments ---
Physical extent 0 to 255:
Logical volume /dev/vg0/lvol0      #PV被lvol0占用一部份
Logical extents 0 to 255
Physical extent 256 to 510:
FREE

--- Physical volume ---
PV Name /dev/sdb2
VG Name vg0
PV Size 3.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 767
Free PE 0
Allocated PE 767         #以用PE数
PV UUID zMP4oN-GbB2-h2Xg-Ksxi-KM94-hesj-s3s3FA

--- Physical Segments ---
Physical extent 0 to 255:
Logical volume /dev/vg0/lv0      #PV被lv0占用一部份
Logical extents 0 to 255
Physical extent 256 to 511:
Logical volume /dev/vg0/lv1      #PV被lv1占用一部份
Logical extents 0 to 255
Physical extent 512 to 766:
Logical volume /dev/vg0/lv0      #PV被lv0占用一部份
Logical extents 256 to 510

--- Physical volume ---
PV Name /dev/sdc
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1278        #可用PE数
Allocated PE 1
PV UUID sApAs0-0s6C-02Tb-Y70L-PDkZ-ZxRG-o4zaJK

--- Physical Segments ---
Physical extent 0 to 513:
FREE
Physical extent 514 to 514:
Logical volume /dev/vg0/lv0
Logical extents 511 to 511
Physical extent 515 to 1278:
FREE

root@debian:~#
-------------------------------------------------------------------------
通过pvdisplay -m 命令可以更直观的查看PE的使用情况, /dev/sdb硬盘两个分区一共被占用了256+767=1023个PE,而/dev/sdc有1278个可用的PE,同时三个PV在同一个
卷组vg0中,所以我们可以通过命令pvmove把物理卷/dev/sdb1和/dev/sdb2中的PE转移到同卷组中的/dev/sdc物理卷中,如果物理卷中没有剩余PE请添加PV扩充PE。


2,通过命令pvmove把物理卷中的PE转移到同卷组中其他的物理卷中
-------------------------------------------------------------------------
root@debian:~# pvmove /dev/sdb1 /dev/sdc           #将/dev/sdb1中以用的PE转移到 /dev/sdc中
/dev/sdb1: Moved: 16.41%
root@debian:~# pvmove -v /dev/sdb2 /dev/sdc       #将/dev/sdb2中以用的PE转移到 /dev/sdc中,同时显示详细过程
Cluster mirror log daemon is not running.
Wiping internal VG cache
Wiping cache of LVM-capable devices
Archiving volume group "vg0" metadata (seqno 53).
Creating logical volume pvmove0
Moving 511 extents of logical volume vg0/lv0
Moving 256 extents of logical volume vg0/lv1
activation/volume_list configuration setting not defined: Checking only host tags for vg0/lv0.
activation/volume_list configuration setting not defined: Checking only host tags for vg0/lv1.
Setting up pvmove in on-disk volume group metadata.
Creating vg0-pvmove0
Loading vg0-pvmove0 table (254:3)
Loading vg0-lv0 table (254:1)
Loading vg0-lv1 table (254:2)
Suspending vg0-lv0 (254:1) with device flush
Suspending vg0-lv1 (254:2) with device flush
activation/volume_list configuration setting not defined: Checking only host tags for vg0/pvmove0.
Resuming vg0-pvmove0 (254:3)
Loading vg0-pvmove0 table (254:3)
Suppressed vg0-pvmove0 (254:3) identical table reload.
Resuming vg0-lv0 (254:1)
Resuming vg0-lv1 (254:2)
Creating volume group backup "/etc/lvm/backup/vg0" (seqno 54).
Checking progress before waiting every 15 seconds.
/dev/sdb2: Moved: 1.30%
/dev/sdb2: Moved: 33.38%
/dev/sdb2: Moved: 66.62%
/dev/sdb2: Moved: 100.00%
Polling finished successfully.

root@debian:~# pvdisplay -m
--- Physical volume ---
PV Name /dev/sdb1
VG Name vg0
PV Size 2.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 511
Free PE 511
Allocated PE 0            #/dev/sdb1中没有占用的PE,转移成功
PV UUID Q9L0el-2PXV-bLy4-eVck-MsWm-1bBL-ODGByA

--- Physical Segments ---
Physical extent 0 to 510:
FREE

--- Physical volume ---
PV Name /dev/sdb2
VG Name vg0
PV Size 3.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 767
Free PE 767
Allocated PE 0            #/dev/sdb2中没有占用的PE,转移成功
PV UUID zMP4oN-GbB2-h2Xg-Ksxi-KM94-hesj-s3s3FA

--- Physical Segments ---
Physical extent 0 to 766:
FREE

--- Physical volume ---
PV Name /dev/sdc
VG Name vg0
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 255
Allocated PE 1024
PV UUID sApAs0-0s6C-02Tb-Y70L-PDkZ-ZxRG-o4zaJK

--- Physical Segments ---        #全部转移到/dev/sdc 中
Physical extent 0 to 255:
Logical volume /dev/vg0/lv0
Logical extents 0 to 255
Physical extent 256 to 511:
Logical volume /dev/vg0/lv1
Logical extents 0 to 255
Physical extent 512 to 513:
FREE
Physical extent 514 to 514:
Logical volume /dev/vg0/lv0
Logical extents 511 to 511
Physical extent 515 to 770:
Logical volume /dev/vg0/lvol0
Logical extents 0 to 255
Physical extent 771 to 1025:
Logical volume /dev/vg0/lv0
Logical extents 256 to 510
Physical extent 1026 to 1278:
FREE

root@debian:~#

-------------------------------------------------------------------------

 

3,通过命令vgreduce 删除卷组中的物理卷
-------------------------------------------------------------------------
root@debian:~# vgreduce vg0 /dev/sdb1 /dev/sdb2      #删除卷组中的2个物理卷
Removed "/dev/sdb1" from volume group "vg0"
Removed "/dev/sdb2" from volume group "vg0"

root@debian:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 2.00g 2.00g                #删除成功
/dev/sdb2 lvm2 --- 3.00g 3.00g
/dev/sdc vg0 lvm2 a-- 5.00g 1020.00m
root@debian:~#
-------------------------------------------------------------------------

4,通过命令pvremove删除物理卷
-------------------------------------------------------------------------
root@debian:~# pvremove /dev/sdb1 /dev/sdb2         #删除连个物理卷
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdb2" successfully wiped.
-------------------------------------------------------------------------
root@debian:~# pvs
PV VG Fmt Attr PSize PFree            #删除成功
/dev/sdc vg0 lvm2 a-- 5.00g 1020.00m
root@debian:~#

posted @ 2023-01-11 15:25  咿呀哒喏  阅读(701)  评论(0编辑  收藏  举报