如何在主机(Proxmox)上挂载VM使用的lvm磁盘,以便我可以复制文件?
VM(Xpenology)已损坏,我无法再启动它。我在 RAID 1 中安装了 2 个 4TB 磁盘,我想取回我的数据,但无法安装 LVM。
(我只对Disk_1和Disk_2感兴趣)
以下是一些信息:
root@pr0xm0x:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
vm-100-disk-0 Disk_1 -wi-a----- 3.55t
vm-100-disk-0 Disk_2 -wi-a----- 3.55t
data pve twi-aotz-- <181.69g 66.51 3.92
root pve -wi-ao---- 69.50g
swap pve -wi-ao---- 8.00g
vm-100-disk-0 pve Vwi-a-tz-- 16.00g data 12.24
vm-100-disk-1 pve Vwi-a-tz-- 52.00m data 57.21
vm-103-disk-1 pve Vwi-a-tz-- 6.00g data 27.56
vm-200-disk-0 pve Vwi-a-tz-- 120.00g data 97.66
vm-200-disk-1 pve Vwi-a-tz-- 100.00g data 0.00
root@pr0xm0x:~# parted /dev/Disk_1/vm-100-disk-0 print
Model: Linux device-mapper (linear) (dm)
Disk /dev/dm-0: 3908GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 2551MB 2550MB ext4 raid
2 2551MB 4699MB 2147MB linux-swap(v1) raid
3 4832MB 3908GB 3903GB raid
root@pr0xm0x:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 279.4G 0 disk
├─sda1 8:1 0 1007K 0 part
├─sda2 8:2 0 512M 0 part
└─sda3 8:3 0 278.9G 0 part
├─pve-swap 253:2 0 8G 0 lvm [SWAP]
├─pve-root 253:3 0 69.5G 0 lvm /
├─pve-data_tmeta 253:4 0 1.9G 0 lvm
│ └─pve-data-tpool 253:6 0 181.7G 0 lvm
│ ├─pve-data 253:7 0 181.7G 0 lvm
│ ├─pve-vm--200--disk--0 253:8 0 120G 0 lvm
│ ├─pve-vm--100--disk--0 253:9 0 16G 0 lvm
│ ├─pve-vm--100--disk--1 253:10 0 52M 0 lvm
│ ├─pve-vm--200--disk--1 253:11 0 100G 0 lvm
│ └─pve-vm--103--disk--1 253:12 0 6G 0 lvm
└─pve-data_tdata 253:5 0 181.7G 0 lvm
└─pve-data-tpool 253:6 0 181.7G 0 lvm
├─pve-data 253:7 0 181.7G 0 lvm
├─pve-vm--200--disk--0 253:8 0 120G 0 lvm
├─pve-vm--100--disk--0 253:9 0 16G 0 lvm
├─pve-vm--100--disk--1 253:10 0 52M 0 lvm
├─pve-vm--200--disk--1 253:11 0 100G 0 lvm
└─pve-vm--103--disk--1 253:12 0 6G 0 lvm
sdb 8:16 0 3.7T 0 disk
└─Disk_2-vm--100--disk--0 253:1 0 3.6T 0 lvm
sdc 8:32 0 3.7T 0 disk
└─Disk_1-vm--100--disk--0 253:0 0 3.6T 0 lvm
├─Disk_1-vm--100--disk--0p1 253:13 0 2.4G 0 part
├─Disk_1-vm--100--disk--0p2 253:14 0 2G 0 part
└─Disk_1-vm--100--disk--0p3 253:15 0 3.6T 0 part
sdd 8:48 0 3.7T 0 disk
sde 8:64 0 1.8T 0 disk
└─sde1 8:65 0 1.8T 0 part
sdf 8:80 1 14.4G 0 disk
├─sdf1 8:81 1 2.9G 0 part
├─sdf2 8:82 1 3.9M 0 part
└─sdf3 8:83 1 11.6G 0 part
sr0 11:0 1 1024M 0 rom
root@pr0xm0x:~# lvdisplay
--- Logical volume ---
LV Path /dev/Disk_1/vm-100-disk-0
LV Name vm-100-disk-0
VG Name Disk_1
LV UUID Hek0vC-VCjH-9BhS-i1Va-5X3d-0mzC-FK3bbM
LV Write Access read/write
LV Creation host, time pr0xm0x, 2020-01-23 08:50:40 +0100
LV Status available
# open 3
LV Size 3.55 TiB
Current LE 931840
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/Disk_2/vm-100-disk-0
LV Name vm-100-disk-0
VG Name Disk_2
LV UUID M6dzfZ-6wXt-dyvI-pSL8-3hky-aROy-JfWZUC
LV Write Access read/write
LV Creation host, time pr0xm0x, 2020-01-23 08:50:55 +0100
LV Status available
# open 0
LV Size 3.55 TiB
Current LE 931840
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/pve/swap
LV Name swap
VG Name pve
LV UUID JogsLv-1xic-2cK2-rBRX-EHt5-buYg-pcrWJM
LV Write Access read/write
LV Creation host, time proxmox, 2019-12-07 11:10:23 +0100
LV Status available
# open 2
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Path /dev/pve/root
LV Name root
VG Name pve
LV UUID Ukw2fX-Dcf1-RueD-mx6e-spEw-GdrV-fvxnjB
LV Write Access read/write
LV Creation host, time proxmox, 2019-12-07 11:10:23 +0100
LV Status available
# open 1
LV Size 69.50 GiB
Current LE 17792
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
--- Logical volume ---
LV Name data
VG Name pve
LV UUID LZmHdO-0rZX-XfGy-6fRz-j9bm-VmJz-yS2CQd
LV Write Access read/write
LV Creation host, time proxmox, 2019-12-07 11:10:24 +0100
LV Pool metadata data_tmeta
LV Pool data data_tdata
LV Status available
# open 6
LV Size <181.69 GiB
Allocated pool data 66.51%
Allocated metadata 3.92%
Current LE 46512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:6
--- Logical volume ---
LV Path /dev/pve/vm-200-disk-0
LV Name vm-200-disk-0
VG Name pve
LV UUID vRF4uB-WzMy-B2Nm-LDcy-T8BN-ghjF-PqPVKS
LV Write Access read/write
LV Creation host, time pr0xm0x, 2019-12-17 11:03:55 +0100
LV Pool name data
LV Status available
# open 0
LV Size 120.00 GiB
Mapped size 97.66%
Current LE 30720
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:8
--- Logical volume ---
LV Path /dev/pve/vm-100-disk-0
LV Name vm-100-disk-0
VG Name pve
LV UUID 3yGcBF-rhHJ-EMhC-Ft8o-okne-YdVg-ll3D4f
LV Write Access read/write
LV Creation host, time pr0xm0x, 2020-01-23 08:40:48 +0100
LV Pool name data
LV Status available
# open 0
LV Size 16.00 GiB
Mapped size 12.24%
Current LE 4096
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:9
--- Logical volume ---
LV Path /dev/pve/vm-100-disk-1
LV Name vm-100-disk-1
VG Name pve
LV UUID 3YV9J4-mLv3-yHg3-Sv2f-kklP-cvPt-1H5Zc0
LV Write Access read/write
LV Creation host, time pr0xm0x, 2020-01-23 08:48:19 +0100
LV Pool name data
LV Status available
# open 0
LV Size 52.00 MiB
Mapped size 57.21%
Current LE 13
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:10
--- Logical volume ---
LV Path /dev/pve/vm-200-disk-1
LV Name vm-200-disk-1
VG Name pve
LV UUID 3TWqbr-RO52-chRo-ubLf-zzzx-4QGg-Z21cuq
LV Write Access read/write
LV Creation host, time pr0xm0x, 2020-02-01 13:59:13 +0100
LV Pool name data
LV Status available
# open 0
LV Size 100.00 GiB
Mapped size 0.00%
Current LE 25600
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:11
--- Logical volume ---
LV Path /dev/pve/vm-103-disk-1
LV Name vm-103-disk-1
VG Name pve
LV UUID 4e22Xm-P40c-NaxA-TttF-5eBQ-F3CR-IcK2DP
LV Write Access read/write
LV Creation host, time pr0xm0x, 2022-01-30 16:47:57 +0100
LV Pool name data
LV Status available
# open 0
LV Size 6.00 GiB
Mapped size 27.56%
Current LE 1536
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:12
这是挂载的结果:
root@pr0xm0x:~# mount /dev/Disk_1/vm-100-disk-0 /mnt/Disk_1/
mount: /mnt/Disk_1: wrong fs type, bad option, bad superblock on /dev/mapper/Disk_1-vm--100--disk--0, missing codepage or helper program, or other error.
答案1
逻辑卷的名称表明 LV 被用作虚拟磁盘对于虚拟机,因此每个 LV 可能包含一个分区表和一个或多个分区 - 并且您的parted
输出证明这正是正在发生的情况。
您将无法直接挂载,/dev/Disk_1/vm-100-disk-0
就像/dev/sda
定义了分区时一样。当您挂载某些内容时,文件系统驱动程序期望实际的文件系统从您尝试挂载的设备的第一个块开始,而不是距离设备一定距离(即在分区表和可能的其他分区之后)。
首先,使用losetup -f
:它将报告第一个未使用的/dev/loopN
设备。使用此命令报告的实际设备来代替/dev/loopN
任何后续命令。
将 LV 绑定到循环设备并请求losetup
为其自动创建分区设备:
losetup -P /dev/loopN /dev/Disk_1/vm-100-disk-0
这将创建诸如 等设备/dev/loopNp1
,/dev/loopNp2
通过这些设备您将能够访问 LV 中包含的虚拟磁盘的每个单独分区。
(如果您的旧版本losetup
无法识别该-P
选项,则可以使用该命令kpartx
作为替代品,如 Bravo 在评论中建议的那样。根据您的发行版,kpartx
可能会作为单独的包提供或与device-mapper-multipath
工具一起打包.)
如果虚拟磁盘包含常规分区,您现在应该能够安装它们。但是,如果虚拟磁盘还包含 LVM 物理卷,则必须先激活 LVM 卷组,然后才能访问其 LV:vgchange -ay
应该足以激活任何和所有可检测到的 LVM 卷组。
访问完虚拟磁盘后,请记住按正确的顺序撤消访问其分区所需的所有步骤:
- 卸载从虚拟磁盘安装的所有分区/LV
- 如果虚拟磁盘包含 LVM 卷,请停用您使用 激活的所有 LVM 卷组
vgchange -an <name of the VG>
。如果您不确定卷组的名称,该pvs
命令的输出应该会有所帮助。 - 如果您使用了
kpartx
,请运行kpartx -d /dev/loopN
以作为单独的步骤删除分区设备。 - 用于
losetup -d /dev/loopN
解除循环设备(以及由 所创建的任何分区设备losetup -P
)的绑定。
当您实际运行该磁盘所属的虚拟机时,切勿将虚拟机的虚拟磁盘挂载到主机系统上:这会导致主机和虚拟机的文件系统缓存不同步并相互冲突,从而迅速导致虚拟磁盘上的数据损坏。