When you ask people why they don’t switch to Linux, you often hear the argument that certain applications are not available. Many users are aware that most of the time they just need a browser. But this one application, be it online banking or graphics software, prevents the change.

In many cases, this problem can be avoided by simply virtualizing Windows. The prerequisite is that the hardware is powerful. An i5 or i7 processor and 16 GB RAM are currently ideal. The necessary tools to convert a Windows installation into a virtual machine are manifold and mostly available free of charge.

In this article, I’ll show you how to convert an existing Windows installation into a virtual machine and how to make it ready for use under Linux.

Prerequisites are:

  • A PC with Windows 10
  • A large USB hard disk which can store the image of the existing Windows
  • A modern PC with Linux. I use and recommend Fedora 29.
  • Solid knowledge of Windows and Linux.

Step 1: Export your Windows Installation

What parts of your Windows installation do you need? Be aware that your Windows consists of several partitions, even if you can only see “one” drive C:. In addition to the actual data partition for drive C:, an EFI partition and a recovery partition are usually created during Windows 10 installation. Of course, we take these partitions with us into the virtual machine.

When copying the system, a lot of data will be generated. It’s best to get yourself a large hard disk that would be able to record your installation twice. Format the hard disk under Windows (not Linux) with NTFS file system.

Disk2VHD from Microsoft is a good tool for creating an image of the system. You can download it here. Copy and unpack it to the backup hard disk and then start it from there.

Select the system partitions. In case of doubt, simply take everything with you, except the backup hard disk of course.

Step 2: Convert into KVM/QEMU image

After you have created the image of your Windows installation, we continue in Linux. There you first have to convert the VHDx file into the qcow2 format. Then the virtual Windows is set up with the Manager for Virtual Machines. Finally, drivers have to be installed.

Open a terminal in Linux. Use the command qemu-img to convert the VHDx file.

qemu-img convert -O qcow2 <original>.vhd <copy>.qcow2

You can use the qemu-img command to copy your qcow2 file to your home folder while you are converting it. Example:

qemu-img convert -O qcow2 /path/to/backup/disk/filename.vhd /home/username/filename.qcow2

Step 3: Add virtual Machine

3.a: Using the Graphical User Interface

Start the virtual machine manager. It comes preinstalled in Fedora 29.

Choose “File” -> “New Virtual Machine”

Choose “Import existing disk image” and click “Forward”.

Click Browse and then click “Browse local” to choose the .qcow2 file. As OS type choose “Windows” and the Version “Microsoft Windows 10”. Click “Forward”.

Make a decision how much RAM und how many CPU cores you can dedicate to the virtual machine. I recommend at least 4GB (4096 MB) of RAM and 4 CPU cores. Click “Forward”.

Type in a name for your virtual machine and select “Customize configuration before install”. This is important! Click “Finish”.

It is important that you choose “UEFI x86_64” as firmware. Most modern PC use UEFI instead of Bios. This setting depends on your Computer. If you are coming from a PC which had Windows 7 installed and then upgraded to Windows 10, it is likely that “BIOS” is the right setting for you. If you are coming from a newer PC where Windows 10 was preinstalled then “UEFI” will be the correct setting.

Click “Apply” (bottom right) and then “Begin Installation” (top left).

3.b: Using the Command Line Interface

Alternatively you can create the virtual machine using the command line interface tool “virt-install”.

sudo dnf install virt-install
sudo virt-install --name <machine name> --memory 4096 --vcpus 4 --boot uefi --disk </path/to/image.qcow2> --os-variant win10

When using virt-install, the machine will automatically start. Open the virtual machine manager to connect to it.

The virtual machine is now starting. The screenshot above shows the UEFI boot screen.

Step 4: Install Drivers in Windows

The final step is to install the “spice-vdagent” drivers in Windows 10. With these drivers you can resize the virtual machine’s graphical output freely and integrate the virtual machine into your Linux.

Go to the website spice-space.org and click “Download”. Scroll down to “Guest” -> “Windows Binaries” and download the “spice-guest-tools“. Install these tools in your windows and restart.

After restarting you can set the display scaling option “Auto resize VM with window”.

Further reading