how to configure remote desktop to LXD container using Xspice

  • install Xspice server
sudo apt install xserver-xspice xinput spice-vdagent dbus-x11

  • configure Xspice server
cp /usr/share/doc/xserver-xspice/spiceqxl.xorg.conf.example.gz  ~/gunzip spiceqxl.xorg.conf.example.gz
mv spiceqxl.xorg.conf.example spiceqxl.xorg.conf
vi spiceqxl.xorg.conf
  Option "SpiceDisableTicketing" "True"
  Option "NumHeads" "1"
  Option "SpiceVdagentEnabled" "True"
echo "SPICE_VDAGENTD_EXTRA_ARGS=-X" >> /etc/default/spice-vdagentd

  • launch Xspice-server
export DISPLAY=:10
Xspice -noreset $DISPLAY --config /root/spiceqxl.xorg.conf

other option for manual spice-vdagentd launching
sudo service spice-vdagentd stop
sudo Xspice --port 5900 --disable-ticketing --tls-port 0 -noreset $DISPLAY --config /root/spiceqxl.xorg.conf --vdagent-no-launch
sudo spice-vdagentd -X -x -f -d


  • port forwarding
cat portForwarding4lxd.sh
#!/bin/bash
#

if [ $# != 4 ]; then
    echo "Usage: $0 hostIP containerName srcPort dstPort"
    echo "Example: $0 192.168.0.107 xc 55910 22"
    echo "Example: $0 192.168.0.107 sc 55900 5900"
    exit 1
fi

hostIP=$1
cName=$2
srcPort=$3
dstPort=$4

lxdIP=$(lxc list |grep -w $cName | awk '{print $6}')
if [ -z $lxdIP ]; then
    echo "Error: no such container, named $cName"
    exit 1
fi
lxdSubnet=${lxdIP%.*}.0/24

sudo iptables -t nat -A PREROUTING -d $hostIP -p tcp --dport $srcPort -j DNAT --to-destination $lxdIP:$dstPort
sudo iptables -I FORWARD -m state -d $lxdSubnet --state NEW,RELATED,ESTABLISHED -j ACCEPT

for spice client to access lxd container desktop,
./portForwarding4lxd.sh 192.168.0.107 sc 55900 5900


  • start remote desktop session
sudo apt install lightdm
sudo su - ubuntu
DISPLAY=:10 /usr/bin/dbus-launch --exit-with-session /usr/sbin/lightdm-session

  • launch client app using spicy or remote-viewer
spicy --host 10.159.57.104 -p 5900
# or
remote-viewer

remote-viewer is in virt-viewer package
sudo apt install virt-viewer


  • how to use spice web client

https://www.spice-space.org/spice-html5.html
https://gitlab.freedesktop.org/spice/spice-html5
https://github.com/novnc/websockify
https://chrome.google.com/webstore/detail/spice-client/icklgohmolmmdagbigdkhhcgdechbeje?utm_source=chrome-app-launcher-info-dialog
https://play.google.com/store/apps/details?id=com.iiordanov.freeaSPICE

websockify [srcPort] [targetIP:dstPort]


  • how to start Xspice and window manager on boot-time
sudo vi /root/Xspice.service
sudo vi /root/start-Xspice.sh
sudo vi /root/lightdm-session.service
sudo vi /root/start-lightdm-session.sh

sudo chmod 755 /root/start-Xspice.sh
sudo ln -s /root/Xspice.service /etc/systemd/system/Xspice.service
sudo ln -s /root/lightdm-session.service /etc/systemd/system/lightdm-session.service
sudo systemctl daemon-reload
sudo systemctl enable Xspice.service
sudo systemctl enable lightdm-session.service
sudo reboot
cat /etc/systemd/system/Xspice.service
[Unit]
After=network.eth0
[Service]
ExecStart=/root/start-Xspice.sh

[Install]
WantedBy=default.target
cat /root/start-Xspice.sh
#!/bin/bash
#

export DISPLAY=:10
spice-vdagentd -X -x -f -d &
Xspice --port 5900 --disable-ticketing --tls-port 0 -noreset $DISPLAY --config /root/spiceqxl.xorg.conf --vdagent-no-launch >& /dev/null
cat /etc/systemd/system/lightdm-session.service
[Unit]
After=Xspice.service

[Service]
ExecStart=/root/start-lightdm-session.sh

[Install]
WantedBy=default.target
cat /root/start-lightdm-session.sh
#!/bin/bash
#

su ubuntu -c 'DISPLAY=:10 /usr/bin/dbus-launch --exit-with-session /usr/sbin/lightdm-session >& /dev/null'

reference
https://s3hh.wordpress.com/2014/04/18/xspice-in-containers/
http://ghanima.net/doku.php?id=wiki:ghanima:xspiceservercontainer
https://discuss.linuxcontainers.org/t/access-container-via-spice-sharing-clipboard/2544/2
https://www.spice-space.org/download.html

Leave a Reply

Your email address will not be published.