2

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".
4
  • 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 Commented Dec 5, 2019 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
    Commented Dec 5, 2019 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? Commented Dec 6, 2019 at 20:22
  • @MarkStosberg yes, the container needs its own x session since I want to run the entire desktop session.
    – Botspot
    Commented Dec 6, 2019 at 20:33

1 Answer 1

1

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 [email protected] template that manages pts/[0-9] pseudo ttys:

# /etc/systemd/system/[email protected]/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...

3
  • Noob question: These service overrides should be put inside the container's filesystem, right?
    – Botspot
    Commented May 4, 2020 at 12:45
  • @Botspot Yes, they should Commented May 4, 2020 at 15:58
  • I wonder if this isn't better done with pam then getty. Commented Nov 19, 2020 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .