I want to use 4k block size for emulated nvme device in qemu. 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:
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:
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!
I found qemu-nvme can have 4k block and sector size for NVME, after the installation, see more details using:
qemu\install\dir/bin/qemu-system-x86_64 -device nvme,help