从崩溃的Linux系统中抢救LVM物理卷数据
本文笔记了一次从已经崩溃的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
(成功复制数据之后,抢救任务完成)
================================================================================
(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
(成功复制数据之后,抢救任务完成)
相关推荐
kanpiaoxue 2013-06-19
RexLeee 2019-12-23
fouweng 2011-08-27
heavenmark 2011-07-31
Tinazhou 2016-11-22
molong0 2017-07-13
ECSHOP专属建设 2016-11-25
ruizhenggang 2011-10-11
BlogForUS 2018-01-22
cxj 2019-10-08
lilygg 2019-10-04
啦啦啦啦啦 2019-09-29
二哈 2012-02-12
小微分享驿站 2011-12-28