挂载文件系统类型“LVM2_member”的 zvol 分区,这是原始 qcow2 导出的快照

挂载文件系统类型“LVM2_member”的 zvol 分区,这是原始 qcow2 导出的快照

我目前正在尝试将存储在 qcow2 文件中的一些虚拟机迁移到 ZFS ZVOL 上。

在决定是否真的要坚持这样做之前,我想做的一件事是看看是否可以为已关闭的虚拟机创建快照,然后以只读模式在主机上安装该快照,以便对其进行导航和随意查看/复制文件。

我有以下工作流程:

获取信息:

/kvm-images $ sudo qemu-img info Ubuntu-Server-20.04.qcow2

image: Ubuntu-Server-20.04.qcow2
file format: qcow2
virtual size: 128 GiB (137438953472 bytes)
disk size: 41.4 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: true
    refcount bits: 16
    corrupt: false
    extended l2: false   

创建ZVOL

/kvm-images $ sudo zfs create -V 137438953472 tank/kvm-images/Ubuntu-Server-20.04

将图像从 qcow2 文件导出到 ZVOL

/kvm-images $ sudo qemu-img convert -O raw /kvm-images/Ubuntu-Server-20.04.qcow2 /dev/zvol/tank/kvm-images/Ubuntu-Server-20.04

然后修改VM Virtio Disk 1 xml

<disk type="file" device="disk">
  <driver name="qemu" type="qcow2"/>
  <source file="/kvm-images/Ubuntu-Server-20.04.qcow2"/>
  <target dev="vda" bus="virtio"/>
  <boot order="1"/>
  <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
</disk>

<disk type="block" device="disk">
  <driver name="qemu" type="raw" cache="none" io="native" discard="unmap"/>
  <source dev="/dev/zvol/tank/kvm-images/Ubuntu-Server-20.04" index="2"/>
  <backingStore/>
  <target dev="vda" bus="virtio"/>
  <boot order="1"/>
  <alias name="virtio-disk0"/>
  <address type="pci" domain="0x0000" bus="0x03" slot="0x00" function="0x0"/>
</disk>

可以启动进入虚拟机,一切似乎都像以前一样。

所以我关闭虚拟机并创建快照

/kvm-images $ sudo zfs snapshot tank/kvm-images/Ubuntu-Server-20.04@test-01

发出后

sudo zfs set snapdev=visible tank/kvm-images/Ubuntu-Server-20.04

我可以看到快照的分区/dev/zvol/tank/kvm-images

/dev/zvol/tank/kvm-images $ ls -lsah
total 0
0 drwxr-xr-x 2 root root 280 Jul 25 16:31 .
0 drwxr-xr-x 3 root root  80 Jul 25 11:47 ..
0 lrwxrwxrwx 1 root root  13 Jul 25 15:53 Ubuntu-Server-20.04 -> ../../../zd48
0 lrwxrwxrwx 1 root root  15 Jul 25 15:53 Ubuntu-Server-20.04-part1 -> ../../../zd48p1
0 lrwxrwxrwx 1 root root  15 Jul 25 15:53 Ubuntu-Server-20.04-part2 -> ../../../zd48p2
0 lrwxrwxrwx 1 root root  15 Jul 25 15:53 Ubuntu-Server-20.04-part3 -> ../../../zd48p3
0 lrwxrwxrwx 1 root root  13 Jul 25 16:31 Ubuntu-Server-20.04@test-01 -> ../../../zd64
0 lrwxrwxrwx 1 root root  15 Jul 25 16:31 Ubuntu-Server-20.04@test-01-part1 -> ../../../zd64p1
0 lrwxrwxrwx 1 root root  15 Jul 25 16:31 Ubuntu-Server-20.04@test-01-part2 -> ../../../zd64p2
0 lrwxrwxrwx 1 root root  15 Jul 25 16:31 Ubuntu-Server-20.04@test-01-part3 -> ../../../zd64p3

尝试使用zfs mount没有效果,

sudo zfs mount tank/kvm-images/Ubuntu-Server-20.04@test-01

Ubuntu-Server-20.04 之后无法自动完成,并且如果强制提及

cannot open 'tank/kvm-images/Ubuntu-Server-20.04@test-01': snapshot delimiter '@' is not expected here

所以我尝试手动安装它,就像它是遗留的一样:

sudo mount /dev/zvol/tank/kvm-images/Ubuntu-Server-20.04@test-01-part3 /mnt/snapshots/ubuntu

mount: /mnt/snapshots/ubuntu: unknown filesystem type 'LVM2_member'.

分区 2 ( Ubuntu-Server-20.04@test-01-part2) 可安装且可导航,它包含该/boot分区。

发行sudo vgscan --mknodes收益率

WARNING: Not using device /dev/zd64p3 for PV aaaaaa-aaaa-aaaa-aaaa-aaaa-aaaa-aaaaaa.
WARNING: PV aaaaaa-aaaa-aaaa-aaaa-aaaa-aaaa-aaaaaa prefers device /dev/zd48p3 because device is used by LV.
Found volume group "ubuntu-vg" using metadata type lvm2
WARNING: Not using device /dev/zd64p3 for PV aaaaaa-aaaa-aaaa-aaaa-aaaa-aaaa-aaaaaa.
WARNING: PV aaaaaa-aaaa-aaaa-aaaa-aaaa-aaaa-aaaaaa prefers device /dev/zd48p3 because device is used by LV.

请注意,这些唯一 ID (aaa) 都完全相同。

因此,考虑到所有这些结果,我如何访问驻留在中的快照文件/dev/zvol/tank/kvm-images/Ubuntu-Server-20.04@test-01-part3

另外,请记住,我对 ZFS 非常陌生(上周才读了很多相关内容),对 LVM 的经验为零(除了让操作系统安装程序将其用作默认值),因此可能还有其他正确执行此操作的方法。

如果我将 qcow2 文件移至 ZFS 文件系统并继续从那里使用它,这样会更容易创建快照吗?我这样做了并且成功了(虽然没有测试快照),但后来我读到这是 CoW on CoW 并且应该避免,所以我正在测试这种 ZVOL 方法。

相关内容