Bobcares

How to Use KVM to Boot Windows from a Physical Disk

by | Oct 27, 2024

Learn how to use KVM to boot Windows from a physical disk. Our KVM Support team is here to help you with your questions and concerns.

How to Use KVM to Boot Windows from a Physical Disk

Did you know that running Windows from a physical disk within a KVM environment lets us use an existing Windows installation on a physical hard drive as the virtual machine’s disk?

How to Use KVM to Boot Windows from a Physical Disk

In fact, this technique lets us run Windows virtually without creating a new disk image, benefiting from direct hardware access and improved performance.

In a typical KVM setup, a virtual machine uses a disk image file, such as QCOW2 or RAW format, as its virtual hard disk. However, with KVM, we can use a physical Windows installation directly from the physical disk—be it an internal drive or an external one.

This approach is called disk pass-through. It allows the VM to access the disk directly, providing full read and write access. Changes made in the VM will affect the physical installation.

An Overview:

Why Use a Physical Disk with KVM?

  • Direct disk access can significantly improve performance compared to using virtual disk images, especially for I/O-intensive tasks.
  • This setup leverages the full hardware capabilities, including specific drivers and hardware optimizations.
  • It simplifies the migration of a physical Windows installation to a virtual environment, as there’s no need to create or manage virtual disk images.

Before getting started, we need to meet these requirements:

  • Make sure KVM, QEMU, and related virtualization packages (e.g., libvirt) are installed on the Linux host.
  • Have a functioning Windows installation on a separate physical disk.
  • Always back up important data before proceeding.
  • We will need administrative privileges on the Linux host.

How to Boot Windows from a Physical Disk in KVM

  1. Run the following command to identify the disk containing the Windows installation:

    lsblk

    This command lists block devices, displaying drives and partitions. Locate the device name for your Windows disk (e.g., `/dev/sdb`).

  2. Before passing the disk to KVM, unmount it from the Linux host using:

    sudo umount /dev/sdb*

    This step ensures no partitions on the disk are in use, preventing data corruption.

  3. Then, make sure that KVM (or the QEMU process) has permission to access the disk. So, check the current user groups:

    groups

    If we are not part of the KVM group, we have to add ourself to it:

    sudo usermod -aG kvm $USER

    Then, log out and back in for the changes to take effect.

  4. Now, we have two options for configuring the KVM virtual machine: using Virt-Manager (GUI) or virsh (CLI).

Option 1: Using Virt-Manager (GUI)

  1. First, open Virt-Manager from the Linux desktop.
  2. Now, ti is time to create a new VM. So, select “Import existing disk image.”
  3. Then, choose the physical disk instead of an image file.
  4. Next, specify the path to the physical disk (e.g., `/dev/sdb`).
  5. After that, assign CPU and memory resources.
  6. Now, set the boot mode (EFI/BIOS) to match the Windows installation.
  7. Finally, complete the configuration and start the virtual machine.

Option 2: Using virsh (CLI)

  1. First, save the following XML as `win10-physical.xml` :

    <domain type='kvm'>
    <name>Windows10</name>
    <memory unit='KiB'>8192000</memory>
    <vcpu placement='static'>4</vcpu>
    <os>
    <type arch='x86_64' machine='pc-i440fx-2.11'>hvm</type>
    <boot dev='hd'/>
    </os>
    <devices>
    <disk type='block' device='disk'>
    <driver name='qemu' type='raw'/>
    <source dev='/dev/sdb'/>
    <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='network'>
    <model type='virtio'/>
    </interface>
    <input type='mouse' bus='usb'/>
    <input type='keyboard' bus='usb'/>
    <graphics type='vnc' port='-1'/>
    </devices>
    </domain>

     

    We can adjust paths as needed.

  2. Then, define the virtual machine:

    sudo virsh define win10-physical.xml

  3. After that, start the virtual machine:

    sudo virsh start Windows10

Install Drivers for Enhanced Performance

To improve the VM’s performance, we need to install Virtio drivers for Windows, which optimize disk I/O and networking. Additionally, we can use SPICE with QXL drivers for better graphics performance.

Potential Issues

  • Windows may require reactivation due to hardware differences when running in a VM.
  • While faster than virtual disk images, performance may not be as high as a native Windows installation, especially for graphics-heavy workloads.

Furthermore, if we plan to dual-boot between native Windows and KVM, we have to address potential driver conflicts.

Also, modifying disk configurations always carries risks. So, we need to back up important data before making changes.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Booting Windows from a physical disk in KVM is an effective way to enhance virtual machine performance and leverage existing installations. With the above steps, we can successfully set up and run Windows directly from a physical disk within a KVM environment.

In brief, our Support Experts demonstrated how to use KVM to boot Windows from a physical disk.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.