8

I know that this is not the normal way people use X. Most setup instructions tell you to put something like startx in your shell's profile. However I want to have systemd manage things.

Ideally I would have something like systemctl --user enable x.service which is run when my user is logged in, and sources my .xinitrc thus starting my WM.

All my attempts to do this have given me the error:

/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

There must be a way to do this. Any help would be greatly appreciated.

7
  • 2
    I've no idea what setup instructions you read, but putting startx in the shell profile is utterly ridiculous (just think what happens when you log in remotely into several shells). The normal way to do this is to start a display manager (e.g. lightdm, or any you want), which in turn starts the X server. Starting the X server without a display manager will be a bit tricky; you'll have to setup all the stuff the display manager does for you (authorization cookies, etc.) yourself.
    – dirkt
    Apr 15, 2018 at 19:37
  • @dirkt while I agree (hence the question), it does seem to be a pretty common practice. See wiki.archlinux.org/index.php/Xinit#Autostart_X_at_login. May 11, 2018 at 21:22
  • People do a lot of stupid things (and like to blog about it), but that's not a reason to copy it.
    – dirkt
    May 12, 2018 at 6:03
  • @jasonwryan that link is promising, the second option seems ideal, but wrought with issues. I'll give it a shot when I have some free time and report back. P.S. I don't know how I missed that when searching this issue on my own. Jun 1, 2018 at 17:57

4 Answers 4

5

Booting direcly into X11 using startx, with a free choice of the active user, see https://vincent.bernat.ch/en/blog/2021-startx-systemd

Comparing to Archlinux guide, auto login to TTYx is not needed anymore, this is direct graphical-target startup.

For an embedded/kiosk/set-top-box system, I changed the service to restart automatically with a small delay

[Unit]
Description=X11 session for bernat
After=graphical.target systemd-user-sessions.service

[Service]
User=bernat
WorkingDirectory=~

PAMName=login
Environment=XDG_SESSION_TYPE=x11
TTYPath=/dev/tty8
StandardInput=tty
UnsetEnvironment=TERM

UtmpIdentifier=tty8
UtmpMode=user

StandardOutput=journal
ExecStartPre=/usr/bin/chvt 8
ExecStart=/usr/bin/startx -- vt8 -keeptty -verbose 3 -logfile /dev/null
#Restart=no
Restart=always
RestartSec=3

[Install]
WantedBy=graphical.target

Remember to activate the graphical-target with

sudo systemctl set-default graphical.target

I found this to be the best working solution when creating an embedded Linux, like a kiosk or set-top-box system with Debian. Fast boot, directly to graphical application.

1
  • Welcome bra'tac! This is an excellent answer (worked great for me). Would you please include the full x11 service file from that site (and not just your restart changes) along with the enable in your answer, as so there is not an external link dependency? Jan 19, 2022 at 23:45
1

This is a security restriction enforced by XOrg by default. You can diable it by editing /etc/X11/Xwrapper.config, and changing allowed_users from console to anybody.

I've tested this by executing startx from a systemd unit file, and it works fine.

Source: the same document mentioned by Lyle.

0

As a systemd user who starts X at boot (without a login manager), here's what I followed: https://wiki.archlinux.org/index.php/Systemd/User#Automatic_login_into_Xorg_without_display_manager

-5

https://wiki.archlinux.org/index.php/Xinit#Autostart_X_at_login

A little searching goes a long way.

if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then exec startx fi

Put this in your shell startup and in the console it will auto start.

I guess if there is some problem with startx you fall back to the tty, it should work.

1
  • 8
    The OP specifically wants this handled by systemd...
    – jasonwryan
    May 31, 2018 at 21:44

You must log in to answer this question.

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