Windows Host as LXD vm

From UVOO Tech Wiki
Revision as of 17:05, 11 February 2021 by Busk (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

https://discuss.linuxcontainers.org/t/running-virtual-machines-with-lxd-4-0/7519

It is possible to build Windows images for LXD, but this process is currently very very manual and involves either a bunch of custom raw.qemu flags to get a temporary graphical console to perform the install or using a separate QEMU process to prepare the image.

The basic steps are:

Grab a Windows ISO image 93 from Microsoft
Grab the latest virtio drivers 110 for Windows
Create an empty VM with beefier CPU/RAM and SecureBoot disabled:
lxc init win10 --empty --vm -c security.secureboot=false -c limits.cpu=4 -c limits.memory=4GB
Grow its root disk to a reasonable size:
lxc config device override win10 root size=20GB
Enable temporary install and drivers media:
echo -n '-drive file=/home/USER/Downloads/Win10_1909_English_x64.iso,index=0,media=cdrom,if=ide -drive file=/home/USER/Downloads/virtio-win-0.1.173.iso,index=1,media=cdrom,if=ide' | lxc config set win10 raw.qemu -
lxc config set win10 raw.apparmor "/home/** rwk,"
Start the VM: lxc start win10 --console
Repeatedly hit ESC in that console (even before any output) to enter the firmware menu.
Select Boot Manager and then the QM00001 drive. Then hit ENTER a few times to answer an invisible boot prompt.
Disconnect using ctrl+a-q
Use the VGA console with lxc console win10 --type=vga, you’ll see the installer boot
During the installation, when on the formatting screen, click Load driver, then select the vioscsi\w10\amd64 directory from the E: drive
Once installed and configured to allow RDP/SSH access, you can remove the various workarounds with:
lxc config unset win10 raw.qemu
Boot the system to confirm it all works, install all the other drivers from the virtio drive, then run the Windows sysprep tool
Finally publish your VM as an image with:
lxc publish win10 --alias win10
Caveats
Community images are only available for x86_64 and aarch64
Some distributions are not Secure Boot enabled, this will show up as a boot failure with something along the lines of Access Denied. For those, secureboot must be disabled with lxc config set NAME security.secureboot false, then the VM started again.