I have a dual-boot configuration with Linux and Windows. Now, I would like to keep dual-boot setup and also be able to run Windows inside of KVM on Linux.

The following configuration works fine. I include the entire disk (/dev/sda) inside of KVM. For running Windows, I created an ISO image of grub (grub-mkresque), which has been configured to boot Windows from its partition (/dev/sda2). However, I am not happy with this solution, because the Windows guest then gets access to the whole disk with all partitions.

This, as commenters @telcoM & @kenneth-b-jensen had also pointed out, is/should_be part of my strategy to avoid corruption by avoiding concurrent access/mounting by both OSs.

The desired solution is only to include the Windows partition (/dev/sda2) and then start Windows from there. Because this partition is not bootable, I cannot boot Windows just from there. Because KVM apparently binds the single partition to a disk with its own partition table, grub from my image cannot find the corresponding partition from which to boot.

I need to finalize the configuration or some other idea to get a working configuration.

  • Use VirtualBox because it provides the possibility to create an image for raw disk access keeping the partitioning table, but specifying only the necessary partitions. IMHO, one should avoid this, as KVM brings more performance.

  • Find a solution to keep the partition table (as described above) with KVM.

  • Set up grub to use the proper partition inside of KVM. I would like to receive expert guidance on configuring grub according to the goals.


3 Answers 3


I've tried to run the same Windows disk alternately on hardware and inside a virtual machine, but always failed because the devices presented inside the virtual machine are different than the actual hardware.

But drawing on your "some other idea" clause, let me explain how I run Linux and Windows on the same machine.

Windows is running in a KVM virtual machine, but virt-viewer has control of one virtual console. It appears for all the world as if it's a dedicated Windows machine when I switch to that console. And I can log into and out of Linux and Windows independently. (And with Cygwin installed on Windows, I can ssh between them.)

These are roughly the steps I took to set it up. I downloaded the .iso from Microsoft and bought a license separately. You may be able to reinstall your existing Windows license.

sudo vgcreate vg0 /dev/sd...
sudo lvcreate --size 128G --name win10 vg0
sudo virt-install --name Windows --connect qemu:///system --virt-type kvm --disk path=/dev/vg0/win10,format=raw --cdrom '<path>/Win10_1607_English_x64.iso' --network bridge=br0 --video qxl --chanel spicevm,target_type=virtio --graphics spice,listen=,port=5900 --os-variant win10 --memorybacking nosharepages=true --memory 2048 --vcpus 1

I've created a network bridge device br0 on the Linux host so I can transparently connect virtual machines. But that's a separate topic.

The virt-install command brings up virt-viewer automatically the first time, which brought up the Windows 10 installation program. The only disk it sees is the virtual disk I created and put on the virt-install command-line. Then I boot it subsequently:

virsh --connect qemu:///system start Windows

That starts the machine, but doesn't view the output. To view the output, I switch to an unused virtual console pressing e.g. CTRLALTF6 and enter this command. Note that we're starting an X app (virt-viewer) directly on an X server with no window manager.

The -k switch puts virt-viewer in kiosk mode which effectively hides the fact that it's really running in a virtual machine.

startx /usr/bin/virt-viewer -a -k -r -w -c qemu:///system Windows -- :6  -config CtrlAltBksp.conf -nolisten tcp -novtswitch

The CtrlAltBksp.conf file is optional. It allows you to shutdown virt-viewer by pressing CTRLALTBackspace. It must be put in /etc/X11/ on the host, or another directory that xorg knows about. Here it is:

Section "ServerFlags"
        Option "DontZap" "false"
Section "InputClass"
        Identifier "CTRL_ALT_BACKSPACE"
        MatchIsKeyboard "on"
        Option "XkbOptions" "terminate:ctrl_alt_bksp"

Note: You don't need to install with spice and qxl as I did, but if you do, it's best to install the spice tools.


I've ran a few operating systems installed for dual-boot side-by-side with QEMU residing on disks, but I don't think ever one without a bootloader.

If you're booting with UEFI, you will need to use OVMF for QEMU, which means things have gotten much hairier and out of the scope of my knowledge.

Try installing & configuring GRUB on the Windows partition, or booting a Windows rescue/install media with QEMU (otherwise, Windows will eat GRUB) and reinstalling to get a Windows bootloader back. To install GRUB, use grub-install /dev/sdxY, mount the filesystem, and run grub-mkconfig -o /mnt/grub/grub.cfg. Then, copy over just what you need from your existing grub.cfg, and edit it as necessary -- feel free to ask for help in this thread.

Another option is doing some research on just installing a bootloader natively on Windows.

The nuclear option is something along the lines of creating an .img file the same size as your Windows partition with qemu-img, reinstalling Windows via QEMU to that file, and copying everything after a certain offset from the partition (probably just past the first 1024 cylinders or so) to the .img file with dd.

A very dangerous option is to continue using your existing GRUB to chain-boot into windows by using all of your disks with the read-only option. See @telcoM's comment on the OP; DO NOT RUN A VIRTUAL MACHINE ON A DISK THAT IS IN-USE BY THE HOST! THE FILESYSTEM WILL BE CORRUPTED AND UNRECOVERABLE! (ONLY unless it's used read-only by the guest.) Try qemu-xxxxxxx -drive file=/dev/sdxX,format=raw,readonly.

Nonetheless, QEMU can run a raw disk:

qemu-xxxxxxxx -drive file=/dev/sdxY,format=raw (see man 1 qemu & search for -drive for more information).

If you haven't much experience with QEMU/KVM, running & configuring it directly from the command-line can be intimidating and frustrating -- consider a front-end for your health.

  • I've added an answer about creating an abstraction of the physical disk with same size/"geometry"/partition-table etc as the real disk, but with the Linux partitions "blanked" out by using zero targets in the dmsetup table map. Sounds like that would fit some of your usecases too. Feb 8, 2019 at 16:25

You can use dmsetup from the tools with the --table option to "construct" a resembling your /dev/sda by specifying a table file (Search "Table Format").

You could use read-only maps (or copies) of some partitions like the EFIBOOT partition, and the /, along with some zero targets for "replacing" your Linux-partitions in that map. Just make sure you include the real Windows partition(s) in the table map, and at the right location in the table.

I have used this in the past for a similar endeavor, and this is most likely the mechanism uses under the hood on Linux to construct of custom, composed block devices.

Make sure, none of your partitions are mounted/accessed by more than one OS at a time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.