How to run a Windows virtual machine on LXD on Linux

By Simos Xenitellis

LXD is a hypervisor to run both system containers (a la LXC) and virtual machines (a la QEMU) on Linux distributions. System containers are lightweight because they are based solely on the Linux kernel for their virtualization features, and support Linux guests only. However, virtual machines can run other operating systems. In this post, we see how to run Windows in a LXD virtual machine.

The benefit with running Windows through LXD is that you are using the familiar LXD workflow and takes away some of the the complexity from the other ways of running a VM (like virt-manager).

The content of this tutorial came from https://discuss.linuxcontainers.org/t/running-virtual-machines-with-lxd-4-0/7519 Look towards the end of the thread where Stéphane Graber describes how to simplify the process compared to the instructions at the top of that thread.

The prerequisite is that you have LXD configured and running.

In the following, we

  1. Download a Windows 10 ISO from Microsoft.
  2. Prepare the ISO using distrobuilder (we do this once per ISO).
  3. Start the virtual machine from that prepared ISO and go through the installation.

Download a Windows 10 ISO

You can download a Windows 10 ISO from Microsoft, through the following URL.

https://www.microsoft.com/en-us/software-download/windows10ISO

You will be given the option to select Windows 10. Then, select a language for the Windows 10 ISO, and finally to select whether to download a 32-bit or 64-bit version. Select your preferred language, and then choose the 64-bit version.

Once the ISO file has been downloaded, move to the next section.

Prepare the ISO using distrobuilder

Install the distrobuilder package. It is available as a snap package, using the classic type of confinement.

sudo snap install distrobuilder --classic

Then, run distrobuilder over the Windows 10 ISO as follows. Obviously, the filename of the ISO file might be different in your case. Adapt and overcome.

$ sudo distrobuilder repack-windows Win10_1809Oct_English_x64.iso Win10_1809Oct_English_x64-distrobuilder.iso 2021/02/13 23:15:57 Mounting Windows ISO ...
2021/02/13 23:15:57 Downloading drivers ISO ...
2021/02/13 23:24:19 Mounting driver ISO ...
2021/02/13 23:24:20 Injecting drivers into boot.wim (index 2)...
2021/02/13 23:24:24 Injecting drivers into install.wim (index 1)...
2021/02/13 23:25:01 Injecting drivers into install.wim (index 2)...
2021/02/13 23:25:09 Injecting drivers into install.wim (index 3)...
2021/02/13 23:25:17 Injecting drivers into install.wim (index 4)...
2021/02/13 23:25:25 Injecting drivers into install.wim (index 5)...
2021/02/13 23:25:33 Injecting drivers into install.wim (index 6)...
2021/02/13 23:25:41 Injecting drivers into install.wim (index 7)...
2021/02/13 23:25:49 Injecting drivers into install.wim (index 8)...
2021/02/13 23:25:57 Injecting drivers into install.wim (index 9)...
2021/02/13 23:26:05 Injecting drivers into install.wim (index 10)...
2021/02/13 23:26:13 Injecting drivers into install.wim (index 11)...
2021/02/13 23:26:21 Generating new ISO ...
$ 

In my case, it generated a new ISO, the one with a name Win10_1809Oct_English_x64-distrobuilder.iso. We have the prepared ISO, we can now start.

Start the Windows 10 installation

Run the following commands to initialize the VM, to configure (=increase) the allocated disk space and finally attach the full path of your prepared ISO file. Note that the installation of Windows 10 takes about 10GB (before updates), therefore a 30GB disk gives you about 20GB of free space.

lxc init win10 --empty --vm -c security.secureboot=false
lxc config device override win10 root size=30GiB
lxc config device add win10 iso disk source=/home/myusername/Downloads/Win10_1809Oct_English_x64-distrobuilder.iso boot.priority=10

Now, the VM win10 has been configured and it is ready to be started. The following command starts the virtual machine and opens up a VGA console so that we go through the graphical installation of Windows.

lxc start win10 --console=vga
Windows 10 is booting up in a LXD virtual machine. The LXD logo is shown above.

Note that the installation of Windows 10 does a few restarts before you end up on the desktop. Those will appear as errors in your terminal that look like the following.

(remote-viewer:13539): dbind-WARNING **: 15:51:45.744: Couldn't register with accessibility bus: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. (remote-viewer:13539): GLib-GIO-CRITICAL **: 15:51:45.765: g_dbus_proxy_new_sync: assertion 'G_IS_DBUS_CONNECTION (connection)' failed

You just need to launch again the console as follows. To start the VM we run lxc start but to re-attach to the running VM (since it was restarted by itself), we run lxc console.

lxc console win10 --type=vga

It will take you two lxc consoles until you get to the Windows desktop.

Windows 10 booted up in a LXD virtual machine.

Notes

  1. When installing Windows, you will be prompted to use your personal information. If this is an expendable virtual machine, you can get away with creating a new outlook.comaccount and adding some telephone number (it does not verify the telephone number). You will be prompted for a PIN as well, and it will be asking for that PIN when you use this installation.
  2. To shutdown the VM, click to Shutdown from the Windows desktop. To start it again at a later time, run the following (as we did before).
    lxc start win10 --console=vga
  3. When the VM is stopped, you may remove the Windows 10 ISO with the following. iso was the name of the ISO device we setup earlier.
    lxc config device remove win10 iso
  4. This VM setup does not have sound. It is probably easy to add that using a QEMU option.
  5. By default, the VM gets a private IP address, one from the lxdbr0 network range. I could not get to ping that IP address from the host or from a container. It is likely a VM issue. But of couse, the VM has networking.

Summary

We have seen how to get to run Windows 10 on a LXD virtual machine. At the moment, these are the easiest instructions. Once more features are added, I’ll update this page.