我的主机中有两个块设备,我试图将它们传递给虚拟机来宾。一个可以完美地工作,而另一个则不能。唯一的区别是,一个是内部驱动器上的逻辑卷,而另一个是基于外部 Thunderbolt 驱动器构建的软件 RAID 上的逻辑卷。我很好奇是否需要做得更好,以确保分区表位于主机和来宾需要的位置。
来宾和主机都运行最新的 Arch Linux。主机中的第一个设备位于 LVM 卷组上的逻辑卷上,/dev/nvme0n1p3
该卷组上直接连接到 Intel NUC13 主板
# fdisk -l /dev/HomeServerNUC13VM/HomeServerNUC13Storage
Disk /dev/HomeServerNUC13VM/HomeServerNUC13Storage: 16 GiB, 17179869184 bytes, 33554432 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
Disklabel type: gpt
Disk identifier: CAEF53EA-821B-4A57-9FFB-E62CE5174E16
Device Start End Sectors Size Type
/dev/HomeServerNUC13VM/HomeServerNUC13Storage1 2048 2099199 2097152 1G EFI System
/dev/HomeServerNUC13VM/HomeServerNUC13Storage2 2099200 33552383 31453184 15G Linux filesystem
第二个是不同 LVM 卷组上的逻辑卷,/dev/md127p1
其上有一个软件 RAID 5 阵列/dev/nvme{1,2,3,4}n1p1
。所有这些物理驱动器都位于外壳中并通过 Thunderbolt 连接到 NUC
# fdisk -l /dev/HomeStorageOWC/HomeServerNUC13Storage
Disk /dev/HomeStorageOWC/HomeServerNUC13Storage: 2 TiB, 2199023255552 bytes, 536870912 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: gpt
Disk identifier: DBF9C573-63AF-417B-ADE6-F6560D0702D9
Device Start End Sectors Size Type
/dev/HomeStorageOWC/HomeServerNUC13Storage1 256 536870655 536870400 2T Linux filesystem
我可以访问主机中两个块设备上的分区并kpartx -a
毫无问题地安装它们。当我将设备传递给虚拟机来宾时,问题就出现了
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
<source dev='/dev/HomeServerNUC13VM/HomeServerNUC13Storage'/>
<target dev='sda' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
<source dev='/dev/HomeStorageOWC/HomeServerNUC13Storage'/>
<target dev='sdb' bus='sata'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</disk>
在来宾中/dev/HomeServerNUC13VM
显示为/dev/sda
并且工作正常,而在/dev/HomeStorageOWC/HomeServerNUC13Storage
显示时则显示为/dev/sdb
搞砸了。请注意,Disklabel type
是dos
# fdisk -l /dev/sdb
GPT PMBR size mismatch (536870911 != 4294967295) will be corrected by write.
Disk /dev/sdb: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/sdb1 1 4294967295 4294967295 2T ee GPT
如果我在来宾中重新创建分区表和分区,那么来宾中的一切都很好
# fdisk -l /dev/sdb
Disk /dev/sdb: 2 TiB, 2199023255552 bytes, 4294967296 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 00B06790-6D3B-4694-B435-6E9E6E9E12CB
Device Start End Sectors Size Type
/dev/sdb1 2048 4294965247 4294963200 2T Linux filesystem
但回到主机后事情就搞砸了。再次Disklabel type
是dos
。
# fdisk -l /dev/HomeStorageOWC/HomeServerNUC13Storage
Disk /dev/HomeStorageOWC/HomeServerNUC13Storage: 2 TiB, 2199023255552 bytes, 536870912 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 262144 bytes / 786432 bytes
Disklabel type: dos
Disk identifier: 0x00000000
Device Boot Start End Sectors Size Id Type
/dev/HomeStorageOWC/HomeServerNUC13Storage1 1 4294967295 4294967295 16T ee GPT
Partition 1 does not start on physical sector boundary.
我删除了 RAID 5 并直接重新创建它,/dev/nvme{1,2,3,4}n1
同时直接放置 LVM /dev/md127
(即没有分区),然后将 LV 设为 256 GB,但仍然遇到相同的问题。
答案1
答案就在libvirt 文档,特别是在该行中:
blockio logical_block_size='512' physical_block_size='4096'
discard_granularity='4096'
QEMU 也有一个选项;就像是:
-设备 scsi-hd,总线=scsi1.0,驱动器=drive-virtio-disk1,id=virtio-scsi-pci1,物理块大小=4096,逻辑块大小=512
答案2
/dev/nvme0n1
我错过的是主机中的内容
Sector size (logical/physical): 512 bytes / 512 bytes
而/dev/nvme{1,2,3,4}n1
在主机中有
Sector size (logical/physical): 4096 bytes / 4096 bytes
在来宾中,有问题的设备显示为
Sector size (logical/physical): 512 bytes / 512 bytes
我认为扇区大小的这种不匹配会搞砸分区表。您似乎无法设置虚拟SATA设备的扇区大小,但可以使用virtio设备的blockio参数
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none' io='native' discard='unmap'/>
<source dev='/dev/HomeStorageOWC/HomeServerNUC13Web'/>
<target dev='vda' bus='virtio'/>
<blockio logical_block_size='4096' physical_block_size='4096'/>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</disk>