Skip to content

Instantly share code, notes, and snippets.

@imaami
Last active December 18, 2023 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaami/d8a75c0c5b2d20da7dc93a877ec15aed to your computer and use it in GitHub Desktop.
Save imaami/d8a75c0c5b2d20da7dc93a877ec15aed to your computer and use it in GitHub Desktop.
Correctly defer xdm.service until /dev/dri/card0 exists.
# /etc/udev/rules.d/99-xdm.rules
# Create a dev-dri-card0.device unit for xdm.service to wait on.
SUBSYSTEM=="drm", KERNEL=="card0", TAG+="systemd"
# /etc/systemd/system/xdm.service
[Unit]
Description=X-Window Display Manager
After=systemd-user-sessions.service
# Wait for DRM before starting. This only works if there's a udev rule for
# creating dev-dri-card0.device, otherwise "systemctl start xdm" will hang.
After=dev-dri-card0.device
BindsTo=dev-dri-card0.device
[Service]
# temporary safety check until all DMs are converted to correct
# display-manager.service symlink handling
ExecStartPre=/bin/sh -c '[ "$(cat /etc/X11/default-display-manager 2>/dev/null)" = "/usr/bin/xdm" ]'
ExecStart=/usr/bin/xdm -nodaemon
@imaami
Copy link
Author

imaami commented Dec 18, 2023

This is a fix for a problem I've recently encountered on Debian unstable. Notable symptoms are:

  • XDM will not start after a cold boot, but instead the system will appear to boot into console mode.
  • After a failed boot, when logging in as root and doing systemctl start xdm, XDM will start successfully.
  • After a failed boot, before trying to start XDM manually, /var/log/Xorg.0.log will contain a fatal error saying that /dev/dri/card0 was not found.

The above implies that the DRM stack takes longer to initialize than what it takes my system to reach xdm.service during boot. I have no idea why this has only started happening recently. The cause could be some change in upstream Debian, or my config, or amdgpu changes in the kernel, or something else entirely. Ultimately the details don't matter – this sort of thing is obviously a problem if at any time, for any reason, XDM is started before the graphics stack initializes.

The correct way to fix my problem is generic and universal. Simply put, the ordering between DRM init and X startup must be enforced in a non-stupid manner (the latter including things like e.g. a test-and-sleep script loop). This gist is, to my knowledge, not the worst possible hack out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment