I'm working on a device running Linux system, however, the display device needs to be configured manually before Xserver starts, otherwise the framebuffer device won't work.

There are 2 methods to implement this "manual operation":

  1. Run this operation before xinit, however, after googling and reading startx script, I found that there's no script hook that runs before xinit running;

  2. Implement a systemd unit to do this "manual operation" before Xserver starts, I searched but cannot find the information that can tell me which service or which process that actually runs "startx" or brings up Xserver;

So I post this question here, hope that someone can give me a hint.

  • Do you explicitely mean that the Xserver would not be able to configure the display device according to its needs ? What would be missing ? What precisely do you need to achieve "manually" ?
    – MC68020
    Commented Oct 21, 2022 at 17:53
  • My device is a special embedded device, it has its own video output device that needs to be triggered by its own special command. After this triggering operation, the framebuffer can be open by Xserver. In this case, this special command needs to be run before Xserver starts.
    – Tomas
    Commented Oct 21, 2022 at 17:57
  • Then launch it as part of /etc/X11/xinit/xserverrc
    – MC68020
    Commented Oct 21, 2022 at 18:19

2 Answers 2


By running comman ps -A | grep Xorg | awk '{print $1}' | xargs pstree -s -p I found that Xorg is a child process of sddm.

Following is the result of this command in my fedora 36:


After reading SDDM's source code, I have finally found out how Xorg is started during systemd init.

In systemd graphical.target, display-manager.service is called.

For example, I use sddm.service as the display-manager.service, sddm itself will bing up Xorg before showing the login screen.

It depends on which display manager user uses to run scripts. sddm provides /etc/sddm/Xsetup script after Xorg is running, however, sddm doesn't provide any script hook before starting Xorg.

If you don't use any display-manager.service during systemd init process, you can use startx to bing up Xorg, and you may add your own scripts in side xserverrc file.

In this case, if you want to run a special command before Xorg really starts, the best way is to write a systemd unit which runs Before=display-manager.service, this will make sure the command runs before Xorg starts.

I'll study gdm source code to find if gdm provides any pre-start-Xorg scripts hook.


Being said that you can always (if not invited to) fiddle your own startx script in order to launch whatever command prior to calling xinit,
If your unique demand is for your command to be started before the X server, then you can notice that (via unmodified startx) the X server will be exec-ed by the /etc/X11/xinit/xserverrc script.

Therefore simply insert your command within this script prior to the exec.

Of course, if you command returns whatever value upon success or failure, it will be wise to test it prior to proceed…

  • Does systemd run startx before starting DisplayManager ? If systemd doesn't run startx, how can I hook my script ?
    – Tomas
    Commented Oct 22, 2022 at 7:32
  • @Tomas : You asked a question suggesting two methods. My answer stands for your first option. Which will indeed need something to launch startx. Does systemd / yourDM use startx ? Well… I cannot tell… I use none of them. I personally fire startx from some tty to get directly into my DE thanks to dbus. I'd be anyhow greatly surprised that whatever the way followed… the X server is not launched by the xserverrc script. It would just break many well established standards.
    – MC68020
    Commented Oct 22, 2022 at 11:10

You must log in to answer this question.

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