[KVM] Installing Virtio drivers in a KVM Windows guest VM

本文指导如何在Windows虚拟机中安装Fedora提供的Virtio驱动,以实现使用Virtio NIC和虚拟硬盘接口。通过创建额外的虚拟硬盘并启动虚拟机,然后安装必要的驱动,Windows可以识别并利用Virtio接口。详细步骤包括创建虚拟硬盘、启动虚拟机、安装驱动,并最终验证驱动安装成功。本文还包括针对Windows XP和Windows 7的特定驱动安装说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

KVM provides a Virtio interface for the virtual hard disk and NIC. To use them in a Windows guest VM, the drivers from Fedora (you only need the ISO file) must first be installed into Windows. To install them in a Windows guest VM, it must also be started with these interfaces so that Windows can detect them. While the Windows guest could be started with the Virtio NIC without any problems, we can not start with the Windows image (i.e. the virtual hard disk image where Windows is installed on your guest VM) using the Virtio hard disk interface (until the driver is installed, Windows will not know how to use the Virtio hard disk interface). The easiest solution to this problem is to create another virtual disk that can use Virtio:

1qemu-img create -f qcow2 <image name> <size>

Now, start the Windows VM with the Virtio interfaces:

1qemu-kvm \
2    -hda <path to your Windows guest image> \
3    -drive file=<your guest image file>,if=virtio \
4    -drive file=<path to Virtio driver ISO>,media=cdrom,index=1 \
5    -net nic,model=virtio \
6    -net user \
7    -boot d \
8    -vga std \
9    -m 1024

When Windows is loaded in your guest VM, go in to the Device Manager. Under Other Devices, there should be two entries – one for the SCSI controller to the the temporary virtual hard drive and the other for the Virtio network card.

On one of the items, right click on it and select Properties, go to the Driver tab. You should now see the following:

Click on Update Driver. In the next dialog, choose to specify a location and install the Red Hat Virtio drivers. The dialogs for installing the drivers will vary, depending on the installed version of Windows. It should be fairly easy to work how to install the drivers, but installing the drivers for Windows 7 and Windows XP are here if you need them ( skip to instructions for Windows 7).

Installing the Drivers on Windows XP

For Windows XP, choose Install from a list or specific location on the first prompt.

On the next set of options, choose Search for the best driver in these locations and ensure that Search removable media is ticked and click on Next again.

When installing the hard disk controller, you might be prompted, at this point, to choose a driver. At this point, choose the one in the wxp directory.

Eventually, you will probably be warned that you are installing an unsigned driver. Select Continue Anyway to install the driver.

When installation is complete, you should get a confirmation, similar to the following:

After repeating the steps for the other driver, you use the Virtio interface on your Windows hard disk image (see After Installing the Drivers…).


Installing the Drivers on Windows 7

For Windows 7, choose Browse my computer for driver software.

On the next screen, choose the drive for your CDROM. You should be able to let Windows search the CD for the drive.

When prompted, confirm that you want to install the driver.

There will be a confirmation that the driver was installed, similar to this one:

Close the dialog and repeat the steps for the other driver.


After Installing the Drivers…

After both drivers are installed, the device manager should contain a Red Hat VirtIO device for the SCSI controller and another one for the ethernet adapter.

Next time you start the guest VM, you can use the Virtio interface for the Windows image:

1qemu-kvm \
2    -drive file=<path to your Windows guest image>,if=virtio \
3    -net nic,model=virtio \
4    -net user \
5    -vga std \
6    -m 1024

Your Windows VM is now using the Virtio interfaces for your Windows virtual hard drive and NIC. If you wish to know more about Virtio and how it works, I suggest having a read of the article Virtio: An I/O virtualization framework for Linux.


Packer是一个开源工具,用于自动化操作系统映像的构建过程,包括Windows、Linux等。如果你想使用Packer创建一个定制的Windows镜像,并安装VirtIO(一种轻量级虚拟设备驱动)和Vminit(可能是Vagrant的一个组件,用于管理虚拟机),可以按照以下步骤操作: 1. **设置Packer配置文件**: 首先,你需要创建一个Packer JSON配置文件,例如`win.box.json`。在这个文件里,指定基础模板(如Microsoft Windows Server ISO)、操作系统版本以及自定义安装脚本。 ```json { "variables": { "iso_url": "your_iso_path", "virtio_driver_url": "your_virtio_driver_url" }, "builders": [ { "type": "msi", "source_url": "{{ user `iso_url` }}", "output_directory": "output", "guest_additions_share_dir": "C:/Program Files/VBox Guest Additions", "post-processors": [ ["vagrant", "package", "-o output/win.box"] ], "customization": { "cmdline": "/S / quiet / v:force / c 'echo Installing VirtIO... && (copy {{ user `virtio_driver_url` }} C:\\VirtIO || echo VirtIO driver installation failed)'" } } ] } ``` 2. **下载必要的软件**: - 找到并下载对应的Windows Server ISO。 - 下载VirtIO驱动程序,通常可以从虚拟化厂商的官方网站获取,比如QEMU的GitHub仓库。 3. **运行Packer**: 使用命令行工具(如Git Bash、PowerShell或CMD)运行`packer build win.box.json`,这将下载ISO、安装操作系统及驱动,并打包成Vagrant可用的box文件。 4. **验证和测试**: 创建完Vagrant虚拟机后,确认VirtIO驱动已成功安装并在虚拟机内工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值