Recovery of lvm metadata in case of mishaps while modifying partition or corruption
root@myserver:~# apt install lvm2
root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg
# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021
contents = "Text Format Volume Group"
version = 1
description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"
creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64
creation_time = 1628088870 # Wed Aug 4 14:54:30 2021
root@myserver:~# head /root/lvm/archive/SIEM-vg_00002-106947711.vg -n 40
# Generated by LVM2 version 2.03.07(2) (2019-11-30): Wed Aug 4 14:54:30 2021
contents = "Text Format Volume Group"
version = 1
description = "Created *before* executing 'lvextend -l +100%FREE /dev/SIEM-vg/data'"
creation_host = "MC-UKHC1-LPSH-MAP" # Linux MC-UKHC1-LPSH-MAP 5.4.0-65-generic #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021 x86_64
creation_time = 1628088870 # Wed Aug 4 14:54:30 2021
SIEM-vg {
id = "fKhTFb-Uyy5-gnKu-R6Dv-keXh-73xZ-mRj31X"
seqno = 4
format = "lvm2" # informational
status = ["RESIZEABLE", "READ", "WRITE"]
flags = []
extent_size = 8192 # 4 Megabytes
max_lv = 0
max_pv = 0
metadata_copies = 0
physical_volumes {
pv0 {
id = "wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA"
device = "/dev/sda4" # Hint only
status = ["ALLOCATABLE"]
flags = []
dev_size = 156342272 # 74.5498 Gigabytes
pe_start = 2048
pe_count = 19084 # 74.5469 Gigabytes
}
pv1 {
id = "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd"
device = "/dev/sdb" # Hint only
status = ["ALLOCATABLE"]
flags = []
...
root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc
WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.
WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.
Cannot use /dev/sdc: device is partitioned
root@myserver:~# sfdisk -l /dev/sdc
Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: D174C1CF-EC08-42F9-A7E6-F9B838671444
root@myserver:~# sfdisk -d /dev/sdc >> sdcparttablebackup
root@myserver:~# cat sdcparttablebackup
label: gpt
label-id: D174C1CF-EC08-42F9-A7E6-F9B838671444
device: /dev/sdc
unit: sectors
first-lba: 34
last-lba: 4294967262
sector-size: 512
root@myserver:~# gdisk /dev/sdc
Command (? for help): x
z zap (destroy) GPT data structures and exit
Expert command (? for help): z
About to wipe out GPT on /dev/sdc. Proceed? (Y/N): Y
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): Y
root@myserver:~# pvcreate --uuid "FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" --restorefile /root/lvm/archive/SIEM-vg_00002-106947711.vg /dev/sdc
WARNING: Couldn't find device with uuid wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA.
WARNING: Couldn't find device with uuid FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd.
Physical volume "/dev/sdc" successfully created.
root@myserver:~# pvscan
WARNING: PV /dev/sdc in VG SIEM-vg is missing the used flag in PV header.
PV /dev/sdb4 VG SIEM-vg lvm2 [<74.55 GiB / 0 free]
PV /dev/sdc VG SIEM-vg lvm2 [<1024.00 GiB / 0 free]
Total: 2 [1.07 TiB] / in use: 2 [1.07 TiB] / in no VG: 0 [0 ]
root@myserver:~# vgcfgrestore -f /root/lvm/backup/SIEM-vg SIEM-vg
Volume group SIEM-vg has active volume: app.
WARNING: Found 1 active volume(s) in volume group "SIEM-vg".
Restoring VG with active LVs, may cause mismatch with its metadata.
Do you really want to proceed with restore of volume group "SIEM-vg", while 1 volume(s) are active? [y/n]: y
Restored volume group SIEM-vg.
root@myserver:~# blkid
/dev/sda3: UUID="dfc2bdb0-6f36-470a-9dfc-c98924b332b1" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5e192eda-6b4c-4fa0-ae8d-8a53d91020ad"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/sdb2: UUID="43abf87d-d093-4a77-a3b6-e1faab8d0c65" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="9ddcbbe8-dca3-4236-9612-569eb7e13da0"
/dev/sdb3: UUID="3d066f7e-9ca3-46d7-afd0-021373bdb159" TYPE="swap" PARTUUID="a46bf250-cd06-4d6b-a965-1215d3610e73"
/dev/sdb4: UUID="wKDxJk-B5tL-cMZH-aPNW-1FyP-8KAy-ozWwQA" TYPE="LVM2_member" PARTUUID="1f7270a4-0caa-4025-9d3c-2fae2a801ef0"
/dev/sda2: UUID="B474-DDD0" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="d413ec6f-39c4-47d2-8a5b-06b48847f215"
/dev/mapper/SIEM--vg-app: UUID="ac421fd4-dd0f-4aa0-874b-ae4a6554ff96" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sdb1: PARTUUID="a95b528d-a529-4ea8-92de-ea8b46fd67f3"
/dev/sdc: UUID="FcTEwf-MIY9-0zcd-3T4B-hLBl-Ybfm-DZeRLd" TYPE="LVM2_member"
/dev/sda1: PARTUUID="18b705bc-4c32-4391-ab95-0b47ab67e831"
root@myserver:~# vgchange -ay SIEM-vg
2 logical volume(s) in volume group "SIEM-vg" now active
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 7F434980-3FBB-4D7D-9770-F446936F74FE
Device Start End Sectors Size Type
/dev/sdb1 2048 63487 61440 30M BIOS boot
/dev/sdb2 63488 37746687 37683200 18G EFI System
/dev/sdb3 37746688 53370879 15624192 7.5G Linux swap
/dev/sdb4 53370880 209713151 156342272 74.5G Linux LVM
Disk /dev/sdc: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: Virtual Disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 12D18C3D-9E89-4B69-8FB3-E163A97BD783
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 1054719 1050624 513M EFI System
/dev/sda3 1054720 209713151 208658432 99.5G Linux filesystem
Disk /dev/mapper/SIEM--vg-app: 18.63 GiB, 19998441472 bytes, 39059456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/SIEM--vg-data: 1.05 TiB, 1159553089536 bytes, 2264752128 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
root@myserver:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb4 SIEM-vg lvm2 a-- <74.55g 0
/dev/sdc SIEM-vg lvm2 a-- <1024.00g 0
root@myserver:~# pvre
pvremove pvresize
root@myserver:~# pvresize -t /dev/sdc
TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
Physical volume "/dev/sdc" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
No comments:
Post a Comment