Installing Windows VM on unclaimed sectors of a drive with QEMU/KVM

Posted on

Problem :

I have a single 500 GB NVMe drive. I’m using GPT and I have the following partitions:

  1. 1G of ef00 / EFI System for /boot
  2. 4G of 8200 / Linux swap
  3. 245G of 8300 / Linux filesystem for a Linux install, my host/primary OS

The rest of the drive, 250G, is free space. I’d like to use it for my Windows 10 VM, virtualized with KVM, while avoiding as much overhead as possible. I’ve seen three approaches to this:

  1. Have a single large partition, and put a raw image on it.
  2. Have a second 8300 partition, and pass it as a disk to KVM.
  3. Software RAID trickery (the complexity is off-putting).

However, I was wondering, is there any way to let the Windows 10 installer take care of the free space partitioning for me, by giving it access to a certain range of sectors, and pretending that it’s an actual standalone physical drive?

Alternatively, wouldn’t it be possible for me to just pre-allocate all necessary partitions for Windows (namely a system partition, an MSR, a Windows partition, and a recovery tools partition, as described here), and somehow pass them to KVM?

And my theories aside, what’s the best performance-first solution? I’ve googled this for a while, but no luck. Not even a single anecdote or casual comparison, not to mention proper benchmarks.

Solution :

So there are two levels to consider, in the Windows guest having a single system drive with multiple partitions is probably the easiest to setup. It is also low overhead since a partition table (or dynamic disk meta data) is basically only a mapping of sector offsets.

On the host you can provide a disk from a physical disk or a disk partition or a logical volume. Those three options basically have the same overhead (negligible sector offset calculations).

If you put the device in a file then the overhead is a bit bigger since it has to go through the filesystem translation layer.

I would probably go with a logical volume or even file to have the flexibility benefit of multiple clones, snapshots and be able to resize. That depends on what are you doing. If you regularly have to try different software and Windows versions it is better to have a less static setup. With fixed volumes you get the performance advantage of avoiding the host filesystem.

Leave a Reply

Your email address will not be published.