TL;DR I'm looking for a way to autostart graphical applications, without first requiring the user to manually login.
I'm improving my Vdesktop script that runs multiple versions of Raspbian on one Pi simultaneously using systemd-nspawn.

I am working towards building a GUI tool that manages SD cards and image files, as well as booting them.
The only hindrance to a GUI tool able to 'boot' a Raspbian image is the bothersome manual console login.
enter image description here I'm looking for a way to autostart graphical applications, without first requiring the user to manually login.
Either getting the console to autologin (I've tried, I failed), or finding an autostart method that can run lxsession in the foreground, with no need for console login first.

I'd like to stay away from having the script automatically type in 'pi', and 'raspberry', because Vdesktop must work properly on a system whose Pi password has been changed.

  • 1
    Why is lightdm.sevice not starting? Can you edit the lightdm configuration to connect to the Xephyr server?
    – Craig
    Dec 4, 2019 at 22:23
  • I doubt there is a silver bullet here. The two solutions I'm aware of (lightdm/agetty) are already mentioned, and I would try to understand why they don't work in nspawnd container rather than hoping to find yet another one. Dec 6, 2019 at 9:29
  • 1
    I think it comes down to the container not having a /dev/tty0. Because when I run /usr/sbin/lightdm, it errors Error opening /dev/tty0: No such file or directory. Is there any way to fix this?
    – Botspot
    Dec 6, 2019 at 21:12
  • Perhaps you could try machinectl bind NAME /dev/sometty /dev/tty0, assuming you have an unused sometty device on the host system? Or symlink /dev/console to /dev/tty0 inside the container? Dec 9, 2019 at 12:45
  • @DmitryGrigoryev I tried creating a symlink /dev/vconsole to /dev/tty0, but now lightdm says Error using VT_ACTIVATE 7 on /dev/tty0: Inappropriate ioctl for device.
    – Botspot
    Dec 9, 2019 at 14:48

2 Answers 2


There are probably a few ways to do this, but what I've done in the past is to first set up an auto-login service for the user account that would run the application:

sudo nano /etc/systemd/system/[email protected]

ExecStart=-/sbin/agetty --autologin app_user %I $TERM

Then in the user .profile, start an X session:

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

Lastly, in the user X init file (.xinitrc) start the GUI application:

exec python gui_app.py

This may not be the best way, but it worked for me on an application that only had a graphic display and didn't require (or have) any user input. Note that this setup does rely on systemd.

  • Yes, this works on a Pi. For some reason not on a systemd virtual machine. Raspbian already has [email protected] by default.
    – Botspot
    Dec 3, 2019 at 15:20
  • @Botspot What is a systemd virtual machine? You do not use a Raspberry Pi that would be a systemd real machine?
    – Ingo
    Dec 3, 2019 at 20:20
  • @Ingo good question. I have developed a script that uses systemd-nspawn to 'boot' a raspbian virtual machine on a Raspberry Pi. A way to run several OS'es at once for testing, development, comparison, backups, compiling in a disposable OS, etc.
    – Botspot
    Dec 3, 2019 at 22:00
  • Vdesktop takes a Raspbian .img file, and boots it inside a VNC-style window.
    – Botspot
    Dec 3, 2019 at 22:02
  • 1
    @Botspot No problem, it was only for my understanding because you don't mention it in the question. I have only skimmed the thread you have linked, tl;dr. And sorry, I just don't have a desktop available on my RasPi. I'm one of the guys loving the command line on a black and white console ;-)
    – Ingo
    Dec 4, 2019 at 12:54

I'm convinced that your problems stem from the fact that regular autologin methods rely on a real tty being available, while your guest system will have none (it will only have /dev/console which kind of emulates a terminal using stream redirection and the like, depending on the --console parameter of nspawnd). You don't seem to be able to start an X server on that, which is not surprising since it's not a real screen, so you need the guest system to use the X server of the host system which has already started.

The command line autologin should still work though. Perhaps you need to specify /dev/console as a terminal for agetty (instead of $TERM), or perhaps provide the guest system with a pseudo terminal (check out the -S option of xterm for instance).

You likely won't be able to run startx directly from this console, but the XDMCP protocol may do the trick. It should let your guest X server use the screen of the host system. On your host, you need to enable XDMCP support. Add the following to your lightdm.conf and restart:


Make a virtual networking interface between host and guest using --network-veth parameter of nspawnd, then inside your host system start the X server with

X -query HOST_IP
  • 1
    I haven't had time to try this yet, but this answer looks helpful. Bounty granted, and I will report my progress.
    – Botspot
    Dec 11, 2019 at 15:32
  • @Botspot I wouldn't vouch it will work, but at least it's something you haven't tried yet. Dec 12, 2019 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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