It's possible to run containerlized X11 without nesting or vnc or rdp, but I need help with input

My test laptop dead, so all I can done is using VM, but vmware only pass ps2 mouse to VM, but ps2 mouse is not hotplugable, so I have to disable hotplug in x11 config to use the mouse, but only one container succeeded to let mouse click, but it drifted, and I forgot how to reproduce it, but it’s possible. And I can’t test audio. And I can’t start wayland compositor this way.

requirement:

  • a pc with mouse and keyboard and monitor and gpu
  • no X11 or wayland installed
  • have access to switch to a tty and login
  • incus or lxd

You need another device to ssh to the pc, because after X start in tty, keyboard won’t let you use Ctrl+Alt+F* to switch tty.

Containerlized X11 has 2 part, output and input. Let’s start output part.

To display containerlized X11 in host is very easy. All we need is a gpu and a tty.
let’s say we use tty3. You switch to tty3 with Ctrl+Alt+F3, and login. Now you can use ls -alh /dev | grep tty3 to verify you own tty3, will dispaly soming like: crw------- 1 username tty 4, 1 tty3, username will be your username.
you can find your gpu with lspci | grep VGA, we only need pci address like: 00:02.0.

Create a container. Let’s call it gui, and enter it. incus exec gui bash
We need group id in container: cat /etc/group . Find tty, video and input. My is 5, 44 and 102.
Exit container, and create a profile call display.

devices:
  mygpu:
    type: gpu
    gputype: physical
    pci: '0000:00:02.0'
    mode: '0770'
    gid: '44'
    uid: '1000'
  tty3:
    path: /dev/tty3
    required: "false"
    source: /dev/tty3
    type: unix-char
    uid: "1000"
    gid: '5'

And add profile to container. incus profile add gui display
Enter container create a user with group video,input,tty: useradd -m -G video,sudo,input,tty -s /bin/bash lxc
And install xorg, I’m using debian so apt: apt install xorg --install-recommends
And and desktop environment: apt install mate-desktop-environment-core --no-install-recommends
Switch to user: su -l lxc
You can try mate-session or whatever your desktop environment start cmd is, it won’t success, you will get /usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server. Just change allowed_users=console to allowed_users=anybody in /etc/X11/Xwrapper.config in container. Then you will get Cannot open display. Xorg will succeed, but only black screen, not useful this time. Only startx will work. You can move mouse but cannot click, at least that’s what I can experience. If you can click, please let me know how.

Let’s talk about input part which I can’t solve.
I add everything in /dev/input in profile, like this:

devices:
  event0:
    gid: "102"
    path: /dev/input/event0
    source: /dev/input/event0
    type: unix-char
    uid: "1000"
  event1:
    gid: "102"
    path: /dev/input/event1
    source: /dev/input/event1
    type: unix-char
    uid: "1000"
  mice:
    gid: "102"
    path: /dev/input/mice
    source: /dev/input/mice
    type: unix-char
    uid: "1000"

Enter container and startx, still cannot click. But can use keyboard, although it will directly input in tty instead of container.
Kill X, you will see black screen, Ctrl+Alt+F2 Ctrl+Alt+F3, you will see what you keyboard input before.
To stop hotplug so X11 won’t disable ps2: X -configure, you will get xorg.conf.new. Edit it, add 2 Options in Section “ServerLayout”:

Section "ServerLayout"
    Option "AutoAddDevices" "Off" 
    Option "AutoEnableDevices" "False"

Start X: startx -- -config xorg.conf.new. I have 2 containers for test, only first one can click but drifting, but I forgot what I have done, second one cannot. I installed xserver-xorg-input-mouse in both container.

I guess by pass usb mouse to container can avoid disable hotplug.

So, 2 problems with input, how to let mouse click and how to let keyboard input in container.

Great, I figure out how to let ps2 mouse click, it’s xserver-xorg-input-mouse. I forget my second one restored snapshot, so it doesn’t have xserver-xorg-input-mouse installed. With hotplug disabled, both containers can click. Problem changes to how to stop mouse drifting.

Figure out how to deal ICEauthority. Now you can use api to start desktop environment to start in any tty you own. tty in profile is no longer needed.
Copy $XDG_RUNTIME_DIR/ICEauthority to your home dir.
Add this to .profile:

if ! [ -e "$XDG_RUNTIME_DIR/ICEauthority" ] ; then
    ln -s /home/lxc/ICEauthority $XDG_RUNTIME_DIR/ICEauthority
fi

then use this to start X if you own tty1:

incus query --request POST --wait /1.0/instances/gui/exec --data '{"command":["sh","-c", "startx -- -config /home/lxc/xorg.conf.new -auth /home/lxc/.Xauthority"],"environment":{"SHELL":"/bin/bash","CWD":"/home/lxc","HOME":"/home/lxc","LANG":"en_US.UTF-8","XDG_SESSION_CLASS":"user","TERM":"linux","USER":"lxc","SHLVL":"1","PATH":"/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"},"group": 1000,"user": 1000}' > /dev/tty1

Still no luck deal with mouse and keyboard.

Great, I figure mouse drifting problem. It’s actually not drifting, but VMware virtual mouse not ally with container mouse. Thank to my curiosity and this: input - Linux: dual mice - multiple mice with multiple mouse pointers? - Stack Overflow
Easy fix. Everything is done in container.
Install xinput. And start X. X will start at :0. So use this to find out device: DISPLAY=:0 xinput list
My output is:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Mouse0                                    id=6    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Keyboard0                                 id=7    [slave  keyboard (3)]

create a new master device: DISPLAY=:0 xinput create-master someName
List device again. My output is:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Mouse0                                    id=6    [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Keyboard0                                 id=7    [slave  keyboard (3)]
⎡ someName pointer                              id=8    [master pointer  (9)]
⎜   ↳ someName XTEST pointer                    id=10   [slave  pointer  (8)]
⎣ someName keyboard                             id=9    [master keyboard (8)]
    ↳ someName XTEST keyboard                   id=11   [slave  keyboard (9)]

Reattach Mouse0 to someName pointer: DISPLAY=:0 xinput reattach 6 8
Now, you will see where actual container mouse is. But you need to do this every time after X started.

And I found a genius who found how to pass X to tty 14 years ago in Sep 28, 2011 at 12:50:

No luck with keyboard.
So, only keyboard problem remains.

1 Like

I gave up. I can’t find a way to let keyboard input in container desktop environment. Even virtual keyboard runs into problem.
If you use onboard. In onboard preferences → keyboard → advanced → input options, change “input event source” from Xinput to GTK. It will let you type something in container by click in onboard.

If you figure out how to use keyboard in container desktop environment, reply me.

End of test.