Skip to content

Instantly share code, notes, and snippets.

@sepastian
Last active December 19, 2022 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sepastian/484ce418c73eb0f4b4c893fa59766296 to your computer and use it in GitHub Desktop.
Save sepastian/484ce418c73eb0f4b4c893fa59766296 to your computer and use it in GitHub Desktop.
QEMU: Win10 guest on Debian host

Install Win10 as a guest in QEMU, running on a Debian host.

# Host machine used.
uname -a
Linux x220 5.10.0-2-amd64 #1 SMP Debian 5.10.9-1 (2021-01-20) x86_64 GNU/Linux

This is based on https://linuxconfig.org/how-to-create-and-manage-kvm-virtual-machines-from-cli.

Prerequisites

Download Win10 Iso

https://www.microsoft.com/de-de/software-download/windows10ISO

Install Requirements

# Install QEMU and tools required.
sudo apt install libvirt-clients qemu-kvm virtinst virt-viewer

# Install osinfo-query.
sudo apt install libosinfo-bin

# Check, if win10 is supported;
# specify --os-variant=win10 below.
osinfo-query os | grep Windows

Check for Virtualization Support on Host

# Check for virtualization support
cat /proc/cpuinfo | grep vmx   # Intel
cat /proc/cpuinfo | grep svm   # AMD

# Check for kvm modules;
# result must include kvm_intel (Intel) or kvm_amd (AMD).
lsmod | grep kvm

# Enable libvirt daemon now and on startup.
systemctl enable --now libvirtd

Install

Install Win10 guest on Debian Host.

Add current user to the kvm group to be able to install without using sudo. Requires logging out and in again.

# Add sebastian to group kvm.
sudo usermod -aG kvm sebastian
# log out, log in again.

The Win10 ISO is located at Isos/Win10_20H2_v2_English_x64.iso.

Specifying --disk size=5 creates a 11GB disk at ~/.local/share/libvirt/images; a different path may be specified with path=....

The disk must be at least 10544MB in size, or Win10 won't install on it; the installer recommends 15351MB and complains, if the partition is smaller than that.

Specifying the --os-variant=win10 is important to get optimizations for this OS; see osinfo-query above.

virt-install \
  --name=win10 \
  --vcpus=2 \
  --memory=2048 \
  --cdrom=Isos/Win10_20H2_v2_English_x64.iso \
  --disk size=16 \
  --os-variant=win10

The graphical installer opens in a new window. Select language etc., then select I don't have a product key; select an N version, e.g. Windows 10 Pro N to install Windows without media player, Skype etc.

To uninstall an installation created with virt-install:

# https://serverfault.com/q/299632
virsh destroy virt1.example.com
virsh undefine --nvram virt1.example.com
virsh undefine virt1.example.com
virsh vol-delete --pool vg0 virt1.example.com.img

Caveats

If running the virt-install command multiple times fails with Disk [...] is already in use by other guests, delete the disk image and use virsh to remove the guest before running virt-install again.

# Delete disk image.
rm -rf ~/.local/share/libvirt/images/win10.qcow2

# Start the virsh console,
# destroy win10.
virsh
virsh # list
 Id   Name    State
-----------------------
 2    win10   running

virsh # destroy win10
Domain 'win10' destroyed

virsh # list
 Id   Name   State
--------------------

virsh # undefine win10
Domain 'win10' has been undefined

virsh # 

Managing and Using VMs

Use virsh to manage domains (VMs).

# list running VMs (domains)
virsh list
 Id   Name    State
-----------------------
 7    win10   running

# Start win10.
virsh start win10
Domain win10 started

# Suspend win10.
virsh suspend win10
Domain 'win10' suspended

# Resume win10.
virsh resume win10
Domain 'win10' resumed

# Disable autostart for win10.
virsh autostart --disable win10
Domain 'win10' unmarked as autostarted

# Use virst start and virst shutdown to start/shutdown a domain.

Conect to the graphical UI of win10 running virt-viewer and selecting the VM to connect to in the box that appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment