in qemu/kvm, can I mount a host partition as a virtual disk drive?

user691307 picture user691307 · Oct 11, 2011 · Viewed 8.9k times · Source

I have a new laptop with a Windows partition and a Linux partition. I want to run qemu/kvm under Linux, and run an instance of Windows XP on that virtual machine. The desired setup is to have a virtual disk (in a Linux host file) as the C: drive on the virtual machine, and the underlying host Windows partition as the D: drive on the virtual machine. This is the setup I have been using for a while under VirtualBox on another laptop. Is it possible to do this with qemu/kvm?

One note - I don't have the Windows partition mounted under Linux, so the virtual machine instance would have the Windows partition all to itself. I would prefer the Windows partition to be read/write, but that is not absolutely necessary.

Thanks in advance,

Greg Johnson

Answer

kaapstorm picture kaapstorm · Nov 3, 2011

I am pretty sure what you want to do can be done. You would need to ...

  1. Create a file for the master boot record to be used by qemu/kvm
  2. Mount it as a loop device
  3. Prepend it to your Windows partition using software RAID

Then start QEMU using the RAID device as "-hdc" for drive C: or "-hdd" for drive D:. The drive would be read-write.

You can find detailed instructions at the Arch Linux QEMU wiki page.