怎么刪除LVM中PV物理卷
怎么刪除LVM中PV物理卷
LVM通常用于裝備大量磁盤的系統(tǒng),今天學(xué)習(xí)啦小編要給大家介紹的是Linux如何刪除LVM中的硬盤或分區(qū),一起來學(xué)習(xí)下吧。
怎么刪除LVM中PV物理卷
一、由于硬盤或者分區(qū)的操作方式其實(shí)都一樣,所以我這里就以分區(qū)為例。
二、/home分區(qū)2.6G,由如下pv組成:
/dev/sda5 100M
/dev/sda6 200M
/dev/sda7 300M
/dev/sda8 400M
/dev/sda9 500M
/dev/sda10 600M
/dev/sda11 500M
很碎對吧?^_^因?yàn)闇y試。
三、隨機(jī)寫了一堆文件進(jìn)去,用量達(dá)到了2G,空閑500M
四、準(zhǔn)備將sda6這個200M的PV卸掉(卸掉的容量必須小于空閑容量)
好了開始具體操作了。
卸載分區(qū)(縮小操作必須卸載才能進(jìn)行):
umount /home
縮小分區(qū):
e2fsck -f /dev/liuhg_disk/home
resize2fs /dev/liuhg_disk/home 2200M
首先將分區(qū)縮小到2200M這是為了給sda6騰出空間,sda6為200M,而我騰出了400M,因此應(yīng)該是足夠的。
縮小邏輯卷:
lvreduce -L 2200M /dev/liuhg_disk/home
分區(qū)縮小了用到的邏輯卷也要隨著縮小,并查看PV使用的狀態(tài):
pvdisplay -m
顯示如下:
--- Physical volume ---
PV Name /dev/sda5
VG Name liuhg_disk
PV Size 103.26 MiB / not usable 3.26 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25
Free PE 0
Allocated PE 25
PV UUID 5lnx52-b4jc-OOfZ-f2QA-ttdQ-DZeD-Ce3rb3
--- Physical Segments ---
Physical extent 0 to 24:
Logical volume /dev/liuhg_disk/home
Logical extents 0 to 24
--- Physical volume ---
PV Name /dev/sda6
VG Name liuhg_disk
PV Size 203.92 MiB / not usable 3.92 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 50
Free PE 0 <-----太悲劇了,sda6里寫滿了數(shù)據(jù)一點(diǎn)不剩
Allocated PE 50 <-----這50PE的數(shù)據(jù)要挪走才行,否則數(shù)據(jù)就丟了,并且存放的地方也必須是連續(xù)的至少50PE
PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK
--- Physical Segments ---
Physical extent 0 to 49:
Logical volume /dev/liuhg_disk/home
Logical extents 25 to 74
--- Physical volume ---
PV Name /dev/sda7
VG Name liuhg_disk
PV Size 305.89 MiB / not usable 1.89 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 76
Free PE 76 <---這個分區(qū)有76個空余,因此預(yù)計(jì)裝那50個是不會有問題的
Allocated PE 0
PV UUID 9CFnlx-CAEw-CSul-Rig9-FiCN-zK0a-oGmTEP
--- Physical Segments ---
Physical extent 0 to 75:
FREE
--- Physical volume ---
PV Name /dev/sda8
VG Name liuhg_disk
PV Size 407.87 MiB / not usable 3.87 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 101
Free PE 60
Allocated PE 41
PV UUID X0I8p0-x2xr-2xLG-QQD4-jbtS-3C4i-xPn4Bl
--- Physical Segments ---
Physical extent 0 to 40:
Logical volume /dev/liuhg_disk/home
Logical extents 471 to 511
Physical extent 41 to 100:
FREE
--- Physical volume ---
PV Name /dev/sda9
VG Name liuhg_disk
PV Size 509.84 MiB / not usable 1.84 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 127
Free PE 0
Allocated PE 127
PV UUID avJQaA-oMKt-NEoJ-ojBK-2Csc-1dca-1mh6Ue
--- Physical Segments ---
Physical extent 0 to 126:
Logical volume /dev/liuhg_disk/home
Logical extents 225 to 351
--- Physical volume ---
PV Name /dev/sda10
VG Name liuhg_disk
PV Size 603.98 MiB / not usable 3.98 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 150
Free PE 0
Allocated PE 150
PV UUID JlMIAF-A49n-M6HA-ZLXf-d8nS-pfZr-YeQsKT
--- Physical Segments ---
Physical extent 0 to 149:
Logical volume /dev/liuhg_disk/home
Logical extents 75 to 224
--- Physical volume ---
PV Name /dev/sda11
VG Name liuhg_disk
PV Size 478.47 MiB / not usable 2.47 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 119
Free PE 0
Allocated PE 119
PV UUID xnHJNA-tDVx-dryX-KM1x-g96Y-sptI-9iUOcU
--- Physical Segments ---
Physical extent 0 to 118:
Logical volume /dev/liuhg_disk/home
Logical extents 352 to 470
將sda6設(shè)置為離線狀態(tài):
pvchange -xn /dev/sda6
使用pvdisplay -m
顯示如下:
……
--- Physical volume ---
PV Name /dev/sda6
VG Name liuhg_disk
PV Size 203.92 MiB / not usable 3.92 MiB
Allocatable NO <-----表示已經(jīng)關(guān)閉了該P(yáng)V
PE Size 4.00 MiB
Total PE 50
Free PE 0
Allocated PE 50
PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK
……
將sda6的數(shù)據(jù)移走:
pvmove -i 1 /dev/sda6
-i 1是每1秒鐘報(bào)告一次數(shù)據(jù)遷移的進(jìn)度。
[root@liuhg /]# pvmove -i 1 /dev/sda6
/dev/sda6: Moved: 38.0%
/dev/sda6: Moved: 84.0%
/dev/sda6: Moved: 100.0%
重新用pvdisplay -m
顯示如下:
……
--- Physical volume ---
PV Name /dev/sda6
VG Name liuhg_disk
PV Size 203.92 MiB / not usable 3.92 MiB
Allocatable NO
PE Size 4.00 MiB
Total PE 50
Free PE 50 <----顯示完全空閑和Total PE數(shù)一致
Allocated PE 0
PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK
……
從卷組里把sda6刪除:
[root@liuhg /]# vgreduce liuhg_disk /dev/sda6
Removed "/dev/sda6" from volume group "liuhg_disk"
pvdisplay -m再看看吧:
--- NEW Physical volume --- <-----還告訴你這是一個新的PV ^_^
PV Name /dev/sda6
VG Name <-----空了
PV Size 203.92 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK
到此vgdisplay -v能看到已經(jīng)沒有了/dev/sda6了。重新掛載/home
[root@liuhg /]# mount /dev/liuhg_disk/home /home
[root@liuhg /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.0G 546M 1.3G 30% /
tmpfs 504M 0 504M 0% /dev/shm
/dev/mapper/liuhg_disk-home
2.2G 1.8G 42M 98% /home
進(jìn)去看看數(shù)據(jù),一個都沒丟。
上面就是Linux刪除LVM中的PV物理卷(硬盤或分區(qū))的介紹了,如果你在系統(tǒng)中安裝了LCM,而又不知道如何刪除其中的PV物理卷的話,可以試試文中介紹的方法。