1. 程式人生 > 其它 >kvm裡的虛擬機器硬碟和網絡卡使用virtio驅動

kvm裡的虛擬機器硬碟和網絡卡使用virtio驅動

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>