Setting Up Spice with VMs

Is there some documentation on how I can set up Spice to work with my LXD VMs?

I tried installing the spice-vdagent on the VM but I think I’m missing something as it won’t start until it is started manually (systemctl enable doesn’t enable it, outputs errors). However, I still do not see it listening on some port that I can use to connect to from the host machine using the spice-client.

Any input here is much appreciated.

You shouldn’t need to install anything on the VM. Are you using the console command?
https://documentation.ubuntu.com/lxd/en/latest/howto/instances_console/

You could also check if it works through the UI (which would indicate there’s something wrong with your client setup).

Yeah, I’m aware of the lxc console. The reason I want to use spice is that I can access the console in the browser with spice and websockify.

Have you tried the LXD-UI? If it’s not directly useful to you, maybe you could take inspiration on how it uses the graphical console.

Yes, seen it but how do I create a spice device inside the VM so that I can access spice from the web browser?

From what I understood, spice-vdagent and a spice device must be configured in the VM and then from the host I can access spice with virt-viewer or any other spice client. Is that correct?

The LXD-UI uses the LXD API which provides the spice protocol over websocket back to LXD server, which then connects that to the raw console output of the VM, without needing to setup spice inside the VM guest.

The lxc CLI tool will setup a local spice URL that you can connect to using a local client as well.

You are of course able to setup a spice server inside the VM guest too/instead, but that isn’t anything LXD specific.

Thanks for replying, first of all.

Is it spice-vdagent that needs to be installed or some other package? I can’t get spice-vdagent to work. I do not see it listening on any port inside the guest VM. If you can go into some specifics here, that will be very helpful for me.

Edit: I tested with Ubuntu Noble VM. Please let me know if you need more information. And one more question: So adding spice config to raw.qemu is not necessary?

If you’re using LXD’s console you wont because:

the LXD API which provides the spice protocol over websocket back to LXD server, which then connects that to the raw console output of the VM, without needing to setup spice inside the VM guest.

Instead the lxc CLI tool will open a port locally on your machine and tunnel it back to the remote LXD using its HTTPS API:

The lxc CLI tool will setup a local spice URL that you can connect to using a local client as well.

So if you are wanting to go that route then you should start with making LXD’s API reachable externally:

https://documentation.ubuntu.com/lxd/en/latest/howto/server_expose/#server-expose

No. I want to install spice and see the output in a web browser (using websockify). In this case, any more config must be added with “lxc config”?

I can’t use lxd-ui as it requires a cert to be installed on every client browser and so not a way for me

This is detailed here:

https://documentation.ubuntu.com/lxd/en/latest/howto/instances_console/#access-the-graphical-console-for-virtual-machines

and

https://documentation.ubuntu.com/lxd/en/latest/howto/server_expose/#server-expose

There is no prebuilt solution for this in LXD. You can write your own that uses LXD’s API (like lxc and LXD-UI do) or you can setup spice server inside the guest.

LXD-UI also supports OIDC authentication if you don’t want to use TLS:

https://documentation.ubuntu.com/lxd/en/latest/authentication/#openid-connect-authentication

See also How to integrate the VM graphical console inside a web browser with Spice.js - #3 by edlerd for more info on how LXD-UI does it.