If you are using a Linux environment but want to run a Windows 11 virtual machine, you can easily do so using LXD. Windows 11 is somewhat strict in its requirements (needs UEFI SecureBoot, having a TPM, and having a modern CPU), but LXD supports that out of the box, and there’s no need for any complex configuration in order to enable a Windows VM. In this tutorial, we will walk through the process of installing Windows in an LXD virtual machine. We will be installing Windows 11, but the same procedure also applies to Windows server machines.
- How to repackage an iso image with distrobuilder
- How to install a Windows VM
- Ubuntu Desktop 16.04 or above
- LXD snap (version 4.2 or above) installed and running
- Some basic command-line knowledge
To start, we need to download a Windows 11 Disk Image (ISO) from the official website.
To proceed with the installation, we need to prepare the downloaded image, by repackaging it with a tool called distrobuilder. Distrobuilder is an image-building tool for LXC and LXD, used to build all our official images.
First, we need to install distrobuilder
sudo snap install distrobuilder --classic
Then we need to locate our downloads directory and find our Windows 11 iso file
We can then repackage the file, and give it a new file name (let’s call it “win11.lxd.iso”)
This needs to be run as root
sudo distrobuilder repack-windows WindowsIsoImage.iso win11.lxd.iso
ⓘYou might get a message “Required tool “hivexregedit” is missing” and “Required tool “wimlib-imagex” is missing”. You can easily install the first one using the following command:
apt-get install libwin-hivex-perland the second one using
apt-get install wimtools
ⓘYou might also get a message “failed to create overlay” depending on the file system you use. This does not hinder the process, rather it will just do things the alternative way which may take a few min longer
The result is a new iso image that will work seamlessly with LXD.
We can now locate the new iso file
ls -lh win11.lxd.iso
After we create the Windows image, We can create a new empty VM that we can call ”win11”
lxc init win11 --vm --empty
The default storage/disk provided to new VMs is 10GB, which is not enough for Windows so we need to increase the size of the disk to 50GB with the following command before proceeding
lxc config device override win11 root size=50GiB
We should also increase the CPU limits for optimal performance
lxc config set win11 limits.cpu=4 limits.memory=8GiB
Next, we need to add TPM (Trusted Platform Module) as it’s one of the things Windows requires. We can call it vtpm as it is a virtual TPM after all. Adding TPM will also enable you to enable things like bitlocker inside of your VM.
lxc config device add win11 vtpm tpm path=/dev/tpm0
The last thing we need to do is add the install media Itself and make it a boot priority (so it boots automatically)
lxc config device add win11 install disk source=/home/mionaalex/Downloads/win11.lxd.iso boot.priority=10
ⓘReplace /home/mionaalex/Downloads/ with your own path to the repackaged file
Now we can start the installer.
ⓘYou will need to manually provide a VGA console access by installing either remote-viewer or spicy. If neither of these is found in the system, you will get a message instructing you to install them.
lxc start win11 --console=vga
If needed, install remote-viewer or spicy as prompted
sudo apt install virt-viewer
The rest of the installation will proceed automatically.
You should now see the Windows installer screen.
You can select “I don’t have a key” (or add a key if you have one), select Windows 11 Pro, select the option Custom: Install Windows Pro only (Custom/advanced) and click install.
The installation will take some time.
Once the first stage is done, you will need to restart. That will close the terminal for the console, so you need to open it again.
lxc console win11 --type=vga
This will now look like a regular Windows installation process. You will see a boot window with “getting ready”. If it needs to reboot again, just run the command above.
You will get another standard setup screen, choose your options (date format, keyboard layout etc.) or skip through it.
Now it will look for updates. This will take some time.
Once completed, it will restart again so attach to the console again. The installer will show up once again and complete the process.
Now you have your Windows 11 VM up and running, and you can use it in any way you’d like.
ⓘFor best results, update the virtIO drivers. It will give you a driver that is capable of doing more than 800 by 600, this allows you to increase the size of the window.
Now you’ve learned how you can set up and run a Windows 11 virtual machine using LXD.
If you’d like to watch a video walkthrough, you can find it here.
If you’d like to read more about LXD virtual machines, read this blog.
For more about LXD in general, take a look at the following resources:
If you have further questions or need help, you can get help here: