Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to restore deleted physical volumes in LVM

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to restore deleted physical volumes in LVM. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

System environment

Centos8

Existing file system

The following uses / dev/sd [amurc] three disks, divides them into a volume group, and creates two logical volumes:

# Create pv [root@localhost ~] # pvcreate / dev/sda [root@localhost ~] # pvcreate / dev/sdb [root@localhost ~] # pvcreate / dev/sdc# Create VG [root@localhost ~] # vgcreate vg_data / dev/sd [Amurc] # Create LV [root@localhost ~] # lvcreate-L 25G-n lv_data vg_ data [root @ localhost ~] # lvcreate-L 25G-n lv_log vg_data

The allocation usage information for logical volumes is listed below:

[root@localhost] # pvs PV VG Fmt Attr PSize PFree / dev/nvme0n1p2 cl lvm2 Amuri-# vgs VG # PV # LV # SN Attr VSize VFree cl 120 wz--n- # lvs-a-o + devices LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert Devices root cl-wi-ao 15.00g / dev/nvme0n1p2 (512) swap cl-wi-ao---- 2.00g / dev/nvme0n1p2 (0) lv_data vg_data-wi-a- 25.00g / dev/sda (0) lv_data vg_data-wi-a- 25.00g / dev/sdb (0) lv_log vg_data-wi-a- 25.00g / dev/sdc (0) lv_log vg_data-wi-a- 25.00g / dev/sdb (1281)

Create two folders / data and / log in the root directory, format the logical volume, mount the logical volume, and store some data:

[root@localhost ~] # mkdir / data/ logs [root@localhost ~] # mkfs.xfs / dev/vg_data/lv_ data [root @ localhost ~] # mkfs.xfs / dev/vg_data/lv_ log [root @ localhost ~] # mount / dev/vg_data/lv_data / data [root@localhost ~] # mount / dev/vg_data/lv_log / data [root@localhost ~] # df-hFilesystem Size Used Avail Use% Mounted ondevtmpfs 880m 0880M 0% / devtmpfs 897M 0897M 0% / dev/shmtmpfs 897M 8.7M 888M 1% / runtmpfs 897M 0897M 0% / sys/fs/cgroup/dev/mapper/cl-root 15G 1.9G 14G 13% / / dev/nvme0n1p1 976m 183M 726M 21% / boottmpfs 180M 0 180M 0% / run/user/0/dev/mapper/vg_data-lv_log 25G 211M 25G 1% / data [root@localhost ~] # touch / data/file {1.. 10} .txt [root@localhost ~] # touch / logs/text {1.. 10} .log sets the disk as failed or deletes the disk

In both cases, a physical volume is accidentally deleted or a failed disk is deleted, any physical volume is deleted by running the pvremove command, or a physical disk is removed from the virtual machine.

The following removes a physical disk from the virtual machine:

After rebooting the system, it was found that the lv_data and lv_log logical volumes could not be mounted, and the vg_data volume group could not be found in the / dev directory.

If the logical volume is set to boot automatically, after a disk failure, the reboot cannot enter the system because the two logical volumes cannot mount the file system. You can only enter single-user mode and annotate the entries in the fstab configuration file related to the logical volume.

Add a new physical hard disk

Let's add a new physical disk from the virtual machine, and the newly added disk will become / dev/sdc

[root@localhost ~] # lsblk-SNAME HCTL TYPE VENDOR MODEL REV TRANsda 6 disk VMware 0 disk VMware, VMware Virtual S 1.0 spisdb 6 SNAME HCTL TYPE VENDOR MODEL REV TRANsda 0 disk VMware, 0 disk VMware, VMware Virtual S 1.0 spisdc 6, 0 disk VMware, VMware Virtual S 1.0 spisr0 3, 0 rom NECVMWar VMware SATA CD01 1.00 sata restore metadata for deleted physical volumes

Now let's start restoring metadata for deleted physical volumes. When you use the pvs,vgs,lvs command, it warns one of the devices that are missing xxxxx UUID.

Simply copy UUID and use grep to view archives and backups. Before rebooting, the reported UUID refers to the / dev/sdb device.

[root@localhost ~] # cat / etc/lvm/archive/vg_data_00002-1587647360.vg | grep-B2-A 9 "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD" pv1 {id = "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD" device = "/ dev/sdb" # Hint onlystatus = ["ALLOCATABLE"] flags = [] dev_size = 41943040 # 20 Gigabytespe_start = 2048pe_count = 5119 # 19.9961 Gigabytes} [root@localhost ~] # cat / etc/ Lvm/backup/vg_data | grep-B2-A 9 "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD" pv1 {id = "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD" device = "/ dev/sdb" # Hint onlystatus = ["ALLOCATABLE"] flags = [] dev_size = 41943040 # 20 Gigabytespe_start = 2048pe_count = 5119 # 19.9961 Gigabytes}

Let's first use pvcreate-- test for a trial run:

[root@localhost] # pvcreate-test-uuid "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD"-restorefile / etc/lvm/archive/vg_data_00002-1587647360.vg / dev/sdc TEST MODE: Metadata will NOT be updated and volumes will not be (de) activated. Couldn't find device with uuid l5rSrt-SRfc-KQNw-Tm29-gx4D-ihBw-Xzum3L. Couldn't find device with uuid v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD. Couldn't find device with uuid UYyDyH-vc6D-XbQ7-ga1X-DKeM-ObLe-tdBLxR. Physical volume "/ dev/sdc" successfully created.-test trial run-uuid is used to specify the UUID value of the newly created physical volume. If this option is not available, a random UUID is generated. The uid value specified in this lab is the uid value that was previously deleted from the physical volume. -restorefile reads the archive file generated by vgcfgbackup

Remove the-- test option to formally create a physical volume:

[root@localhost] # pvcreate-uuid "v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD"-restorefile / etc/lvm/archive/vg_data_00002-1587647360.vg / dev/sdc Couldn't find device with uuid l5rSrt-SRfc-KQNw-Tm29-gx4D-ihBw-Xzum3L. Couldn't find device with uuid v6wYGZ-0dGA-8ecB-kec8-r2zv-gCJi-gulSAD. Couldn't find device with uuid UYyDyH-vc6D-XbQ7-ga1X-DKeM-ObLe-tdBLxR. Physical volume "/ dev/sdc" successfully created. [root@localhost ~] # pvs PV VG Fmt Attr PSize PFree / dev/nvme0n1p2 cl lvm2 a Murray-recovery volume group

Then use lvm's backup to restore the volume group. First of all, add-- test for a trial run:

[root@localhost] # vgcfgrestore-- test-f / etc/lvm/backup/vg_data vg_data TEST MODE: Metadata will NOT be updated and volumes will not be (de) activated. Volume group vg_data has active volume: lv_log. Volume group vg_data has active volume: lv_data. WARNING: Found 2 active volume (s) in volume group "vg_data". Restoring VG with active LVs, may cause mismatch with its metadata.Do you really want to proceed with restore of volume group "vg_data", while 2 volume (s) are active? [y/n]: y Restored volume group vg_data.

Let's run it officially, and remove the-- test option:

[root@localhost] # vgcfgrestore-f / etc/lvm/backup/vg_data vg_data Volume group vg_data has active volume: lv_log. Volume group vg_data has active volume: lv_data. WARNING: Found 2 active volume (s) in volume group "vg_data". Restoring VG with active LVs, may cause mismatch with its metadata.Do you really want to proceed with restore of volume group "vg_data", while 2 volume (s) are active? [y/n]: y Restored volume group vg_data.

"if the volume group and logical volumes are not activated, activate using the following command:"

# scan volume group [root@localhost ~] # vgscan Reading all physical volumes. This may take a while... Found volume group "cl" using metadata type lvm2 Found volume group "vg_data" using metadata type lvm2# Activation Volume Group vg_ data [root @ localhost ~] # vgchange-ay vg_data 2 logical volume (s) in volume group "vg_data" now active# scan logical volume [root@localhost ~] # lvscan ACTIVE'/ dev/cl/swap' [2.00 GiB] inherit ACTIVE'/ dev/cl/root' [15.00 GiB] Inherit ACTIVE'/ dev/vg_data/lv_data' [25.00 GiB] inherit ACTIVE'/ dev/vg_data/lv_log' [25.00 GiB] inherit on "how to recover deleted physical volumes in LVM" is here. Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report