How to install a Windows 11 VM using LXD

Overview

Duration: 1:00

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.

What you’ll learn

  • How to repackage an iso image with distrobuilder
  • How to install a Windows VM

What you’ll need

  • Ubuntu Desktop 16.04 or above
  • LXD snap (version 4.2 or above) installed and running
  • Some basic command-line knowledge

Prepare your Windows image

Duration: 5:00

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

cd Downloads/
ls WindowsIsoImage.iso

We can then repackage the file, and give it a new file name (let’s call it “win11.lxd.iso”)

:warning: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-perl and the second one using apt-get install wimtoolslx

ⓘ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

Create a new VM

Duration: 4:00

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.

Install Windows

Duration: 10:00

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.

Additional information

Duration 1:00

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.

That’s all

Duration 1:00

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:

I could not find wimtoolslx package.
Seems the package is named wimtools in focal repository.

Has the path parameter been removed when adding a tpm device?

$ sudo lxc config device add win11 tpm tpm path=/dev/tpm0
Error: Invalid devices: Device validation failed for "tpm": Failed to validate config: Invalid device option "path"
# Try with this:
sudo apt update; sudo apt install -y snapd genisoimage libwin-hivex-perl wimtools rsync; sudo snap install distrobuilder --classic

# Then build the image
sudo distrobuilder repack-windows WindowsIsoImage.iso win11.lxd.iso --windows-version w11
  1. Check if your computer has a tpm module available as follow:
    ls -la /dev/tpm*
    crw-rw---- 1 tss root 10, 224 Jul 19 00:14 /dev/tpm0
    crw-rw---- 1 tss root 253, 1 Jul 19 00:15 /dev/tpm1
    crw-rw---- 1 tss tss 253, 65536 Jul 19 00:14 /dev/tpmrm0
    crw-rw---- 1 tss tss 253, 65537 Jul 19 00:15 /dev/tpmrm1
  2. If you see /dev/tpm0, then try to add it without specifying a path (assuming that you are running the currrent latest/stable version of lxd or 5.3-91e042b)
    lxc config device add win11 vtpm tpm

For those having issues with this, the actual command is without spaces on each – or:
lxc init win11 --vm --empty

You can also specify the resources that you would like to allocate in the same command:
lxc init win11 --vm --empty -c limits.cpu=4 -c limits.memory=8GB

This worked for me, thanks