1.首先從虛擬機的xml文件中找到已經使用virtio驅動的硬件,復制里面的address這行參數出來
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
說明:這里面的slot參數是需要修改的,不能重復
因此硬盤slot使用0x08
,網卡使用0x09
2.找到硬盤的配置內容所在
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/home/kvm/generic.qcow2'/>
<target dev='hda' bus='ide'/> # ide換成virtio
<address type='drive' controller='0' bus='0' target='0' unit='0'/> # 這行換成這個:<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</disk>
3.找到網卡的配置內容所在
沒有切換使用橋接網絡的配置,默認的NAT配置
<interface type='network'>
<mac address='52:54:00:30:06:32'/>
<source network='default'/>
<model type='rtl8139'/> # 需要修改這個rtl8139為virtio
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> # 這行修改成 <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
</interface>
切換使用橋接網絡的配置
<interface type='bridge'>
<mac address='52:54:00:30:06:32'/>
<source network='br0'/>
<model type='rtl8139'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
切換使用virtio驅動的配置
<interface type='bridge'>
<mac address='52:54:00:30:06:32'/>
<source bridge='br0'/>
<model type='virtio'/> # 修改后的效果
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/> # 修改后的效果
</interface>