LVM之VG、PV误删除恢复方法
VG恢復
一、lvremove誤刪除vg卷組
lvremove vgname 會刪除vg下的所有pv,需要用archive記錄的元數據日志去恢復lv
[root@centos7 archive]# ll /etc/lvm/archive
total 40
-rw------- 1 root root 879 Sep 28 14:51 vg01_00000-1599738857.vg
-rw------- 1 root root 890 Sep 28 14:56 vg01_00001-1325802091.vg
-rw------- 1 root root 1285 Sep 28 15:13 vg01_00002-1209567998.vg
-rw------- 1 root root 1285 Sep 28 15:13 vg01_00003-2132380656.vg
-rw------- 1 root root 1285 Sep 28 15:21 vg01_00004-1884729932.vg
-rw------- 1 root root 1285 Sep 28 15:21 vg01_00005-762502250.vg
-rw------- 1 root root 1285 Sep 28 16:00 vg01_00006-354891781.vg
-rw------- 1 root root 1285 Sep 28 16:00 vg01_00007-1771763076.vg
-rw------- 1 root root 1285 Sep 28 16:54 vg01_00008-1631127841.vg
-rw------- 1 root root 1285 Sep 28 16:54 vg01_00009-1527369658.vg
二、通過vgcfgrestore結合元數據日志恢復vg
通過vgcfgrestore恢復vg下的lv
[root@centos7 archive]# vgcfgrestore -f /etc/lvm/archive/vg01_00009-1527369658.vg vg01
Restored volume group vg01
[root@centos7 archive]# vgs
VG #PV #LV #SN Attr VSize VFree
vg01 1 1 0 wz–n- <5.00g 508.00m
[root@centos7 archive]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 vg01 -wi------- 4.50g
[root@centos7 archive]#
PV恢復
一、故障詳情:在LVM環境中對PV進行parted mklabel,會破壞第二個扇區所記錄的labelone、pv-uuid信息,導致PV處于loss狀態。
二、模擬故障:
創建PV,記錄原Pv信息:
[root@centos7 ~]# pvcreate /dev/vdb
WARNING: dos signature detected on /dev/vdb at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/vdb.
Physical volume “/dev/vdb” successfully created
[root@centos7 ~]# parted /dev/vdb u s p
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10485760s
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
[root@centos7 ~]# wipefs /dev/vdb
offset type
0x218 LVM2_member [raid]
UUID: sDXsbb-zyG4-9Jwg-whVY-zjse-vNS8-tldfT8
[root@centos7 ~]# wipefs -a /dev/vdb
/dev/vdb: 8 bytes were erased at offset 0x00000218 (LVM2_member): 4c 56 4d 32 20 30 30 31
[root@centos7 ~]# pvdisplay
— Physical volume —
PV Name /dev/vdb
VG Name vg01
PV Size 5.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1279
Free PE 1279
Allocated PE 0
PV UUID vrtyiU-hnNe-kGwX-Pij3-LxUK-IgiW-ifmFge
[root@centos7 ~]# dd if=/dev/vdb bs=512 count=2|hexdump -C
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.00969323 s, 106 kB/s
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000200 4c 41 42 45 4c 4f 4e 45 01 00 00 00 00 00 00 00 |LABELONE…|
00000210 92 44 a7 57 20 00 00 00 4c 56 4d 32 20 30 30 31 |.D.W …LVM2 001|
00000220 76 72 74 79 69 55 68 6e 4e 65 6b 47 77 58 50 69 |vrtyiUhnNekGwXPi|
00000230 6a 33 4c 78 55 4b 49 67 69 57 69 66 6d 46 67 65 |j3LxUKIgiWifmFge|
00000240 00 00 00 40 01 00 00 00 00 00 10 00 00 00 00 00 |…@…|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000260 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |…|
00000270 00 f0 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000280 00 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 |…|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000400
模擬誤操作:
[root@centos7 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) p
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted) mklabel gpt
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) q
Information: You may need to update /etc/fstab.
查看被破壞后的磁盤頭記錄:
[root@centos7 ~]# dd if=/dev/vdb bs=512 count=2|hexdump -C
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0103813 s, 98.6 kB/s
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
000001c0 01 00 ee fe ff ff 01 00 00 00 ff ff 9f 00 00 00 |…|
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |…U.|
00000200 45 46 49 20 50 41 52 54 00 00 01 00 5c 00 00 00 |EFI PART…|
00000210 22 fb 34 f8 00 00 00 00 01 00 00 00 00 00 00 00 |“.4…|
00000220 ff ff 9f 00 00 00 00 00 22 00 00 00 00 00 00 00 |…”…|
00000230 de ff 9f 00 00 00 00 00 fc 86 1e b3 01 c2 6c 4a |…lJ|
00000240 a2 38 60 20 22 3c d2 c6 02 00 00 00 00 00 00 00 |.8` "<…|
00000250 80 00 00 00 80 00 00 00 86 d2 54 ab 00 00 00 00 |…T…|
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000400
pv、vg、lv都處于丟失狀態
[root@centos7 ~]# lvs
[root@centos7 ~]# pvs
[root@centos7 ~]# vgs
[root@centos7 ~]#
三、pvcreate 恢復PV:
因磁盤第二扇區lvm信息丟失,直接用pvcreate恢復pv會報錯,如下:
四、正確處理思路:
做好lvm原數據備份。(步驟2、3可嘗試用dd if=/zero of=/dev/vdb bs=512 count=2 iflag=direct代替,有一定幾率能成功修復,反之用2、3步驟。) 創建一個PV,指定原pv-uuid進行創建,在新的pv磁盤第二扇區會寫入相關信息. dd前1024字節到原物理盤(通過新建的pv恢復原磁盤頭lvm信息) pvcreate、vgcfgrestore恢復pv、vg、lv,詳細步驟如下:1.做好lvm元數據備份:cp -r /etc/lvm/ /etc/lvm.bak
2.新建PV并指定所需的pv-uuid
用一個新的塊設備創建vg構造第二扇區信息:
[root@centos7 backup]# pvcreate -ff --uuid vrtyiU-hnNe-kGwX-Pij3-LxUK-IgiW-ifmFge --restorefile /etc/lvm//backup/vg01 /dev/vdc
Couldn’t find device with uuid vrtyiU-hnNe-kGwX-Pij3-LxUK-IgiW-ifmFge.
Physical volume “/dev/vdc” successfully created.
[root@centos7 backup]# dd if=/dev/vdc bs=512 count=2|hexdump -C
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0136249 s, 75.2 kB/s
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000200 4c 41 42 45 4c 4f 4e 45 01 00 00 00 00 00 00 00 |LABELONE…|
00000210 7c b1 ee 56 20 00 00 00 4c 56 4d 32 20 30 30 31 ||…V …LVM2 001|
00000220 76 72 74 79 69 55 68 6e 4e 65 6b 47 77 58 50 69 |vrtyiUhnNekGwXPi|
00000230 6a 33 4c 78 55 4b 49 67 69 57 69 66 6d 46 67 65 |j3LxUKIgiWifmFge|
00000240 00 00 00 40 01 00 00 00 00 00 10 00 00 00 00 00 |…@…|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000260 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |…|
00000270 00 f0 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000280 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |…|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000400
[root@centos7 backup]#
3.把構造的信息輸出到一個文件,檢查無誤后覆蓋原磁盤丟失的信息
[root@centos7 backup]# dd if=/dev/vdc of=/opt/new_head_1024 bs=512 count=2
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0121184 s, 84.5 kB/s
[root@centos7 backup]# hexdump -C /opt/new_head_1024
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000200 4c 41 42 45 4c 4f 4e 45 01 00 00 00 00 00 00 00 |LABELONE…|
00000210 7c b1 ee 56 20 00 00 00 4c 56 4d 32 20 30 30 31 ||…V …LVM2 001|
00000220 76 72 74 79 69 55 68 6e 4e 65 6b 47 77 58 50 69 |vrtyiUhnNekGwXPi|
00000230 6a 33 4c 78 55 4b 49 67 69 57 69 66 6d 46 67 65 |j3LxUKIgiWifmFge|
00000240 00 00 00 40 01 00 00 00 00 00 10 00 00 00 00 00 |…@…|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000260 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |…|
00000270 00 f0 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000280 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |…|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000400
[root@centos7 backup]# dd if=/opt/new_head_1024 of=/dev/vdb bs=512 count=2 iflag=direct
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.0394598 s, 26.0 kB/s
[root@centos7 backup]#
驗證原磁盤前兩個扇區信息是否恢復
[root@centos7 backup]# dd if=/dev/vdb bs=512 count=2|hexdump -C
2+0 records in
2+0 records out
1024 bytes (1.0 kB) copied, 0.00719154 s, 142 kB/s
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000200 4c 41 42 45 4c 4f 4e 45 01 00 00 00 00 00 00 00 |LABELONE…|
00000210 7c b1 ee 56 20 00 00 00 4c 56 4d 32 20 30 30 31 ||…V …LVM2 001|
00000220 76 72 74 79 69 55 68 6e 4e 65 6b 47 77 58 50 69 |vrtyiUhnNekGwXPi|
00000230 6a 33 4c 78 55 4b 49 67 69 57 69 66 6d 46 67 65 |j3LxUKIgiWifmFge|
00000240 00 00 00 40 01 00 00 00 00 00 10 00 00 00 00 00 |…@…|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000260 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 |…|
00000270 00 f0 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
00000280 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |…|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |…|
*
00000400
[root@centos7 backup]#
確定原磁盤信息恢復后,刪除新建的pv,避免pv-uuid沖突。
恢復pv前要保證該節點上無客戶端使用相關lv(SAN存儲可選擇其它空閑節點或者拷貝元數據文件到一臺虛擬機上執行,本地存儲需要取消所有lv掛載),否則會出現以下報錯
4.然后進行pvcreate指定uuid和vg原數據進行恢復pv、vg和lv
[root@centos7 backup]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdc lvm2 — 5.00g 5.00g
[root@centos7 backup]# pvremove /dev/vdc
Labels on physical volume “/dev/vdc” successfully wiped.
[root@centos7 backup]# pvs
[root@centos7 backup]# pvcreate -ff --uuid vrtyiU-hnNe-kGwX-Pij3-LxUK-IgiW-ifmFge --restorefile /etc/lvm//ba^Cup/vg01 /dev/vdb
Couldn’t find device with uuid vrtyiU-hnNe-kGwX-Pij3-LxUK-IgiW-ifmFge.
Physical volume “/dev/vdb” successfully created.
[root@centos7 backup]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb lvm2 — 5.00g 5.00g
[root@centos7 backup]# vgs
[root@centos7 backup]#
[root@centos7 backup]# vgcfgrestore -f /etc/lvm/backup/vg01 vg01
Restored volume group vg01
[root@centos7 backup]# vgs
VG #PV #LV #SN Attr VSize VFree
vg01 1 1 0 wz–n- <5.00g 508.00m
[root@centos7 backup]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 vg01 -wi------- 4.50g
至此,pv已經恢復正常。
總結
以上是生活随笔為你收集整理的LVM之VG、PV误删除恢复方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对物联网方向的认识
- 下一篇: 极速office(word)里如何段落首