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.

Nathan Lilienthal
  • 181
  • 1
  • 1
  • 3
  • 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 '18 at 19:37
  • @dirkt while I agree (hence the question), it does seem to be a pretty common practice. See https://wiki.archlinux.org/index.php/Xinit#Autostart_X_at_login. – Nathan Lilienthal May 11 '18 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 '18 at 06:03
  • https://wiki.archlinux.org/index.php/Systemd/User#Xorg_and_systemd – jasonwryan May 31 '18 at 21:45
  • @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. – Nathan Lilienthal Jun 01 '18 at 17:57
  • @NathanLilienthal Any success? I'd love to know if you were able to do this – gpanders Oct 30 '18 at 18:55
  • @gpanders, I wasn't able to get it setup right in my last attempts. It's been a while now, I regret not remembering the exact issue. However, NixOS (despite being far from usable as a daily driver) has a compelling X setup. Perhaps I can just read how that was configured closely sometime. All this being said, I've been running Wayland for over a year with few issues. – Nathan Lilienthal Jul 19 '21 at 19:59

4 Answers4

4

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.

  • 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? – CenterOrbit Jan 19 '22 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.

jpaugh
  • 319
  • 2
  • 13
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

Lyle
  • 101
  • 1
-4

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.