Update 27th April 2021: The post has been updated and rechecked. Now, the stable version of distrobuilder
is able to repack-windows
and you do not need use the version from the edge
channel.
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
- Download a Windows 10 ISO from Microsoft.
- Prepare the ISO using
distrobuilder
(we do this once per ISO). - 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. At the time of writing, the ISO filename is Win10_20H2_v2_EnglishInternational_x64.iso
(I selected the English International 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. Currently, the In addition, repack-windows
option is available in the very latest version of distrobuilder
. Therefore, we have to add for now the --edge
parameter. This means that distrobuilder
as a snap package will be updated frequently, being the edge
channel. Once you perform the repack
, you may switch distrobuilder
to the stable
channel with sudo snap refresh distrobuilder --stable
for the typical use of the tool.distrobuilder
, although it is a snap package, it has the classic confinement, which means that it uses packages from the host. It uses libguestfs-tools
which provides the utility hivexregedit
. In addition, it uses executables from the wimtools
package, where WIM stands for Windows IMage.. We install those packages as well.
sudo snap install distrobuilder
--classic
sudo apt install -y libguestfs-tools wimtools
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_20H2_v2_EnglishInternational_x64.iso Win10_20H2_v2_EnglishInternational_x64-distrobuilder.iso
INFO Mounting Windows ISO
INFO Mounting driver ISO
INFO Modifying WIM file {"file": "boot.wim", "index": 2}
INFO Modifying WIM file {"file": "install.wim", "index": 1}
INFO Modifying WIM file {"file": "install.wim", "index": 2}
INFO Modifying WIM file {"file": "install.wim", "index": 3}
INFO Modifying WIM file {"file": "install.wim", "index": 4}
INFO Modifying WIM file {"file": "install.wim", "index": 5}
INFO Modifying WIM file {"file": "install.wim", "index": 6}
INFO Modifying WIM file {"file": "install.wim", "index": 7}
INFO Modifying WIM file {"file": "install.wim", "index": 8}
INFO Modifying WIM file {"file": "install.wim", "index": 9}
INFO Modifying WIM file {"file": "install.wim", "index": 10}
INFO Modifying WIM file {"file": "install.wim", "index": 11}
INFO Generating new ISO
$
In my case, it generated a new ISO, the one with a name Win10_20H2_v2_EnglishInternational_x64-distrobuilder.iso
. This process takes time, and it took five minutes on a Linode VPS. 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_20H2_v2_EnglishInternational_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

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 console
s until you get to the Windows desktop.

Notes
- 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.com
account 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. - 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
- 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
- This VM setup does not have sound.
It is probably easy to add that using a QEMU option. There are no virtio drivers yet for a virtualized audio card. But it is not an issue if you go for Audio Passthrough, using a tool like Remmina. For this to work, you need to enable Remote Desktop in Windows, and also should have installed Windows Professional (instead of Windows Home). - By default, the VM gets a private IP address, one from the
lxdbr0
network range. I could not get toping
that IP address from the host or from a container.It is likely a VM issue. But of couse, the VM has networking. edit It is a Windows Firewall issue. You can enable an inbound IPv4 ICMP rule, such as the following. We selected to enable some existing rule instead of composing it from scratch.

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.
Recent Comments