xfs_irecover 是个垃圾,无法恢复已删除的文件。
此图为鉴:

运行莫名崩溃。


磁盘导出

1
2
3
4
5
6
将虚拟机的磁盘导出来:
[root@localhost esxi_img]# file CentOS06-flat.vmdk.bak
CentOS06-flat.vmdk.bak: x86 boot sector;
partition 1: ID=0x83, active, starthead 32, startsector 2048, 2097152 sectors;
partition 2: ID=0x8e, starthead 170, startsector 2099200, 417331200 sectors, code offset 0x63
[root@localhost esxi_img]#

losetup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
将文件挂载为设备文件
# -r 映射为只读类型
[root@localhost esxi_img]# losetup -P -f --show -r CentOS06-flat.vmdk.bak
/dev/loop3
[root@localhost esxi_img]#

查看本地回环设备
[root@localhost esxi_img]# losetup -a
/dev/loop0: [2064]:425525252 (/data/img/CentOS-7-x86_64-Everything-1708.iso)
/dev/loop1: [2064]:425525251 (/data/img/rhel-server-7.2-x86_64-dvd.iso)
/dev/loop2: [2064]:425525250 (/data/img/CentOS-7-x86_64-DVD-1708.iso)
/dev/loop3: [2064]:302055427 (/data/esxi_img/CentOS06-flat.vmdk.bak)
[root@localhost esxi_img]#

查看本地回环设备的详细
[root@localhost esxi_img]# ll /dev/loop3*
brw-rw---- 1 root disk 7, 3 Aug 28 15:41 /dev/loop3
brw-rw---- 1 root disk 259, 0 Aug 28 15:41 /dev/loop3p1
brw-rw---- 1 root disk 259, 1 Aug 28 15:41 /dev/loop3p2
[root@localhost esxi_img]#

分区信息

1
2
3
4
5
6
7
8
9
10
11
12
13
查看设备文件的分区
[root@localhost esxi_img]# fdisk -l -u /dev/loop3
Disk /dev/loop3: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ca118

Device Boot Start End Blocks Id System
/dev/loop3p1 * 2048 2099199 1048576 83 Linux
/dev/loop3p2 2099200 419430399 208665600 8e Linux LVM
[root@localhost esxi_img]#

卸载. 挂载 某个分区

1
2
3
4
5
分区开始计算 2099200*512 = 1074790400
[root@localhost esxi_img]# losetup -d /dev/loop3
[root@localhost esxi_img]# losetup -P -f --show -r -o 1074790400 CentOS06-flat.vmdk.bak
/dev/loop3
[root@localhost esxi_img]#

VG 名字 冲突!!!

查看 PV VG 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
[root@localhost esxi_img]# pvscan
PV /dev/sda3 VG centos lvm2 [<277.68 GiB / 4.00 MiB free]
PV /dev/loop3 VG centos lvm2 [<199.00 GiB / 4.00 MiB free]
Total: 2 [476.67 GiB] / in use: 2 [476.67 GiB] / in no VG: 0 [0 ]
[root@localhost esxi_img]#


[root@localhost esxi_img]# vgdisplay
--- 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 <277.68 GiB
PE Size 4.00 MiB
Total PE 71085
Alloc PE / Size 71084 / 277.67 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID hQxRYe-8PMB-X4AM-QTxd-7FdG-fvvv-gfdoWO

--- 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 <199.00 GiB
PE Size 4.00 MiB
Total PE 50943
Alloc PE / Size 50942 / 198.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID YbC0T6-GYzS-kUk6-ZwXn-l68S-gHig-Xlz9xP

[root@localhost esxi_img]#
[root@localhost esxi_img]# vgscan
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
Found volume group "centos" using metadata type lvm2
[root@localhost esxi_img]#

[root@localhost esxi_img]# lvscan
ACTIVE '/dev/centos/swap' [<27.89 GiB] inherit
ACTIVE '/dev/centos/home' [<199.79 GiB] inherit
ACTIVE '/dev/centos/root' [50.00 GiB] inherit
inactive '/dev/centos/swap' [<5.88 GiB] inherit
inactive '/dev/centos/home' [<143.12 GiB] inherit
inactive '/dev/centos/root' [50.00 GiB] inherit
[root@localhost esxi_img]#



[root@localhost esxi_img]# vgscan -v
Wiping cache of LVM-capable devices
Wiping internal VG cache
Reading volume groups from cache.
Found volume group "centos" using metadata type lvm2
Archiving volume group "centos" metadata (seqno 4).
Archiving volume group "centos" metadata (seqno 4).
Creating volume group backup "/etc/lvm/backup/centos" (seqno 4).
Cache: Duplicate VG name centos: Prefer existing hQxRYe-8PMB-X4AM-QTxd-7FdG-fvvv-gfdoWO vs new YbC0T6-GYzS-kUk6-ZwXn-l68S-gHig-Xlz9xP
Found volume group "centos" using metadata type lvm2
Archiving volume group "centos" metadata (seqno 4).
Archiving volume group "centos" metadata (seqno 4).
Creating volume group backup "/etc/lvm/backup/centos" (seqno 4).
[root@localhost esxi_img]#
[root@localhost esxi_img]#

VG 改名

去除-r 映射为只读类型

1
2
3
4
5
6
7
8
9
[root@localhost esxi_img]# losetup -d /dev/loop3
[root@localhost esxi_img]# losetup -P -f --show -o 1074790400 CentOS06-flat.vmdk.bak
/dev/loop3
[root@localhost esxi_img]#
[root@localhost esxi_img]#
[root@localhost esxi_img]# vgrename YbC0T6-GYzS-kUk6-ZwXn-l68S-gHig-Xlz9xP chunli
Processing VG centos because of matching UUID YbC0T6-GYzS-kUk6-ZwXn-l68S-gHig-Xlz9xP
Volume group "YbC0T6-GYzS-kUk6-ZwXn-l68S-gHig-Xlz9xP" successfully renamed to "chunli"
[root@localhost esxi_img]#

VG inactive

然后显示 都是 失效模式

1
2
3
4
5
6
7
8
9
[root@localhost esxi_img]# lvscan
ACTIVE '/dev/centos/swap' [<27.89 GiB] inherit
ACTIVE '/dev/centos/home' [<199.79 GiB] inherit
ACTIVE '/dev/centos/root' [50.00 GiB] inherit
inactive '/dev/chunli/swap' [<5.88 GiB] inherit
inactive '/dev/chunli/home' [<143.12 GiB] inherit
inactive '/dev/chunli/root' [50.00 GiB] inherit
[root@localhost esxi_img]#
[root@localhost esxi_img]#

激活

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost esxi_img]#  vgchange -ay chunli
3 logical volume(s) in volume group "chunli" now active
[root@localhost esxi_img]# lvscan
ACTIVE '/dev/centos/swap' [<27.89 GiB] inherit
ACTIVE '/dev/centos/home' [<199.79 GiB] inherit
ACTIVE '/dev/centos/root' [50.00 GiB] inherit
ACTIVE '/dev/chunli/swap' [<5.88 GiB] inherit
ACTIVE '/dev/chunli/home' [<143.12 GiB] inherit
ACTIVE '/dev/chunli/root' [50.00 GiB] inherit
[root@localhost esxi_img]# ll /dev/mapper/
total 0
lrwxrwxrwx 1 root root 7 Aug 3 11:11 centos-home -> ../dm-2
lrwxrwxrwx 1 root root 7 Aug 3 11:11 centos-root -> ../dm-0
lrwxrwxrwx 1 root root 7 Aug 3 11:11 centos-swap -> ../dm-1
lrwxrwxrwx 1 root root 7 Aug 28 16:27 chunli-home -> ../dm-4
lrwxrwxrwx 1 root root 7 Aug 28 16:27 chunli-root -> ../dm-5
lrwxrwxrwx 1 root root 7 Aug 28 16:27 chunli-swap -> ../dm-3
crw------- 1 root root 10, 236 Aug 3 11:11 control
[root@localhost esxi_img]#