全部文档
当前文档

暂无内容

如果没有找到您期望的内容,请尝试其他搜索词

文档中心

如何安装virtio驱动(Windows)

最近更新时间:2019-05-31 16:49:25

1 安装virtio驱动

Windows镜像需要用户自行安装virtio驱动。

下面简单介绍一下在KVM环境下,为Windows系统安装驱动的方法。

驱动文件准备

下载地址:https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.149-2/ 选择virtio-win-0.1.149.iso 文件下载

创建占位盘的步骤为:

1.提前创建6个小用量(10GB)QCOW2格式的虚拟磁盘文件,分别模拟swap disk(1个)与数据盘(5个);

2.假设创建的另个占位盘的命名(disk.swap,disk1,disk2,disk3,disk4,disk5),这在编辑Libvirt XML配置文件时,对应的virtio PCI设备号,分别是0x06,0x08,0x09,0x0a,0x0b,0x0c
注意:virtio PCI设备号的0x5,与0x7被其他设备占用,不能使用,稍后会有介绍其用于什么设备。

网络:
需要有模拟线上环境的双网桥网络,分别模拟对应内网与外网,如:br0,br_vm等。

配置:
将要安装virtio驱动的镜像和上边提到的占位盘、网络和下载包含驱动文件的ISO文件的信息添加到要创建的虚机的libvirt xml中。之后启动虚机,就可以通过VNC等方式进入虚机内部进行安装配置。

安装:
如果按照上边的步骤执行完成,进入Windows虚机后,进入Windows工具”设备管理器”中,会发现很多带有问号的设备,它们就是virtio设备,目前Windows没有关于这些设备的驱动所以显示的是问号。

微信图片_20180621173522.png

依次右键选择有问号的设备,选择”更新驱动程序软件”,在弹出的对话栏中选择”浏览计算机以查找驱动程序软件”,

微信图片_20180621173555.png

微信图片_20180621173630.png

由于之前的virtio驱动文件已经现在配置在了这台虚机的libvrit xml中,它将以分区挂载的形式显示,如下图这种情况,在输入框中选择’D:\’,点击下一步,安装程序能够自动检测驱动程序,当然用户可以指定准确的路径进行安装。

微信图片_20180621173704.png

微信图片_20180621173728.png

示例如下:

准备工作

  1. 网络正常的linux环境。查看 cpu 是否支持安装,输出 vmx 表示支持。
    $ grep -Ei "svm|vmx" /proc/cpuinfo

  2. 安装qemu-kvm,qemu-img和libvirt。

# centos 6
$ sudo yum install libvirt-daemon libvirt-client qemu-kvm qemu-img

# ubuntu
$ sudo apt-get install libvirt-daemon libvirt-clients  qemu-kvm qemu-utils  bridge-utils libvirt-daemon-system ebtables

根据软件依赖,一般会提示按照许多包,如果所需要的包和当前不冲突的话,可以直接输入"y",回车安装。(ubuntu 可以参考https://help.ubuntu.com/community/KVM/Installation)

  1. 启动libvirtd服务
# centos 6
$ sudo /etc/init.d/libvirtd start
$ /etc/init.d/libvirtd status
# ubuntu
$ sudo systemctl start libvirtd.service
  1. 下载驱动包(下载地址 https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio)
$ wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.110-1/virtio-win-0.1.110.iso
  1. 添加bridge
$ sudo brctl addbr br0
$ sudo ifconfig br0 up
  1. 编辑/etc/qemu/bridge.conf。
$ cat /etc/qemu/bridge.conf
allow all
  1. ubuntu需要添加权限
$ sudo chmod +s /usr/lib/qemu/qemu-bridge-helper
  1. 加载kvm模块
$ modprobe kvm
$ lsmod | grep kvm
kvm_intel             212992  4
kvm                   598016  1 kvm_intel
irqbypass              16384  1 kvm
  1. 可能需要手动创建kvm,libvirt,libvirt-qemu,libvirt-dnsmasq的用户或组。

安装驱动

1.参照文档创建占位盘(https://docs.ksyun.com/documents/5429 )

qemu-img create -f qcow2 Windows_Server.1.img 10G
qemu-img create -f qcow2 Windows_Server.2.img 10G
qemu-img create -f qcow2 Windows_Server.3.img 10G
qemu-img create -f qcow2 Windows_Server.4.img 10G
qemu-img create -f qcow2 Windows_Server.5.img 10G
qemu-img create -f qcow2 Windows_Server.6.img 10G

2.编辑libvirt daemon xml
先获取qemu-system-x86_64的路径

$ which qemu-system-x86_64

将路径修改到下面xml的emulator。
使用编辑器,将下列代码保存为libvirt.xml。

<domain type='kvm'>
  <name>windows2012zh</name>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='localtime'>
    <timer name='rtc' tickpolicy='catchup'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
  <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file=''/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/virtio-win-0.1.110.iso'/>
      <target dev='hdc' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.1.img'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.2.img'/>
      <target dev='vdc' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.3.img'/>
      <target dev='vdd' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.4.img'/>
      <target dev='vde' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.5.img'/>
      <target dev='vdf' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0b' function='0x0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/lqm/Downloads/import-image/Windows_Server.6.img'/>
      <target dev='vdg' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0c' function='0x0'/>
    </disk>
    <controller type='usb' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <interface type='bridge'>
      <mac address='fa:16:3e:32:19:f1'/>
      <source bridge='virbr0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='ea:16:3e:57:7a:fa'/>
      <source bridge='br0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='1'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='1'/>
    </console>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='vga' vram='9216' heads='1'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
  </devices>
</domain>

3.创建目标镜像的后继镜像,或者直接对镜像进行操作。

$ qemu-img create -f qcow2 -b Win2012R2.qcow2 Win2012R2.qcow2.init
Formatting 'Win2012R2.qcow2.init', fmt=qcow2 size=53687091200 backing_file='Win2012R2.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16

将Win2012R2.qcow2.init的绝对路径编辑到libvirt.xml中第一个disk的source处。

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
  <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
  <target dev='hda' bus='ide'/>
  <address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>

4.注册domain

$ virsh define libvirt.xml
Domain windows2012zh defined from libvirt.xml

5.启动虚拟机

$ virsh start windows2012zh
Domain windows2012zh started

6.获得vnc地址。

$ virsh vncdisplay windows2012zh
:0

故vnc地址为127.0.0.1:0
使用vnc client登录127.0.0.1:0,即进入虚机。

7.安装驱动。

(1).右键计算机->属性->进入设备管理器。可以看到SCSI 控制器和以太网控制器的驱动没有安装。 选由上而下第一个以太网控制器,右击,点击“更新驱动程序”,之后选择“浏览计算机以查找驱动程序软件”。

1.png

填写安装驱动程序的路径,按照上边的libvirt xml配置后,虚机只有一个CD-ROM,路径:“D:”,选择“下一步”。在安装驱动程序时,Windows会警告此驱动程序没有经过微软签名,此时点击“始终信任Red Hat,Inc的软件”,然后点击安装。

同上,安装第二个以太网控制器驱动程序。
完全安装成功的状态如下:

2.png

(2).同上一步进入Windows的设备管理器。
右击“SCSI控制器”,点击“更新驱动程序”,之后选择“浏览计算机上的驱动程序”。填写安装驱动程序的路径,如果只有一个CD-ROM,路径:“D:”,选择“下一步”。
3.png

同上,安装第二~六个SCSI控制器驱动程序。完全安装成功的状态如下。

4.png

(3).将虚机关机,编辑Libvirt XML中Windows Guest 所使用虚拟磁盘总线类型与驱动类型如下,使系统盘也使用virtio驱动:

变更前:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
  <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
  <target dev='hda' bus='ide'/>
  <address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>

变更后:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' cache='none'/>
  <source file='/home/lqm/Downloads/import-image/Win2012R2.qcow2.init'/>
  <target dev='vda' bus='virtio'/>
  <address type='pci' domain='0x000' bus='0x00' slot='0x05' function='0x0'/>
</disk>

(4).重新启动虚机,成功登入系统,设备管理器中无未知设备,驱动无异常,完成驱动安装。

  1. 如果使用了后继.init镜像完成上边的更新步骤,需要将镜像进行合并。新生产的后缀.base的镜像可以上传KS3。
$ qemu-img convert -f qcow2 -O qcow2 Win2012R2.qcow2.init Win2012R2.qcow2.base
  1. 按照文档(https://docs.ksyun.com/documents/5335)中“三、镜像导入流程”,的步骤完成导入镜像。
文档导读
纯净模式常规模式

纯净模式

点击可全屏预览文档内容
文档反馈