KVM 使用virtio驱动Windows server 虚拟机

简介:

KVM安装Windows默认使用的是qemu虚拟化IDE硬盘模式,在这种情况下,IO性能比较低,如果使用virtio的方式可以提高虚拟机IO性能。而virtio所驱动的网卡,也将原来的百兆扩展到千兆。这里就简单介绍下如何使用virtio驱动安装window server 2008. 其它windows版本操作相同,只需选择对应的驱动即可。


使用virtio安装window虚拟机

KVM安装Windows需要使用virtio的驱动:

https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download 


安装虚拟机步骤:

1、安装virtio驱动:

1
wget https: //fedorapeople .org /groups/virt/virtio-win/virtio-win .repo -O  /etc/yum .repos.d /virtio-win .repo
1
yum  install  virtio-win -y

2、查看virtio-win提供的驱动:

1
2
3
rpm -ql virtio-win |  grep  iso
/usr/share/virtio-win/virtio-win-0 .1.126.iso
/usr/share/virtio-win/virtio-win .iso

3、安装windows:

创建一个虚拟机磁盘:

1
qemu-img  create -f qcow2 win-2c8g150g.img 150G

使用virtio驱动安装虚拟机:

1
2
3
4
5
virt- install  -n win-2c8g150g --vcpus=2 -- ram =8192 --os- type =windows --os-variant=win2k8 \
-c  /vm/iso/cn_windows_server_2008_r2_sp1_x64 .iso \
--disk path= /usr/share/virtio-win/virtio-win-0 .1.126_amd64.vfd,device=floppy \
--disk path= /vm/win-2c8g150g .img, format =qcow2,bus=virtio --graphics vnc,listen=0.0.0.0 \
--noautoconsole

提示: 这里是使用的是软盘方式加载,如果镜像和驱动都使用cdrom的方式加载,在有些情况系统会找不到启动镜像,导致无法启动. 加载的驱动有x86和amd64两种类型,64位系统选择amd64. 32为系统选择x86.

4、 安装过程中,在选择磁盘界面会找不到磁盘,选择“加载驱动”,“浏览”,找到“软盘驱动器”,点开后选择 “server 2008”确定,驱动加载完成后,磁盘就出现了,继续安装即可。


5、安装完成后,在设备管理器中可以看到使用的是virtio:

wKiom1mJM9vToPJuAAF7LT_WF-M343.jpg




在已安装的kvm虚拟机上添加virtio驱动


如果以传统的IDE硬盘模式安装可以使用如下命令:

1
2
3
virt- install   --virt- type  kvm --name win-2c8g100g  -- ram  8192  \
-vcpus=2 -s 100 -c  /vm/iso/cn_windows_server_2008_r2_sp1_x64 .iso \
--os- type =windows -f  /vm/win-2c8g100g .img --graphics vnc,listen=0.0.0.0 --noautoconsole


安装之后要使用virtio驱动,可以选择加载virtio驱动的iso文件到虚拟机光驱:

1
virsh  attach-disk  win-2c8g100g  /usr/share/virtio-win/virtio-win .iso  hdb  -- type  cdrom

或者使用如下命令:

1
virsh change-media win-2c8g100g hdb  /usr/share/virtio-win/virtio-win .iso

参考链接:https://superuser.com/questions/239870/change-cd-rom-via-virsh 


修改虚拟机的xml文件,使其能发现virtio类型的设备,否则驱动无法安装:

增加一块virtio驱动的硬盘:

1
qemu-img  create -f qcow2  test .img 1G

修改虚拟机的xml文件,在原有的"disk type"区域增加一个test磁盘的配置:   

1
2
3
4
5
  <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2' />
       < source  file = '/vm/test.img' />
       <target dev= 'vdb'  bus= 'virtio' />
     < /disk >

修改网卡类型为 virtio, 在 interface type 区域,修改model type='virtio' :

1
2
3
4
  <interface  type = 'bridge' >
       <mac address= '52:54:00:39:f9:60' />
       < source  bridge= 'br0' />
       <model  type = 'virtio' />

提示:如果不是使用vnc远程连接,需要新增一个网卡配置,在没有安装驱动前,使用上面的配置,虚拟机是断网状态。

修改完成之后,重启虚拟机:

1
2
virsh  shutdown  win-2c8g100g
virsh start win-2c8g100g


进入虚拟机,成功添加iso驱动程序后,进入虚拟机的设备管理器界面,在“系统设备”里面对相应的驱动进行更新:

更新驱动需要找到挂载的CD中 virtio-win.iso中的对应文件。驱动镜像中分别有四种驱动,他们对应关系为:

  • Balloon, the balloon driver, affects the PCI standard RAM Controller in the System devicesgroup.

  • vioserial, the serial driver, affects the PCI Simple Communication Controller in the System devices group.

  • NetKVM, the network driver, affects the Network adapters group. This driver is only available if a virtio NIC is configured. Configurable parameters for this driver are documented in Appendix A, NetKVM Driver Parameters.

  • viostor, the block driver, affects the Disk drives group. This driver is only available if a virtio disk is configured.

参考链接:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Mounting_the_image_with_virt_manager.html 



如果找不到英文说明中对应的设备,使用如下方式:

对未知设备添加virtio驱动即可,如图:wKiom1mJcb7QkcQhAAGRHg_CpEE735.jpg

安装驱动之后:

wKioL1mJcg7Sjv5TAAGNZdlc8LI143.jpg

对应的磁盘驱动成功安装:

wKiom1mJcnTDxwC4AAHyf7OtQOM892.jpg

此时virtio驱动添加完成,修改虚拟机的xml文件,删除test.img的虚拟磁盘配置,修改启动磁盘驱动类型:

1
2
3
4
5
6
     <disk  type = 'file'  device= 'disk' >
       <driver name= 'qemu'  type = 'qcow2' />
       < source  file = '/vm/win-2c8g100g.img' />
       <target dev= 'vda'  bus= 'virtio' />
       <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x07'  function = '0x0' />
     < /disk >

重启虚拟机即可。


参考链接:

https://access.redhat.com/solutions/17463 

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Installing_with_a_virtualized_floppy_disk.html

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Virtualization_Host_Configuration_and_Guest_Installation_Guide/form-Virtualization_Host_Configuration_and_Guest_Installation_Guide-Para_virtualized_drivers-Mounting_the_image_with_virt_manager.html  

http://blog.csdn.net/ks_is_fighting/article/details/38358793 




 本文转自 酥心糖 51CTO博客,原文链接:http://blog.51cto.com/tryingstuff/1954531

相关文章
|
6月前
|
安全 数据安全/隐私保护 虚拟化
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
1772 2
Windows Server 2022 中文版、英文版下载 (2025 年 10 月更新)
|
6月前
|
安全 Unix 物联网
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
761 0
Windows 7 & Windows Server 2008 R2 简体中文版下载 (2025 年 10 月更新)
|
6月前
|
存储 SQL 人工智能
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
Windows Server 2025 中文版、英文版下载 (2025 年 10 月更新)
998 0
|
7月前
|
运维 安全 网络安全
Windows Server 2019拨号“找不到设备”?Error 1058解决指南
Windows Server 2019拨号报错1058?别急!这不是硬件故障,而是关键服务被禁用。通过“服务依存关系”排查,依次启动“安全套接字隧道协议”“远程接入连接管理”和“路由与远程访问”服务,仅需4步即可恢复PPPoE或VPN拨号功能,轻松解决网络中断问题。
579 1
|
7月前
|
安全 Linux iOS开发
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
341 0
SonarQube Server 2025 Release 5 (macOS, Linux, Windows) - 代码质量、安全与静态分析工具
|
Windows
7、Windows驱动开发技术详解笔记(3) 基本语法回顾
    3、文件读写   在ring3 我们可以使用CreateFile、ReadFile 、WriteFile 等API,在ring0 同样很相似,不过函数变成了ZwCreateFile、ZwReadFile、ZwWriteFile 等内核函数。
1145 0
|
安全 分布式数据库 API
6、Windows驱动开发技术详解笔记(2) 基本语法回顾
    1、字符串   Unicode 字符串有一个结构体定义如下: typedef struct _UNICODE_STRING { USHORT Length; // 字符串的长度(字节数) USHORT MaximumLength; // 字符串缓冲区的长度(字节数) PWSTR Buffer; // 字符串缓冲区 } UNICODE_STRING, *PUNICODE_STRING; 需要注意的是,当我们定义了一个UNICODE_STRING 变量之后,它的Buffer 域还没有分配空间,因此我们不能直接赋值,好的做法是使用微软提供的Rtl 系列函数。
1349 0
|
Windows 数据库连接 存储
8、Windows驱动开发技术详解笔记(4) 基本语法回顾
 4、注册表操作 和文件操作类似,在操作注册表之前需要首先打开注册表,获得一个句柄,这可以通过函数ZwCreateKey 完成。与ZwCreateFile函数类似,它通过一个OBJECT_ATTRIBUTES 获得需要创建或打开的路径信息,但在内核中这个路径与用户模式下不相同,实际上,因为用户模式下的应用程序总是由某个“当前用户”打开的,因此在用户模式下可以直接访问HKEY_CLASSES_ROOT 和HKEY_CURRENT_USER,但工作在内核模式下的驱动程序不属于任何一个用户,因此不能直接访问这两个根键。
1049 0
|
Windows API
9、Windows驱动开发技术详解笔记(5) 基本语法回顾
    5、在驱动中获取系统时间 1)获取启动毫秒数  在ring3 我们可以通过一个GetTickCount 函数来获得自系统启动开始的毫秒数,在ring0也有一个与之对应的KeQueryTickCount 函数。
1214 0
|
Windows API 数据格式
10、Windows驱动开发技术详解笔记(6) 基本语法回顾
7、I/O Request Package,输入输出请求包 1)基本概念 IRP 的全名是I/O Request Package,即输入输出请求包,它是Windows 内核中的一种非常重要的数据结构。
1231 0