How to craete a NVMe with 4K sector size in KVM-QEMU

2k views Asked by At

For testing purposes, I am creating a virtual machine as it follows:

qemu-img create -f qcow2 \
-o cluster_size=4096,preallocation=full \
/home/marcop/.libvirt/nvme-20G.qcow2 20G

qemu-system-x86_64 -machine q35,accel=kvm \
  -m 4096 \
  -smp 4 \
  -cpu host \
  -boot d \
  -cdrom /var/lib/libvirt/isos/archlinux-2020.10.01-x86_64.iso \
  -drive file=/home/marcop/.libvirt/nvme-20G.qcow2,if=none,aio=native,cache.direct=on,id=D24 \
  -device nvme,drive=D24,serial=1234,logical_block_size=4096,physical_block_size=4096

When booted inside the machine, I use fdisk and nvme-cli to check the sector size, but it's always 512B.

pacman -Sy nvme-cli
fdisk -l /dev/nvme0n1

with output:

Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: QEMU NVMe Ctrl
Units: sectors of 1 * 512 = 512 bytes
Sector size (logica/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Looking for the available sector size modes with nvme-cli (see here and here for details on NVMe)

nvme id-ns /dev/nvme0n1

return output:

NVME Identify Namespace 1:
nsze    : 0x2800000
ncap    : 0x2800000
nuse    : 0x2800000
nsfeat  : 0
nlbaf   : 0
flbas   : 0
mc      : 0
dpc     : 0
dps     : 0
nmic    : 0
rescap  : 0
fpi     : 0
dlfeat  : 0
nawun   : 0
nawupf  : 0
nacwu   : 0
nabsn   : 0
nabo    : 0
nabspf  : 0
noiob   : 0
nvmcap  : 0
nsattr  : 0
nvmsetid: 0
anagrpid: 0
endgid  : 0
nguid   : 00000000000000000000000000000000
eui64   : 0000000000000000
lbaf  0 : ms:0   lbads:9  rp:0 (in use)

Which indicates the only one sector profile exits. For comparison, the output of the same command issued for my physical NVMe returns

[...]
lbaf  0 : ms:0   lbads:9  rp:0x2 (in use)
lbaf  1 : ms:0   lbads:12 rp:0x1 

Any help would be greatly appreciated!

1

There are 1 answers

1
Umamahesh Allenki On

run command to format with 4k. But beware that format will wipe out data.

nvme format /dev/nvme0n1 --lbaf=1