1

I am using systemd-nspawn to boot a linux container and load its lxsession in a VNC-style nested X server. (Xephyr) enter image description here
I have created a script to do this. One of the main problems with the script is the need to login to the container's console before the GUI is initiated via /etc/profile.

Here's my question: I'm looking for a way to autostart graphical applications, without first requiring the user to manually login. I've tried:

  • Getting the console to autologin using lightdm. This does not work since lightdm always fails to start.
    enter image description here
  • Finding an autostart method that can run lxsession in the foreground. I only know of /etc/rc.local. It kind of works, but the environmental variables are all messed up, and there's a dialog box that says "No session for PID XXX"
  • Having the script type in the username and password. Bad idea since many of the containers use a password other than the default "raspberry".
  • Why not use Docker containers to run GUI apps instead? There are already published recipes for that, and it should use less memory, since systemd doesn't need to boot inside the container. blog.jessfraz.com/post/docker-containers-on-the-desktop – Mark Stosberg Dec 5 '19 at 15:55
  • 1
    @MarkStosberg My script needs to run the entire OS of the guest, including the X session and systemd. Attempting to get it as close to a VM as possible. From what I've heard, Docker can't do that. – Botspot Dec 5 '19 at 19:57
  • does the contain need it's own X session or is it acceptable to connect to the X session of the host? Do you really need to run entire desktop environments or just GUI apps? – Mark Stosberg Dec 6 '19 at 20:22
  • @MarkStosberg yes, the container needs its own x session since I want to run the entire desktop session. – Botspot Dec 6 '19 at 20:33
0

From the Arch wiki:

To configure auto-login for a systemd-nspawn container, override console-getty.service:

# /etc/systemd/system/console-getty.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noclear --autologin username --keep-baud console 115200,38400,9600 $TERM

If machinectl login my-container method is used to access the container, also add --autologin USERNAME to container-getty@.service template that manages pts/[0-9] pseudo ttys:

# /etc/systemd/system/container-getty@.service.d/override.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --noclear --autologin username --keep-baud pts/%I 115200,38400,9600 $TERM

I've used this in practice for nsbox, and it's worked quite well with one catch: agetty will also proceed to start a shell, thus your bashrc/zshrc will be run and you may have an ugly prompt printed to the console that ran nspawn. Not a deal breaker but something worth noting...

| improve this answer | |
  • Noob question: These service overrides should be put inside the container's filesystem, right? – Botspot May 4 at 12:45
  • @Botspot Yes, they should – kirbyfan64sos May 4 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.