Using the container with the host screen and keyboard

Last time I connected to my LXD container from my desktop using NoMachine. Today I will try to interact with it directly using the host’s screen and mouse/keyboard.

The container contains a full system (excepting the kernel, of course) and I want the experience from sitting at the host computer to be like if the system was installed directly to the host. I have not been able to find any guide for this, the closest thing I found was this guide, which explains how to let the container create windows in your already running X session. I will use parts of that.

Ideally, I would like for X to not even be installed directly on the host, but that might be a tall order. There are issues with privilege, and there would probably be conflicts between the X servers on the different containers. I will keep the X server on the host, and let the containers be clients. I install X:

administrator@the-big-one:~$ sudo apt install xorg

I do the user ID mapping as suggested:

administrator@the-big-one:~$ echo "root:$UID:1" | sudo tee -a /etc/subuid /etc/subgid
root:1000:1

This allows the LXD service to remap user IDs, so it can share some files with administrator without permission problems. I set up the remapping:

administrator@the-big-one:~$ lxc config set test-system1 raw.idmap "both $UID 1000"
administrator@the-big-one:~$ lxc restart test-system1

I start the X server on the host:

administrator@the-big-one:~$ sudo /usr/bin/Xorg :0

Now I share some files between the container and the host:

administrator@the-big-one:~$ lxc config device add test-system1 X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0
Device X0 added to test-system1
administrator@the-big-one:~$ lxc config device add test-system1 Xauthority disk path=/home/ubuntu/.Xauthority source=/home/administrator/.Xauthority
Device Xauthority added to test-system1

Now I can start XFCE in the container and it will appear on the host’s screen:

ubuntu@test-system1:~$ DISPLAY=:0 xfce4-session

If I stop the X session and start it again, I also have to remove and re-add the X0 device from the container before it will recognize the display. And if I try to start the container without the X session I have to remove X0 before it will start at all.

I do not have hardware acceleration turned on yet, which shows when I try to play a 3D game. I enable it:

administrator@the-big-one:~$ lxc config device add gpu-acc mygpu gpu

Much better. No sound, but since I intend to use a non-standard setup anyway, I don’t really care. Getting all of this to be automatic is another thing entirely, of course. I will do that later, when the setup has stabilized a bit.

Next time I will try to get the hardware acceleration to work when connecting via NoMachine (spoilers: it’s not trivial).

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s