Start X at login

From ArchWiki
Revision as of 08:11, 29 September 2008 by Chochem (talk | contribs) (Starting X as preferred user without logging in)
Jump to navigation Jump to search

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Method 1: /etc/inittab

This is the main configuration file for the init program. Edit your /etc/inittab

The first uncommented line should be:


This indicates default runlevel 3, multi-user mode. Changing it to:


Will change default runlevel to 5; X11.

Forum Topic

You may also want to change the last line of the /etc/inittab to start kdm or gdm instead of xdm.

Method 2: /etc/rc.conf

Another way to achieve the same result is to start a display manager, (kdm, gdm, xdm, or slim) as a daemon. Edit the DAEMONS array in /etc/rc.conf e.g.:

DAEMONS=(syslog-ng network hal fam gdm)

Method 3: ~/.bash_profile

An alternative is to add something like the following to the bottom of your ~/.bash_profile (if ~/.bash_profile doesn't exist, you can create it):

if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/vc/1 ]]; then


if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/vc/1 ]]; then

Utilizing this method, X is automatically started when logging into the shell. Furthermore your user will be logged out when you kill X using ctrl+alt+backspace. next time you log in, X will start again automatically, and if you followed the mingetty instructions in Automatically_login_some_user_to_a_virtual_console_on_startup you will be able to have X automatically respawn with a fresh environment and everything ready to go.

Along the lines of the above, as described by neocephas here, you can instead add:

[ -f ~/.bash_login ] && . ~/.bash_login

to the bottom of your ~/.bash_profile. Then, in your ~/.bash_login (if ~/.bash_login doesn't exist, you can create it), add:


Of particular note, ~/.bash_login can be used to run more than just "startx" upon logging in to your boot console (for example, if using smbnetfs to mount Windows shares, you can add "smbnetfs /your/mount/location/").

Starting X as preferred user without logging in

A way of circumventing display managers and boot straight into preferred window manager or desktop environment is the following.
In /etc/inittab change:



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




x:5:once:/bin/su PREFERED_USER -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

where PREFERED_USER is the user of your choice.

Instead of startx, you can of course have any program or self-written script you wish to execute. Myself, I have startx -- -nolisten tcp -br -deferglyphs 16 instead of just startx
. Startx will run your ~/.xinitrc script, so editing this is an easy way to get it to start the window manager of your choice.