qemu支持大量的设备仿真,例如网卡,usb,磁盘等。这些设备的配置容易让人困惑,下面的内容有助于理解它们。
一 前端
前端指的是设备如何呈现给guest的,也就是guest系统内部看到的设备类型。qemu通过命令行 -- device指定前端设备,执行接" -- device help"的qemu命令,可以查看qemu支持模拟的所有设备。
libvirt支持的前端设备类型包括"ide", "scsi", "virtio", "xen", "usb", "sata", or"sd"等等,由xml中target元素bus属性指定。
二 后端
后端指的是host侧的设备,qemu通过命令行 -- drive指定后端设备,并定义qemu如何后端设备上的数据。
libvirt支持的后端设备非常多,其中存储设备包括"file", "block", "dir", "network", "volume", "nvme", "vhostuser",由xml中disk元素type属性指定。
三 总线
大部分设备都在总线上。设备在总线上的地址通常是自动分配的,也可以显式指定。libvirt支持的总线类型包括"pci", "drive", "virtio-serial", "ccid", "usb"等等.详见 : https://libvirt.org/formatdomain.html#device-addresses
四 qemu命令行和xml
前端设备类型为virtio-blk-pci,总线类型为pci,后端设备为qcow2镜像。
1 qemu命令行
-device virtio-blk-pci, iothread=iothread1, scsi=off, bus=pci.0, addr=0x4, drive=drive-virtio-disk0, id=virtio-disk0, bootindex=1,write-cache=on drive file=/home/hj/vm/v4.05-snap1.qcow2, format=qcow2, if=none, id=drive-virtio-disk0, cache=none, aio=native
2 xml
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2' cache='none' io='native' iothread='1'/>
<source file='/home/hj/vm/v4.05-snapl.qcow2'/> #指定后端设备
<target dev='vda' bus='virtio'/> #指定前端设备
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>