kvm里的虚拟机硬盘和网卡使用virtio驱动

1.首先从虚拟机的xml文件中找到已经使.

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'/> # 换成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>

attach-disk win10 /data2/virtio-win-0.1.221.iso hda –type cdrom –mode readonly