简体   繁体   English

如何在 KVM-QEMU 中创建 4K 扇区大小的 NVMe

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

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.在机器内部启动时,我使用 fdisk 和 nvme-cli 检查扇区大小,但始终为 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-cli 查找可用的扇区大小模式(有关 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为了比较,为我的物理 NVMe 发出的相同命令的输出返回

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

Any help would be greatly appreciated!任何帮助将不胜感激!

run command to format with 4k.运行命令格式化为 4k。 But beware that format will wipe out data.但请注意,该格式会清除数据。

nvme format /dev/nvme0n1 --lbaf=1

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

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