You (Probably) Don't Need a Display Manager

How to log in directly with startx and .xinitrc

4 minute read

In the Linux world, a display manager is a little GUI program that presents the user with a login screen right after boot, allows her to enter her login credentials and choose the desired desktop environment or window manager. The most common ones are gdm (the default in Gnome), kdm (same for KDE), lightdm (originally written for Ubuntu’s Unity DE) and lxdm (for LXDE). There also exist a bunch of arguably simpler terminal-based display managers like ly, cdm or nodm.

But for most users a fully featured display manager may be a bit too much bloat. You can achieve the exact same functionality by simply using the default shell login and a single command. Everything in this post applies only to X11 (sorry Wayland users).

If you are the only user of your computer, you may not need a display manager at all. Not using one has the advantages of removing complexity, sparing a few MB from your drive, getting rid of an init or systemd task, and being in control of what exactly happens when X starts.

If you have no display manager configured in your init system, after boot you will be presented with the default login shell. Use it to log in normally and access a terminal tty with your default shell.

Now you need to start the X window system, and your desktop environment or window manager of choice with it. To do so, look at the ~/.xinitrc file.

The ~/.xinitrc script

There are a couple of utilities that can launch the X server for you. The first is xinit, the second is startx. In reality, startx is nothing but a wrapper script around xinit that adds a few bells and whistles, so I suggest you use only startx and leave xinit alone. You can inspect the startx script easily:

less $(where startx)

The login sequence goes like this:

  1. login using the default shell
  2. run startx

As we mentioned above, startx calls xinit, which reads the ~/.xinitrc file to know what to execute.

~/.xinitrc is a regular script that contains the commands to run when starting X. You can get the default from /etc/X11/xinit/xinitrc, and copy that one over to your home directory. The final command should run the DE or WM. An example of ~/.xinitrc that starts i3wm file follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

# This is an ~/.xinitrc example file

userresources=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
sysresources=/etc/X11/xinit/.Xresources
sysmodmap=/etc/X11/xinit/.Xmodmap

# merge in defaults and keymaps
if [ -f $sysresources ]; then
    xrdb -merge $sysresources
fi

if [ -f $sysmodmap ]; then
    xmodmap $sysmodmap
fi

if [ -f "$userresources" ]; then
    xrdb -merge "$userresources"
fi

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi

# start some nice programs
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi

# Start compositor
# picom blah blah ...

# Start applets, daemons, etc.
# diskie
# nm-applet
# ...

# Start i3wm
exec i3

In the listing above, we start i3wm with the line exec i3. The rest of the file can be as complex as you want it to be.

Set your DPI in ~/.Xresources

If you use a special display density (DPI) setting, you should make sure to include a call to xrdb with your ~/.Xresources file. In my case, I use a 4K display, so I set a DPI of 192 in my ~/.Xresources file:

!--------------------------------------------
! Custom DPI
!--------------------------------------------
Xft.dpi: 192
Xft.autohint: 0
Xft.lcdfilter: lcddefault
Xft.hintstyle: hintfull
Xft.hinting: 1
Xft.antialias: 1
Xft.rgba: rgb

You can check that this configuration file is sourced correctly by querying the dots per inch setting of your system:

$ xdpyinfo | grep dots
  resolution:    192x192 dots per inch

Conclusion

In this post we have seen how to configure our system to login without a display manager. I would argue this is a good practice, especially if you are the only user, as it removes unnecessary complexity and failure points.

      Website design by myself. See the privacy policy.
      Content licensed under CC-BY-NC-SA 4.0 .