Start X at Boot

From ParabolaWiki
Jump to: navigation, search
Covers bash_profile and inittab methods to start an X server during the boot process.
Automatic login to virtual console
Display Manager

The majority of users use display manager to start X server. This article introduce two methods without display manager. The bash_profile method will start X once logged in from a tty. The inittab way allows automatically starting X without supplying a password.

To manually start X, startx or xinit are used. Both will execute ~/.xinitrc, which may be customized to start the window manager of choice as described in the xinitrc article.

1 bash_profile

An alternative to a login manager is to add the following to the bottom of your ~/.bash_profile (if ~/.bash_profile does not yet exist, you can copy a skeleton version from /etc/skel/.bash_profile. If you use zsh as your preferred shell, add the following lines to your ~/.zprofile instead.):

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then
  exec startx
  # Could use xinit instead of startx
  #exec xinit -- /usr/bin/X -nolisten tcp vt7

or with additional checking (if tty1 (Ctrl+Alt+F1) shows an error message):

if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  exec startx

Or with a prompt:

if [[ -z $DISPLAY ]] && ! [[ -e /tmp/.X11-unix/X0 ]] && (( EUID )); then
  while true; do
    read -p 'Do you want to start X? (y/n): '
    case $REPLY in
      [Yy]) exec xinit -- /usr/bin/X -nolisten tcp vt7 ;;
      [Nn]) break ;;
      *) printf '%s\n' 'Please answer y or n.' ;;

The user will be logged out when X is killed. In order to avoid this, remove the exec part from the script.

Note: This method can be combined with automatic login to virtual console and act similar to the inittab method, but it will properly register your session and works with ConsoleKit.
Warning: There is a significant security difference when using plain startx instead of a login manager. Thus you run startx from your shell you are always able to switch from X (usually on tt7) back to tty1 (Ctrl+Alt+F1) and gain control over the user shell even when the screen is locked (e.g., via XScreenSaver, i3lock, etc.). A solution: replace exec startx with exec nohup startx > .xlog & vlock. This will start X, redirect the print out to ~/.xlog and lock the shell. Of course you need to install vlock first.

2 inittab

Another way of circumventing display managers and booting straight into a preferred window manager or desktop environment involves editing /etc/inittab.

Note: This method will not use /bin/login or register your session, therefore no session will appear in who or w. Your session will also not be authorized as 'local' by ConsoleKit, so you will be unable to shutdown/suspend/reboot or mount drives without using sudo or su.


x:5:respawn:/usr/bin/xdm -nodaemon


x:5:once:/bin/su - -- PREFERRED_USER -l -c '/usr/bin/startx </dev/null >/dev/null 2>&1'
  • The - option invokes a "login shell" by prepending a dash (-) to its name.
  • Because a command is specified with the -c option, the shell is also run in "non-interactive mode".
  • Bash does not do the normal login process in non-interactive login mode unless it is forced with the -l option.
  • The standard input must be redirected (</dev/null) if Getty or some other program is still used on the console, otherwise there will be a conflict between multiple programs stealing console input from each other.
  • The output can also be redirected (>/dev/null 2>&1) to avoid outputting messages from X to the console.
  • The field populated with once may be changed to respawn which will restart X if it exits.
  • startx may be changed to any desired command or script. For example:
startx -- -nolisten tcp -br -deferglyphs 16

Also you can do this for multiple users using different runlevels,

x1:4:once:/bin/su - -- PREFERRED_USER1 -l -c '/usr/bin/startx </dev/null >/dev/null 2>&1'
x2:5:once:/bin/su - -- PREFERRED_USER2 -l -c '/usr/bin/startx </dev/null >/dev/null 2>&1'

and inserting a new entry in GRUB's /boot/grub/menu.lst:

# (0) Parabola GNU/Linux-Libre
title  Parabola GNU/Linux-Libre USER1
root   (hd0,0)
kernel /vmlinuz-linux-libre root=/dev/disk/by-label/Libre ro 4
initrd /initramfs-linux-libre.img

# (1) Parabola GNU/Linux-Libre
title  Parabola GNU/Linux-Libre USER2
root   (hd0,0)
kernel /vmlinuz-linux-libre root=/dev/disk/by-label/Libre ro 5
initrd /initramfs-linux-libre.img
Note: If you have problems with writing non-ASCII letters within terminals in that new X, remove the -l switch (see here).

3 Acknowledgement

This wiki article is based on ArchWiki. We may have removed non-FSDG bits from it.