Ubuntu Desktop VM Failing in LXD

I have been playing with LXD on my home lab to prepare for a demo/talk for work.

We’re interested in LXD as it can run VMs along with containers, we need some of the security due to isolation that VMs provide over containers.

I’ve been able to spin up lots of test Ubuntu Server VMs but I can’t get a Ubuntu desktop to work.

The host is running Ubuntu Desktop 20.04 with LXD 4.24. Both virt-viewer and spice-client-gtk are installed.

I get a warning about “cannot open display” when I try to create a desktop VM.

$ lxc launch images:ubuntu/20.04/desktop lxd-test02 -c limits.cpu=4 -c limits.memory=4MiB -c boot.autostart=true --vm --console=vga
Creating lxd-test02
Starting lxd-test02
Unable to init server: Could not connect: Connection refused
(remote-viewer:61914): Gtk-WARNING **: 16:33:27.283: cannot open display:

If I try to start the VM subsequently I get the following error.

$ lxc start lxd-test02
Error: Failed to run: forklimits limit=memlock:unlimited:unlimited -- /snap/lxd/22667/bin/qemu-system-x86_64 -S -name lxd-test02 -uuid a37b1202-9088-46d3-9df9-32fa1b850275 -daemonize -cpu host,hv_passthrough -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny -readconfig /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.conf -spice unix=on,disable-ticketing=on,addr=/var/snap/lxd/common/lxd/logs/lxd-test02/qemu.spice -pidfile /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.pid -D /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.log -smbios type=2,manufacturer=Canonical Ltd.,product=LXD -runas lxd: char device redirected to /dev/pts/0 (label console)
: Process exited with non-zero value 1

And the logs show

$lxc info --show-log lxd-test02` for more info
Name: lxd-test02
Status: STOPPED
Type: virtual-machine
Architecture: x86_64
Created: 2022/03/17 16:33 GMT
Last Used: 2022/03/17 16:40 GMT
Log:
qemu-system-x86_64:/var/snap/lxd/common/lxd/logs/lxd-test02/qemu.conf:240: cannot initialize fsdev 'qemu_config': failed to open '/var/snap/lxd/common/lxd/devices/lxd-test02/config.mount': No such file or directory

I’ve done some searching in these errors but it is still not clear to me what the problem is here?

That’s a bit of a weird one. Can you try to delete the instance and launch it again but without passing the --console=vga?

If that starts properly and eventually get you in with lxc exec, then we can figure out why you can’t get the video output.

Thanks for the prompt reply.

If I delete and recreate the VM without the --console=vga I don’t get an error but also the VM does not start.

$lxc launch images:ubuntu/20.04/desktop lxd-test02 -c limits.cpu=4 -c limits.memory=4MiB -c boot.autostart=true --vm
Creating lxd-test02
Starting lxd-test02
$ lxc list
+------------+---------+------+------+-----------------+-----------+
|    NAME    |  STATE  | IPV4 | IPV6 |      TYPE       | SNAPSHOTS |
+------------+---------+------+------+-----------------+-----------+
| lxd-test02 | STOPPED |      |      | VIRTUAL-MACHINE | 0         |
+------------+---------+------+------+-----------------+-----------+

Starting the VM gives the same error, the VM won’t start up.

$ lxc start lxd-test02
Error: Failed to run: forklimits limit=memlock:unlimited:unlimited -- /snap/lxd/22667/bin/qemu-system-x86_64 -S -name lxd-test02 -uuid 6c71f434-bff5-4a0f-a8ea-1d7896f36e74 -daemonize -cpu host,hv_passthrough -nographic -serial chardev:console -nodefaults -no-user-config -sandbox on,obsolete=deny,elevateprivileges=allow,spawn=allow,resourcecontrol=deny -readconfig /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.conf -spice unix=on,disable-ticketing=on,addr=/var/snap/lxd/common/lxd/logs/lxd-test02/qemu.spice -pidfile /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.pid -D /var/snap/lxd/common/lxd/logs/lxd-test02/qemu.log -smbios type=2,manufacturer=Canonical Ltd.,product=LXD -runas lxd: char device redirected to /dev/pts/0 (label console)
: Process exited with non-zero value 1

Okay, can you do that while running lxc monitor --debug in another terminal?

The snap list lxd output may also be useful.

Just double checked all those parameters - -c limits.memory=4MiB - obviously wrong!
Changed this to a far more sensible GB and it looks like it’s working.
I have been looking at the for a couple of days now - hadn’t spotted it.

Thanks for your help anyway!

This is pretty cool though - being able to spin up a full desktop VM at the speed of spinning up a container. Impressive!

Ah yeah, that makes sense, 4MiB is enough for QEMU to spawn (I think it needs 512KiB or something) but definitely not enough even for the firmware to load :slight_smile: