简体   繁体   English

在 QEMU 中为 NVMe 设置 4k 块大小

[英]setting 4k block size for NVMe in QEMU

I want to use 4k block size for emulated nvme device in qemu.我想在 qemu 中为模拟的 nvme 设备使用 4k 块大小。 So I end up with a script like this:所以我最终得到了一个这样的脚本:

#!/bin/bash
QEMU_EXE="path/to/bin/qemu-system-x86_64"
SYSTEM_IMG="path/to/ubuntu1604.qcow2"
NVME_IMG="./nvme_8G.img"
$QEMU_EXE -m 2G \
               -machine q35 \
               -hda ${SYSTEM_IMG} \
               -drive file=${NVME_IMG},format=raw,if=none,id=drv0 \
               -device nvme,drive=drv0,serial=foo,opt_io_size=4096,min_io_size=4096,logical_block_size=4096,physical_block_size=4096 \                                                                          
               -smp 4 \
               -enable-kvm \                   
               -net nic \  
               -net user,hostfwd=tcp::2222-:22 

However when I entered the guest machine the block/io size in the "-device nvme ..." seems not to have any effects:但是,当我进入客户机时,“-device nvme ...”中的块/io 大小似乎没有任何影响:

lifeng@node0:~$ sudo fdisk -l
[sudo] password for lifeng:
Disk /dev/nvme0n1: 8 GiB, 8589934592 bytes, 16777216 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 /dev/sda: 30 GiB, 32212254720 bytes, 62914560 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: dos
Disk identifier: 0xbbb77ab7

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 58722303 58720256  28G 83 Linux
/dev/sda2       58724350 62912511  4188162   2G  5 Extended
/dev/sda5       58724352 62912511  4188160   2G 82 Linux swap / Solaris

I am using the QEMU 2.11, compiled from source(./configure with only PREFIX changed), I followed the configuration instructions from here:我正在使用从源代码编译的 QEMU 2.11(./configure 只更改了 PREFIX),我按照这里的配置说明进行操作:

lifeng@1wk300:~/software/qemu-2.11.1qemu-system-x86_64 -device nvme,help
nvme.serial=str
nvme.rombar=uint32
nvme.logical_block_size=uint16 (A power of two between 512 and 32768)
nvme.discard_granularity=uint32
nvme.drive=str (ID of a drive to use as a backend)
nvme.bootindex=int32
nvme.multifunction=bool (on/off)
nvme.opt_io_size=uint32
nvme.min_io_size=uint16
nvme.romfile=str
nvme.command_serr_enable=bool (on/off)
nvme.addr=int32 (Slot and optional function number, example: 06.0 or 06)
nvme.physical_block_size=uint16 (A power of two between 512 and 32768)

Any help or comments are appreciated!任何帮助或意见表示赞赏!

我发现 qemu-nvme 可以为 NVME 提供 4k 块和扇区大小,安装后,使用以下命令查看更多详细信息:

qemu\install\dir/bin/qemu-system-x86_64 -device nvme,help

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM