Step-by-Step Guide: Creating a Windows Virtual Machine (VM) in Linux with KVM
Introduction
Virtualization technology allows running multiple operating systems on a single machine. This tutorial will guide you through the process of setting up a Windows virtual machine (VM) on Linux using Kernel-based Virtual Machine (KVM) for improved performance and efficiency.
1. Install and Configure the Necessary KVM Software
Check Your CPU
As a first step, you need to check if your CPU supports virtualization and whether it's enabled on your system. To do so, run:
grep -Ec '(vmx|svm)' /proc/cpuinfo
If the number shown is higher than 0, virtualization is on, and you're good to go. If not, restart your computer, enter BIOS settings, and switch on virtualization support.
Once virtualization is ready, get the necessary KVM packages from your distribution's repositories. The command to install them will differ based on the Linux distribution you have.
Installing KVM and Essential Tools
Debian Or Ubuntu
sudo apt install qemu-kvm libvirt-daemon bridge-utils virt-manager
Arch Linux
sudo pacman -S qemu-kvm libvirt bridge-utils virt-manager
Fedora and RHEL
sudo dnf install @virtualization
Next, enable and start the libvirt daemon by running:
sudo systemctl enable libvirtd
sudo systemctl start libvirtd
Check whether libvirtd is running properly with:
sudo systemctl status libvirtd
If the output returns "active" in green, you can safely proceed. If it displays "inactive" in red, run the above commands again.
Finally, add your user to the libvirt and kvm groups with:
sudo usermod -aG libvirt $(whoami)
sudo usermod -aG kvm $(whoami)
2- Download the Windows 10 ISO
With virtualization configuration out of the way, you're now ready to create a virtual machine. But first, download the Windows 10 ISO file that you'll use to boot the VM.
Head over to the Windows 10 downloads page and scroll down to select Windows 10 (multi-edition ISO) from the Select edition dropdown menu. Then, click Confirm.
3- Create a New KVM Using virt-manager
Launch Virtual Machine Manager by typing virt-manager in the command line or from the applications menu.
Click the Create a new virtual machine option (the desktop icon with a play button in the middle) to continue
Continue with the default selection—Local install media—and click Forward.
Click Browse > Browse Local and select the downloaded Windows 10 ISO file from your storage. Click Open to select the ISO image. Virtual Machine Manager will automatically detect the OS. Click Forward to proceed.
Specify the amount of memory and CPU cores you want to allocate to the virtual machine. For starters, half of your computer's actual memory will be more than enough. Regarding CPU cores, select anything ranging from one-third to half of the available cores. Once done, hit Forward.
On the following window, make sure Enable storage for this virtual machine is checked off. Then, specify the size of the disk image (50GB will suffice) and click Forward.
Type in the virtual machine's name and click Finish once you've reviewed the VM specifications.
4- Install Windows 10 on the KVM
A new Virtual Machine Manager window will pop up, within which you can see your Windows machine booting. The screen will turn blue and you'll see the Windows Setup box appear.
Select the Language to install, Time and currency format, and Keyboard or input method from the list of available options. Once done, hit Next > Install Now.
The setup process will now start and you'll be asked to enter a product key. Type in the product key if you have one. Otherwise, select I don't have a product key.
There are different versions of Windows 10 you can install. Choose the one you'd like to install and click Next. On the following screen, check off the box next to I accept the license terms and click Next.
Check The Accept License terms Button and hit next
Select Custom: Install Windows only (advanced) since the virtual machine doesn't have Windows installed on it already.
On the next screen, partition the drive using the New, Delete, and Format options if you'd like to have multiple drives. For those who like to set up a single partition, click Next.
Windows will now start installing on the virtual machine. You'll go through these steps: Copying Windows files, Getting files ready for installation, Installing features, Installing updates, and Finishing up.
!!! Note : The virtual machine might restart several times during installation, so don't fret and let Windows Setup do its work.
After Windows has finished installing, you'll see the Cortana Welcome screen. Click the little microphone icon at the bottom left to turn off Cortana. Next, select your geographical location and click Yes.
Skip the Let's customize your experience screen and select Not now when it asks you to share personal information with Cortana. Following that, Windows will customize a few other things for you before booting you to the desktop.