QEMU 6.0 版开始支持对分区命名空间的模拟。如果主机 Linux 发行版不提供QEMU 6.0 或更高版本,则必须从源代码编译QEMU。
cd qemu-6.0.0
mkdir build
cd build
../configure --prefix=/usr/ --sysconfdir=/etc
make clean
make -j 16
sudo make install
编译出错时删除
sudo ninja -C build uninstall
brctl addbr br0
brctl addif br0 eno1
查看网络相关命令
brctl showstp br0
brctl show
网络配置如下:
# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eno1:
dhcp4: false
eno2:
dhcp4: false
ens9f0:
dhcp4: false
ens9f1:
dhcp4: false
bridges:
br0:
interfaces: [eno1]
dhcp4: false
addresses: [172.20.148.124/24]
gateway4: 172.20.148.1
nameservers:
addresses: [172.20.148.1,8.8.8.8]
version: 2
cp /var/lib/libvirt/images/ubuntu.raw /var/lib/libvirt/images/ubuntu20.02.qcow2
truncate -s 20G /var/lib/libvirt/images/zns01.raw
ls -l /var/lib/libvirt/images/zns01.raw
更新脚本中的网桥bridge,虚拟机系统盘文件vmimg,zns盘文件znsimg,vncNumber:vncNo
c# cat start-vm-0107.sh
#!/bin/sh
#
# Some variables
#
bridge="br0"
vmimg="/var/lib/libvirt/images/ubuntu20.02.qcow2"
znsimg="/var/lib/libvirt/images/zns01.raw"
vncNo="2"
nohup taskset -a 0xffff0 qemu-system-x86_64 \
-name guest=yhcubuntu20.02 \
-machine pc-q35-5.2,accel=kvm \
-m 16384 \
-smp 8,sockets=8,cores=1,threads=1 \
-rtc base=utc,driftfix=slew \
-nographic \
-no-hpet \
-global ICH9-LPC.disable_s3=1 \
-global ICH9-LPC.disable_s4=1 \
-boot strict=on \
-audiodev none,id=noaudio \
-object rng-random,id=objrng0,filename=/dev/urandom \
-msg timestamp=on \
-device pcie-root-port,port=0x10,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,addr=0x2 \
-netdev bridge,id=hostnet0,br=${bridge} \
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:fa:2d:b9,bus=pci.1,addr=0x0 \
-device pcie-root-port,port=0x11,chassis=2,id=pci.2,bus=pcie.0,addr=0x2.0x1 \
-blockdev node-name="vmstorage",driver=qcow2,file.driver=file,file.filename="${vmimg}",file.node-name="vmstorage.qcow2",file.discard=unmap \
-device virtio-blk-pci,bus=pci.2,addr=0x0,drive="vmstorage",id=virtio-disk0,bootindex=1 \
-device pcie-root-port,port=0x12,chassis=3,id=pci.3,bus=pcie.0,addr=0x2.0x2 \
-device virtio-balloon-pci,id=balloon0,bus=pci.3,addr=0x0 \
-device pcie-root-port,port=0x13,chassis=4,id=pci.4,bus=pcie.0,addr=0x2.0x3 \
-device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.4,addr=0x0 \
-device pcie-root-port,port=0x14,chassis=5,id=pci.5,bus=pcie.0,addr=0x2.0x4 \
-device nvme,id=nvme0,serial=deadbeef,zoned.zasl=5,bus=pci.5 \
-drive file=${znsimg},id=nvmezns0,format=raw,if=none \
-device nvme-ns,drive=nvmezns0,bus=nvme0,nsid=1,logical_block_size=4096,physical_block_size=4096,zoned=true,zoned.zone_size=64M,zoned.zone_capacity=62M,zoned.max_open=16,zoned.max_active=32,uuid=5e40ec5f-eeb6-4317-bc5e-c919796a5f79 \
-vnc 0.0.0.0:${vncNo} &
VNC 连接方式:{hostIP}:{vncNo}
如:172.20.148.124:5901
更新虚拟机IP ,执行“netplan apply”,示例如下:
# cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp1s0:
dhcp4: false
addresses: [172.20.148.202/24]
gateway4: 172.20.148.1
nameservers:
addresses: [172.20.148.1,8.8.8.8]
version: 2
此时,就可以通过虚拟机的IP 连接到 NVMe zns 设备 的虚拟机啦。