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
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.
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 package. It is available as a snap package, using the
classic type of confinement. Currently, the
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
distrobuilderas 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. In addition,
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. We install that package as well.
sudo snap install distrobuilder--edge --classic sudo apt install -y libguestfs-tools
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
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 win10 --type=vga
It will take you two
lxc consoles until you get to the Windows desktop.
- 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.
- 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.
isowas 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
lxdbr0network range. I could not get to
pingthat 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.
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.