代码之家  ›  专栏  ›  技术社区  ›  Fengggli

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

  •  0
  • Fengggli  · 技术社区  · 7 年前

    我想在qemu中为模拟nvme设备使用4k块大小。所以我最终得到了这样一个脚本:

    #!/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 
    

    但是,当我进入来宾计算机时,“-设备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
    

    我使用的是从源代码编译的QEMU 2.11(/configure,仅更改前缀),我遵循了这里的配置说明:

    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)
    

    欢迎提供任何帮助或意见!

    1 回复  |  直到 7 年前
        1
  •  0
  •   Fengggli    6 年前

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

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