一种恢复无法启动的虚拟机中的数据的方法

使用VirtualBox或者Vmware虚拟机的时候,可能由于程序错误或者异常关机,导致系统无法启动,碰到这种情况该怎么恢复之前虚拟机里的数据呢?


一个可行的办法是重新建一个虚拟机,确定它能够运行之后,把之前虚拟机的虚拟磁盘也挂载上。考虑到默认同一个SATA控制器上无法区别同一个同名卷,需要把老的虚拟机的磁盘挂载到IDE控制器上。


如下面基于Oralc VM VirtualBox的截图所示:


wKiom1l5Mo7QBKP0AADaaqno8U8032.png


完成之后,重新启动虚拟机,发现能发现老磁盘上的卷组。但由于新系统和老系统都是基于同一个导出的虚拟机镜像制作的,此时系统中出现了同名的卷,导致老虚拟机上的盘无法自动导入。那么又如何解决这一新的问题呢?


1.首先,确定不能自动挂载的vg的uuid:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
lvm
  vgdisplay
lvm>
vgdisplay
---
Volume group ---
VG
Name               centos
System
ID
Format
                lvm2
Metadata
Areas        1
Metadata
Sequence No  5
VG
Access             read/write
VG
Status             resizable
MAX
LV                0
Cur
LV                3
Open
LV               0
Max
PV                0
Cur
PV                1
Act
PV                1
VG
Size               63.51 GiB
PE
Size               4.00 MiB
Total
PE              16258
Alloc
PE / Size       16242 / 63.45 GiB
Free
  PE / Size       16 / 64.00 MiB
VG
UUID               bX2g0F-S2gA-7fjc-yj2e-qkeR-ImE9-mkp1xu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
Volume group ---
VG
Name               centos
System
ID
Format
                lvm2
Metadata
Areas        1
Metadata
Sequence No  4
VG
Access             read/write
VG
Status             resizable
MAX
LV                0
Cur
LV                3
Open
LV               3
Max
PV                0
Cur
PV                1
Act
PV                1
VG
Size               255.51 GiB
PE
Size               4.00 MiB
Total
PE              65410
Alloc
PE / Size       65394 / 255.45 GiB
Free
  PE / Size       16 / 64.00 MiB
VG
UUID               ydgLeu-Wt4t-PQ4u-fq1o-XJ8r-JsKH-qwQtyU


可以看到上面有两个同名的VG,结合mount命令,可以发现uuid为bX2g0F-S2gA-7fjc-yj2e-qkeR-ImE9-mkp1xu的卷组但无法自动挂载。


2.为此,需要重命名老的重名卷组:

1
2
lvm
vgrename bX2g0F-S2gA-7fjc-yj2e-qkeR-ImE9-mkp1xu centos-1


3.再次确认修改过成功:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
lvm>
vgdisplay
---
Volume group ---
VG
Name               centos-1
System
ID
Format
                lvm2
Metadata
Areas        1
Metadata
Sequence No  5
VG
Access             read/write
VG
Status             resizable
MAX
LV                0
Cur
LV                3
Open
LV               0
Max
PV                0
Cur
PV                1
Act
PV                1
VG
Size               63.51 GiB
PE
Size               4.00 MiB
Total
PE              16258
Alloc
PE / Size       16242 / 63.45 GiB
Free
  PE / Size       16 / 64.00 MiB
VG
UUID               bX2g0F-S2gA-7fjc-yj2e-qkeR-ImE9-mkp1xu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
Volume group ---
VG
Name               centos
System
ID
Format
                lvm2
Metadata
Areas        1
Metadata
Sequence No  4
VG
Access             read/write
VG
Status             resizable
MAX
LV                0
Cur
LV                3
Open
LV               3
Max
PV                0
Cur
PV                1
Act
PV                1
VG
Size               255.51 GiB
PE
Size               4.00 MiB
Total
PE              65410
Alloc
PE / Size       65394 / 255.45 GiB
Free
  PE / Size       16 / 64.00 MiB
VG
UUID               ydgLeu-Wt4t-PQ4u-fq1o-XJ8r-JsKH-qwQtyU


4.重新激活由于同名没法自动加载的卷组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@localhost
dev]# lvscan
inactive
          '/dev/centos-1/swap' [2.00 GiB] inherit
inactive
          '/dev/centos-1/home' [20.16 GiB] inherit
inactive
          '/dev/centos-1/root' [41.29 GiB] inherit
ACTIVE
            '/dev/centos/swap' [3.88 GiB] inherit
ACTIVE
            '/dev/centos/home' [201.57 GiB] inherit
ACTIVE
            '/dev/centos/root' [50.00 GiB] inherit
[root@localhost
dev]# ls /dev/centos/
home
  root  swap
[root@localhost
dev]# vgchange -ay /dev/centos-1
3
logical volume(s) in volume group "centos-1" now active
[root@localhost
dev]# lvscan
ACTIVE
            '/dev/centos-1/swap' [2.00 GiB] inherit
ACTIVE
            '/dev/centos-1/home' [20.16 GiB] inherit
ACTIVE
            '/dev/centos-1/root' [41.29 GiB] inherit
ACTIVE
            '/dev/centos/swap' [3.88 GiB] inherit
ACTIVE
            '/dev/centos/home' [201.57 GiB] inherit
ACTIVE
            '/dev/centos/root' [50.00 GiB] inherit


5.检查是否自动挂载lv


重启系统之后,运行下面的命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[root@localhost
dev]# cd /dev/mapper/
[root@localhost
mapper]# ls
centos--1-home
  centos--1-root  centos--1-swap  centos-home  centos-root 
centos-swap  control
[root@localhost
mapper]# ls -alrt
total
0
crw-------.
  1 root root 10, 236 Jul 16 22:34 control
lrwxrwxrwx.
  1 root root       7 Jul 16 22:34 centos-swap -> ../dm-1
lrwxrwxrwx.
  1 root root       7 Jul 16 22:34 centos-root -> ../dm-0
lrwxrwxrwx.
  1 root root       7 Jul 16 22:34 centos-home -> ../dm-2
drwxr-xr-x.
21 root root    3280 Jul 16 23:44 ..
lrwxrwxrwx.
  1 root root       7 Jul 16 23:44 centos--1-swap -> ../dm-3
lrwxrwxrwx.
  1 root root       7 Jul 16 23:44 centos--1-root -> ../dm-5
lrwxrwxrwx.
  1 root root       7 Jul 16 23:44 centos--1-home -> ../dm-4
drwxr-xr-x.
  2 root root     180 Jul 16 23:44 .
[root@localhost
mapper]# mount /dev/dm-
dm-0
  dm-1  dm-2  dm-3  dm-4  dm-5
[root@localhost
mapper]# mount /dev/dm-4 /mnt/
[root@localhost
mapper]# ls /mnt/
baba
  worker
[root@localhost
mapper]#


通过上面命令可以看到,之前不能挂载的卷组已经可以自动挂载了。



参考链接:http://www.92csz.com/47/736.html
















本文转自存储之厨51CTO博客,原文链接: http://blog.51cto.com/xiamachao/1951293,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值