Installing and using an X server inside of an LXD container, not on the host


(Igoryonya) #1

Hello.

I trying to figure out the way to install an X server inside of LXD container, so an X server will not mix up with the host system’s files and be isolated from it. I want to start the LXD container with the X server in it whenever I need to run a desktop or a graphical program on the same machine physically, as the host (i.e.: not from the remote workstation), while the rest of the time keep it as a plain Ubuntu Server.

I have Ubuntu 18.04 server with a deb version of LXD v3.0.0.
Please tell me, if you know of the way to accomplish it, or at least, point me to the resource, where I can find such information or tutorial. If I need to use a newer version of LXD for it, I don’t mind and I will use the snap version if needed, or maybe, you know of a way to do it with another isolation technology, such as docker, snap package or whatever else?

Thank You!

P.S.:
While trying to figure it out, I’ve stumbled upon:


What “bunch of bind-mounts to have raw access to the host tty devices, dri kernel interface and any GPU endpoint” is he talking about and how they are done?


#2

For full isolation, you would need a dedicated GPU for the container.
When you attempt to run X within the container, it will fail complaining that it does not have access to this and that. You will be using LXD commands to pass those resources from the host to the container.

In LXD there are already devices for GPU and disk (bind mount). See device types at https://lxd.readthedocs.io/en/latest/containers/


(Jon Clayton) #3

Is this what you are after? running desktops in lxd containers and using guacamole to balance your connections like a terminal server.

I tested that and it worked well!

Cheers,
Jon.


(Igoryonya) #4

Thanx for your suggestion, but I am looking for a local desktop, that starts on local hardware. Not remote.


(Igoryonya) #5

Why can’t you use the same gpu, that you booted your console to?:

You start Ubuntu server.
Then, manually start the lxd container, that has an x server in it, which just takes over your gpu and loads the desktop on it.

I did use gpu:

1st, I’ve found it:
~$ sudo lspci -nnn |egrep -i ‘vga|grap|vide|disp’
00:02.0 VGA compatible controller [0300]: Intel Corporation Atom/Celeron/Pentium Processor x5-E8000/J3xxx/N3xxx Integrated Graphics Controller [8086:22b1] (rev 21)

Then, I configured it LXD container with an installed x server in it:
~$ lxc config device add xserv gpu gpu vendorid=8086 productid=22b1
~$ lxc config device show xserv
gpu:
productid: 22b1
type: gpu
vendorid: “8086”

Then, when I launch it:
~$ lxc start xserv
~$ lxc exec xserv bash
~# xinit
,
(EE) parse_vt_settings: Cannot open /dev/tty0 (No such file or directory)

~# ls /dev/tty*
/dev/tty
~# exit
exit
~$ lxc config device add xserv tty0 unix-char path=/dev/tty0
Device tty0 added to xserv
~$ lxc exec xserv bash
~# ls /dev/tty*
/dev/tty /dev/tty0

~# xinit

(EE)
Fatal server error:
(EE) xf86OpenConsole: Cannot open virtual console 2 (No such file or directory)

~# xinit – vt0

(EE) xf86OpenConsole: Switching VT failed

I can’t get it to start.

P.S.

Then, I’ve tried the following:

~# exit
~$ lxc config device add xserv tty7 unix-char path=/dev/tty7
Device tty7 added to xserv
~$ lxc exec xserv bash
~# ls /dev/tty*
/dev/tty /dev/tty0 /dev/tty7
~# xinit – vt7

xf86EnableIOPorts: failed to set IOPL for I/O (Operation not permitted)

and, although, i’ve got the permission error above, the screen got switched to hi res with a small square of white background console on the black screen, but without anything working, i.e. without mouse and the small white console square also seems inactive, becaue the rectangular cursor is hollow and typing on the keyboard doesn’t do anything.
So, it’s a progress, I think.


(Igoryonya) #6

Can somebody explain, what this error means, because, I can’t find an info about it:

xf86EnableIOPorts: failed to set IOPL for I/O (Operation not permitted)