Install Windows 11 in virtual machine using virt-manager
15 Jan 2022Lets install Windows 11 in a virtual machine using an emulated TPM module. It can be useful to have a virtual Windows machine for some software.
Install SWTPM - Emulated TPM module
If your computer already have a supported TPM module and it is activated in the UEFI settings you can skip this part and choose to passthrough your TPM module.
Lets install the swtpm package to emulate a TPM module. At the moment there is no Debian package for this, so we have to build it. First we need the source code so clone the repository using git
git clone https://github.com/stefanberger/swtpm.git
First install some build dependencies
cd swtpm
mk-build-deps -i
if that fails you can run this to install dependencies
sudo apt-get -y install dpkg-dev debhelper libssl-dev libtool net-tools libfuse-dev libglib2.0-dev libgmp-dev expect libtasn1-dev socat python3-twisted gnutls-dev gnutls-bin libjson-glib-dev python3-setuptools softhsm2 libseccomp-dev gawk libtpms-dev
Now we can build the packages
dpkg-buildpackage -us -uc -j$(nproc)
Now there will be lots of packages in the parent folder of swtpm, lets install what we need
apt install libtpms0
apt install ./swtpm-libs_0.8.0~dev1_amd64.deb
apt install ./swtpm__0.8.0~dev1_amd64.deb
apt install ./swtpm-tools_0.8.0~dev1_amd64.deb
Download Windows 11 iso and Virtio drivers
Microsoft is nice to have the Windows 11 iso on their site. Just remember that you still have to own a license to use it.
The virtio driver iso can be found over at the Fedora Projects site. virtio-win-0.1.208.iso
Create virtual machine
Now lets create the virtual machine Just continue with local install media Now browse for your Windows iso Unless you have moved your Windows iso to a location where you already have a Storage pool, you need to click Browse Local Now we can finally start browsing the filesystem for our Windows 11 iso I have not moved it, so it’s in my Downloads folder. This folder location will be set as a storage pool by virt-manager. So next time you download an iso you don’t have to click Browse local, just choose the “Downloads” storage pool. No one has told my virt-manager that Windows 11 exists, so it will automatically choose Windows 10. But that is fine, just continue. I gave my virtual machine a bit more ram and 8 cores should be more than enough I have no idea how much space Windows 11 will need so I will create one 100Gb disk for it. Remember that the virtual machine will only use as much space as it needs even though I set it to 100Gb here. This size is only what Windows will think the disk is. I have already created a Network Bridge so virtual manager has chosen that one by default. For now it doesn’t really matter what network device you have it can be changed later.
But it is important that you chose to Customize configuration before install
Change BIOS to UEFI
Change the firmware to UEFI Click Add Hardware and choose TPM. If you have a real TPM module you can choose Passthrough in the Backend dropdown. I’m going to use the emulated one. Virt-manager defaults to 8 sockets, I like to change this to 8 cores. I have no idea if this have any impact on the virtual machine.
Replace SATA disk with Virtio disk
Now I want to replace the emulated SATA disk with the better virtio disk controller.
Click Add hardware again and choose Storage, click Manage… to browse for our harddrive image select the harddrive image for this machine Make sure you have changed the Bus type to VirtIO before you click Finish We have not yet removed the default SATA disk so virt-manager will complain that we are already using the disk image. But click Yes to continue Now you can right-click the SATA Disk 1 and choose to remove the device. Don’t click the Delete associated storage files, because that will remove the hard disk image we are now using for the VirtIO disk.
Add a second CD-Rom device for virtio drivers iso
Because Windows install iso will be placed in the default CD rom device we have to add a second CD Rom device for the virtio device drivers.
Click Add Hardware again and choose Storage, this time we change the Device type to CDROM device. Then click Manage… to browse for the virtio drivers iso Now this time the Download storage pool exists. Select that one and browse for the virtio-win drivers iso
Ready to install
Almost ready to install, click Boot Options and make sure the boot order is correct with SATA CDROM 1 first. Now click the small Begin Installation button in the top left corner. I wish it was in the bottom right corner like all the other “continue” buttons has been
Windows Install, virtio drivers
Remember to press a button to boot the installer, then just install almost as on bare hardware. When you are going to choose where to install you need to install the Virtio drivers. Click Load driver button Browse the second CD drive with the virtio drivers and choose the folder for Windows 10 (w10) they will work When the drivers are installed the installer can find your VirtIO drive. Just continue the install process. And finally we have Windows 11 installed in a virtual machine on Linux