Access Container via Spice - Sharing Clipboard?

I’ve been experimenting with LXC(lxd actually) GUI applications via remote acces ie. VNC, X2Go and Spice
From a visual and graphics performance perspective Spice seems (subjectively) the best. Spice works nicely BUT I cannot find a way to share clipboard between client and host (it would be nice to share files and sound too, but they’re far less important than the clipboard).

It seems that -

  • “Spice” on the VM looks for some virtio devices created by Qemu
  • The spice-vdagentd (system) and spice-vdagent (user) agents need to be running for clipboard support. These fail because they look for non-existent devices and sockets

Has anyone made this work (spice shared clipboard) ?

Alternately, is there any way the key devices (eg. /dev/vport1p1) could be created by LXC during initiation, to be similar to what Qemu creates (serial port anyway, not clear to me that the PCI device is really needed) ? There are some udev rules that seem to take over once the key devices “appear” … not that I’m really clear on how all this hangs together :upside_down_face:

Looks interesting and I want to try it out (and figure out what’s wrong).

Can you provide idiot-proof instructions on what packages are needed to be installed

  1. in the unprivileged LXD container
  2. on the client

I started from these discussions

Start by installing the required packages in the VM (best in a new container for testing, I used bionic)

• apt-get install xserver-xspice spice-vdagent dbus-x11

• apt-get install  mate-desktop-environment

The first line above is the spice elements, then you need a desktop (seond line) - I prefer Mate in VMs so as to avoid compositor

Create a Spice config file

• cp /usr/share/doc/xserver-xspice/spiceqxl.xorg.conf.example.gz  ~/

• cd  ~/

• gunzip spiceqxl.xorg.conf.example.gz

• cp spiceqxl.xorg.conf.example  ~/spiceqxl.xorg.conf

Then edit the config file and disable ticketing (up to you, but I’m in a secure LAN playpen so don’t need password protection) reduce the number of “heads” to improve screen size handling and enable vdagent for clipboard sharing (if required)

        ◦ Section "Device"
        ◦     Identifier "XSPICE"
        ◦     Driver "spiceqxl"
        ◦
        ◦     # ---- Network and security options
        ◦
        ◦     # ========================================= {me} Changes ==================================== #
        ◦     # Do not require a client password.
        ◦     # default: False
        ◦     #Option "SpiceDisableTicketing" "False"
        ◦     Option "SpiceDisableTicketing" "True"
        ◦     # ========================================================================================= #


        ◦     # ========================================= {me} Changes ==================================== #
        ◦     #Option "NumHeads" "4"
        ◦     Option "NumHeads" "1"
        ◦     # ========================================================================================= #


        ◦     # ========================================= {me} Changes ==================================== #
        ◦     # Whether or not to accept Vdagent connections.
        ◦     # default: False
        ◦     #Option "SpiceVdagentEnabled" "False"
        ◦     Option "SpiceVdagentEnabled" "True"
        ◦     # ======================================================================================== #

Then create/update /etc/default/spice-vdagentd with line
SPICE_VDAGENTD_EXTRA_ARGS=-X

Then you can start the xSpice server using a command as below.
Note that I chose console number 10 (see “:10”) along with port number 5910 so as to avoid VNC and X2Go running on the same server whilst testing

  # Attemp with external start of vdagent ... because clipboard sharing wont work, no access to /dev/uinput /dev/virtio-ports/com.redhat.spice.0 /dev/vport1p2

  Xspice --config /home/redger/spiceqxl.xorg.conf --disable-ticketing --port 5910 --tls-port 0  \

                --vdagent-no-launch -logfile /var/log/Xspice/Xorg.log -noreset :10 \

                2>/home/{me}/Xspice/Xspice.err >/home/{me}/Xspice/Xspice.log &

I run the above command from /etc/rc.local (after checking Xspice isn’t already running - just in case the service has been enabled)

A similar command which will simultaneously enable vdagent is, though I dont’ recommend this for testing purposes

#  Xspice --config /home/{me}/spiceqxl.xorg.conf --disable-ticketing --port 5910 --tls-port 0 --auto \

#         --vdagent --vdagent-exec /usr/bin/spice-vdagent --vdagentd-exec /usr/sbin/spice-vdagentd -logfile ~/Xspice/Xorg.log -noreset :10 \

#         2>/home/{me}/Xspice/Xspice.err >/dev/null &

If starting vdagentd as a service, or as part of the Xspice command you’ll probably need to create file /etc/default/spice-vdagentd with line

        ◦ SPICE_VDAGENTD_EXTRA_ARGS=-X

To enable vdagent manually, you need to start both the server and the client (first check they’re not already running). On initial install the server is likely to be started automatically so you may want to stop and disable it
◦ systemctl stop spice-vdagent
◦ systemctl disable spice-vdagent

To start the vdagent server, for the 1st / system element of shared clipboard support, manually with parameters, including no daemonise so we can easily see the messages

        ◦ spice-vdagentd -X -x -f -d

Or you could use systemd, though this is less useful for testing

        ◦ systemctl start spice-vdagent

To start the vdagent client / 2nd part (for clipboard support), start the desktop first, then start the client - see below

Launch the desktop (as normal user)

  •       DISPLAY=:10 /usr/bin/dbus-launch --exit-with-session mate-session 2>/home/{me}/Xspice/dbus-launch.err >/home/{me}/Xspice/dbus-launch.log  &
    

The default parameter we set for vdagentd above addresses and issue with systemd and login but it will limit connections to just 1, so I start vdagent from my own account using the same display as the spice server

  •       DISPLAY=:10 spice-vdagent -d> /home/{me}/Xspice/vdagent.log &
    

I also have information on the elements created by Qemu in a hv guest if you’re interested. None of it led to an easy solution to the clipboard problem.

EDIT: Forgot to add instructions for the client. you’ll want to use a spice client, either

  • spicy from package spice-client-gtk. Invoke with “spicy {ip address} port 5910”
  • remote-viewer from package virt-viewer. Invoke with “remote-viewer spice://{ip address}:5910”
  • remmina (packages remmina, remmina-plugin-splice)… which includes a gui front end

R

PS this is all prepared in a hurry so please excuse any mistakes or omissions
1 Like

Thanks. I tried with the instructions and I could not get copy/paste to work either, using the default configuration of SPICE. The clipboards of the host and the guest were separate and indipendent. As if vdagent was not active.

  1. I cannot think of something in LXD that would preclude SPICE from working with vdagent. That is, I suspect it is a SPICE configuration issue rather than a LXD issue. You can see in the container in /tmp that it manages to create the following,

       prw-r--r-- 1 root   root   0 Aug 30 10:27 xspice-uinput
       srwxr-xr-x 1 root   root   0 Aug 30 10:27 xspice-virtio
    
  2. The formatting of the instructions can be made better so that it is easier to follow. See this markdown demo for help.

  3. The problem should be located around vdagent. I could not get it to report when a copy/paste operation is happening. When you run SPICE under QEMU, does it have more verbose output like informing when it is actively in use?