您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關LVM中怎么恢復已刪除的物理卷,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Centos8
下面使用了/dev/sd[a-c]
三塊磁盤,將他們劃入一個卷組,創建兩個邏輯卷:
# 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[a-c]# Create LV[root@localhost ~]# lvcreate -L 25G -n lv_data vg_data[root@localhost ~]# lvcreate -L 25G -n lv_log vg_data
下面列出邏輯卷的分配使用信息:
[root@localhost ~]# pvs PV VG Fmt Attr PSize PFree /dev/nvme0n1p2 cl lvm2 a-- # vgs VG #PV #LV #SN Attr VSize VFree cl 1 2 0 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)
在根目錄創建兩個文件夾/data和/log,格式化邏輯卷,掛載邏輯卷,并存放一些數據:
[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 on devtmpfs 880M 0 880M 0% /dev tmpfs 897M 0 897M 0% /dev/shm tmpfs 897M 8.7M 888M 1% /run tmpfs 897M 0 897M 0% /sys/fs/cgroup /dev/mapper/cl-root 15G 1.9G 14G 13% / /dev/nvme0n1p1 976M 183M 726M 21% /boot tmpfs 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
這兩種情況是意外刪除的物理卷或發生故障的磁盤,通過運行pvremove命令刪除了任何一個物理卷,或者從虛擬機中移除某一塊物理磁盤。
下面從虛擬機中移除一塊物理磁盤:
重啟系統之后,發現不能掛載lv_data和lv_log邏輯卷了,/dev目錄中找不到vg_data
卷組。
如果該邏輯卷設置為開機自動啟動了,磁盤發生故障后,由于兩個邏輯卷無法掛載文件系統,因此重新引導不能進入系統。只能通過進入單用戶模式,并注釋fstab
配置文件里面和該邏輯卷相關的條目。
下面從虛擬機中添加一個新的物理磁盤,新添加的磁盤會變成/dev/sdc
[root@localhost ~]# lsblk -SNAME HCTL TYPE VENDOR MODEL REV TRAN sda 6:0:0:0 disk VMware, VMware Virtual S 1.0 spi sdb 6:0:2:0 disk VMware, VMware Virtual S 1.0 spi sdc 6:0:3:0 disk VMware, VMware Virtual S 1.0 spi sr0 3:0:0:0 rom NECVMWar VMware SATA CD01 1.00 sata
現在讓我們開始為已刪除的物理卷恢復元數據。當使用pvs,vgs,lvs命令時,它將警告缺少xxxxx UUID的設備之一。
只需復制UUID并使用grep查看存檔和備份。在進行重新引導之前,報告的UUID指的是/dev/sdb設備。
[root@localhost ~]# cat /etc/lvm/archive/vg_data_00002-1587647360.vg |grep -B 2 -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 = 2048 pe_count = 5119 # 19.9961 Gigabytes} [root@localhost ~]# cat /etc/lvm/backup/vg_data |grep -B 2 -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 = 2048 pe_count = 5119 # 19.9961 Gigabytes}
讓我們先使用pvcreate --test
進行試運行:
[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
選項,正式創建物理卷:
[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--
然后使用lvm的備份還原卷組。首先加入--test
試運行一下:
[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.
下面正式運行一下,去掉--test
選項:
[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.
如果卷組和邏輯卷未激活,請使用下面命令激活:
# 掃描卷組[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# 激活卷組vg_data[root@localhost ~]# vgchange -ay vg_data 2 logical volume(s) in volume group "vg_data" now active# 掃描邏輯卷[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
關于“LVM中怎么恢復已刪除的物理卷”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。