本文笔记了一次从已经崩溃的LVM文件系统中抢救数据的过程。
================================================================================
(1) 系统和操作环境
================================================================================
Old crashed system environment(旧系统中有两个磁盘):
/dev/hda1 pv0 VolGroup00 LogVol00
/dev/hdb1 pv1 VolGroup00 LogVol00
New recover system environment(将旧磁盘挂到一个抢救环境之中):
/dev/hda1 pv0 VolGroup00 LogVol00
/dev/hdb1 pv0 VolGroup01 LogVol00 <<< old hda1
/dev/hdc1 pv1 VolGroup01 LogVol00 <<< old hdb1
================================================================================
(2) Retrieve old system’s LVM configuration(VGDA – Volume Group Descriptor Area)
================================================================================
Retrieve partition table from hard disk device(复制旧磁盘的分区表):
# sfdisk -d /dev/hdb > /tmp/hdb.pt
# sfdisk -d /dev/hdc > /tmp/hdc.pt
Retrieve(复制旧磁盘的头部,可用以读取旧的LVM的配置信息):
# dd if=/dev/hdb bs=512 count=255 skip=1 of=/tmp/hdb.bs
# dd if=/dev/hdc bs=512 count=255 skip=1 of=/tmp/hdc.bs
Note: the LVM configuration may be saved in several location.
Search keyword “VolGroup” in partition table(all VGDA are same in PVs):
# less /tmp/hdb.bs
# less /tmp/hdc.bs
(读取和查找LVM的配置信息,然后复制其内容,建立一个抢救文件,以供恢复使用)
Create LVM configuration file for restoring later(根据读取结果,创建一个LVM配置):
Please refer the current LVM configuration settings(可参考目前的LVM配置文件格式):
You can get the configuration with command vgcfgbackup(备份命令建立一个LVM配置):
# vgcfgbackup -d -v VolGroup00 –file /tmp/VolGroup00.bak;
********************************************************************************
如下是本次的抢救文件内容,因为抢救系统本身也使用LVM,所以需要手工修改部分名称。
********************************************************************************
vim /tmp/VolGroup01.save; #Change VG name and device if need;
——————————————————————————–
contents = “Text Format Volume Group”
version = 1
description = “”
creation_host = “localhost.localdomain”
creation_time = 1258044126 # Thu Nov 12 16:42:06 2008
VolGroup01 {
id = “SRrnnD-aKdW-bzvR-4YHU-LaEb-ZDuU-B7njtu”
seqno = 2
status = [“RESIZEABLE”, “READ”, “WRITE”]
flags = []
extent_size = 65536
max_lv = 0
max_pv = 0
physical_volumes {
pv0 {
id = “WX8RyD-cDou-FZFb-WC6I-YV3d-XiyF-AyfYRL”
device = “/dev/hdb1”
status = [“ALLOCATABLE”]
flags = []
dev_size = 60050907
pe_start = 384
pe_count = 916
}
pv1 {
id = “3p6KZ4-yExY-Im0l-Lxfv-ExbP-dCKa-uB5SMA”
device = “/dev/hdc1”
status = [“ALLOCATABLE”]
flags = []
dev_size = 80084025
pe_start = 384
pe_count = 1221
}
}
logical_volumes {
LogVol00 {
id = “ZcJbUU-eXv3-Lmkd-2qX2-83UN-rbxP-j2ehlE”
status = [“READ”, “WRITE”, “VISIBLE”]
flags = []
segment_count = 2
segment1 {
start_extent = 0
extent_count = 1221
type = “striped”
stripe_count = 1 # linear
stripes = [
“pv1”, 0
]
}
segment2 {
start_extent = 1221
extent_count = 900
type = “striped”
stripe_count = 1 # linear
stripes = [
“pv0”, 0
]
}
}
}
}
——————————————————————————–
注:以上将卷组改名为VolGroup01,物理卷的设备路径也要相应修改;
================================================================================
(3) Recover恢复数据
================================================================================
Backup current LVM configuration(备份当前系统的LVM配置):
vgcfgbackup -d -v VolGroup00 –file /tmp/VolGroup00.bak;
Restore old LVM configuration from /tmp/VolGroup01.save(从抢救文件中恢复配置);
# vgcfgrestore –file /tmp/VolGroup01.save VolGroup01;
********************************************************************************
如有需要,请参考vgcfgrestore命令的说明:
********************************************************************************
# lvm help vgcfgrestore
——————————————————————————–
vgcfgrestore: Restore volume group configuration
vgcfgrestore
[-d|–debug]
[-f|–file filename]
[-l[l]|–list [–list]]
[-M|–metadatatype 1|2]
[-h|–help]
[-t|–test]
[-v|–verbose]
[–version]
VolumeGroupName
——————————————————————————–
#Activate the LVM’s(启动LVM卷组):
# vgchange -ay;
# vgscan
——————————————————————————–
Reading all physical volumes. This may take a while…
Found volume group “VolGroup01” using metadata type lvm2
Found volume group “VolGroup00” using metadata type lvm2
——————————————————————————–
# lvscan
——————————————————————————–
ACTIVE ‘/dev/VolGroup01/LogVol00’ [66.28 GB] inherit
ACTIVE ‘/dev/VolGroup00/LogVol00’ [36.66 GB] inherit
——————————————————————————–
# /bin/ls -l /dev/mapper/
——————————————————————————–
crw——- 1 root root 10, 63 Oct 6 23:35 control
brw-rw—- 1 root disk 253, 0 Oct 6 23:36 VolGroup00-LogVol00
brw-rw—- 1 root disk 253, 2 Oct 8 19:53 VolGroup01-LogVol00
——————————————————————————–
将所恢复的LVM逻辑卷挂载,然后复制数据:
# mkdir /mnt/vgtmp
# mount /dev/mapper/VolGroup01-LogVol00 /mnt/vgtmp
(成功复制数据之后,抢救任务完成)
从崩溃的Linux系统中抢救LVM物理卷数据
转载请注明出处:服务器评测 » 从崩溃的Linux系统中抢救LVM物理卷数据
相关推荐
- █ 8GB DDR3- 1Gbps █ 高达 /24 IPv4 █ /64 IPv6 rDNS 支持 █ 起价 54 美元
- server.net – 英国伦敦专用服务器,Ryzen 7900 和 Ryzen 7950X3D,英特尔至强第四代
- 洛杉矶、达拉斯、新加坡 – AMD Ryzen 和 AMD EPYC – 69 美元起!
- *OVHcloud 黑色星期五最后机会 🖤 | 定期优惠 | 限量版专用服务器
- MechanicWeb:美国/欧盟/英国/亚太地区 – 2024 年黑色星期五!Ryzen 9950X 托管和非托管 | 10 Gbps
- *IOFLOOD.com █ 黑色星期五 █ 双 E5-2695v4 + 升级 30% 折扣
- Python1.com | 自 2012 年起 | 强大的 AMD Ryzen 3700X、5900X、7900、9900X | NVME| 美国
- *NewidHost:企业级专用服务器|44%折扣(Linux 或 Windows)| 亚洲、美国、欧盟