Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a working automatic login to a virtual console after boot. Now I want the X server to start automatically, instead of typing startx. This worked before, but after switching to systemd, X would not start itself. According to the wiki page, I edited my ~/.bash_profile:

#
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

But X won´t start (executing startx manually works).

The wiki also notes:

X must always be run on the same tty where the login occurred, to preserve the logind session. This is handled by the default /etc/X11/xinit/xserverrc.

But I am not sure how to handle this. My /etc/X11/xinit/xserverrc:

#!/bin/sh
if [ -z "$XDG_VTNR" ]; then
  exec /usr/bin/X -nolisten tcp "$@"
else
  exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR
fi

What am I doing wrong?

UPDATE

~/.xinitrc:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)

# Keyboard layout
setxkbmap -layout de nodeadkeys
# Set the cursor
xsetroot -cursor_name left_ptr

# Autostart
tint2 & #Taskbar
/usr/lib/notification-daemon-1.0/notification-daemon & #Notifications
numlockx & #activate numlock

case "$1" in
    openbox)
        exec ck-launch-session openbox-session ;;
    xmonad)
        exec ck-launch-session xmonad ;;
    *) #default
        exec ck-launch-session xmonad ;;
esac

I don´t have a ~/.Xresources file and I didn´t need one before. Is it important?

share|improve this question
    
Remove the consolekit stuff from your .xinitrc; systemd has replaced that functionality... –  jasonwryan Jan 31 '13 at 17:16
    
Curious why you don't use one of the X display managers and set auto-login there. KDM and GDM both have auto-login (if you're already using one of those desktop environments). Not sure about XDM. Or use nodm, which does what you want and is pretty minimal. –  derobert Jan 31 '13 at 17:23
add comment

2 Answers

In .bash_profile, you can find out (after autologin with getty -a in /etc/inittab) what tty you are in with tty (if you're in fact in X, it could look like this: /dev/pts/1 - this is what the p check is about below). Then, set a variable to store this information; later, use it to launch X with xinit.

You should also setup ~/.xinitrc and ~/.Xresources; a good start of ~/.xinitrc is xrdb ~/.Xresources - check the man pages for all of this. You can find some examples here.

CURRENT_VT=`tty`
if [[ ${CURRENT_VT[6]} == "p" ]]; then
    export VT="X"
else
    export VT=${CURRENT_VT: -1:1}
fi

# ... [cut] initialize everything else ...

# OK, done; let's start applications and X depending on where we are

case $VT in
    (1) emacs ;;
    (5) wait_for_internet
        irssi --connect=open.ircnet.net ;;
    (6) xinit ;;
    (X) ... do X stuff ... ;;
esac

EDIT

By mistake, I posted the above zsh code - in bash syntax, it would look somewhat like this (with the reservation that it is much less tested than the zsh code, which runs every day on my computer). The rest is unchanged.

CURRENT_VT=`tty`
if [[ ${CURRENT_VT:5:1} = "p" ]]; then
    export VT="X";
else
    export VT=${CURRENT_VT:${#CURRENT_VT} - 1};
fi
share|improve this answer
    
@Gilles: It seems to work in .bashrc as well (when I changed the syntax; see the edit) - the reason I thought it would go there, is that I have it in .zshrc - so either those files are not 100% parallel, or you don't think the above belongs in .zshrc either - I sort of suspect the latter (as there is a .zprofile), so it would be interesting to know why? –  Emanuel Berg Jan 28 '13 at 1:20
    
If you put this code in .bashrc, it'll trigger in all kinds of undesirable circumstances, such as running screen, or SSH if it's forwarding the XDG_VTNR variable, or in an xterm if you've unset DISPLAY, etc. –  Gilles Jan 28 '13 at 1:22
    
@Gilles: Is this the case for zsh as well? (That is, you should use .zprofile?) –  Emanuel Berg Jan 28 '13 at 1:28
    
Yes, no matter what the shell is, starting X goes into the login script (.profile, .login, .bash_profile, .zprofile, …), not the interactive startup script (.bashrc, .kshrc, .cshrc, .zshrc, …). –  Gilles Jan 28 '13 at 1:35
    
@Emanuel Berg: I thought you should use startx and not xinit? Updated my question with other files. –  user905686 Jan 31 '13 at 17:04
show 1 more comment

I'm not sure what XDG_VTNR implicates, but this script works for me, put the line to ~/.bashrc

(I do auto-X on tty3)

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty3 ]]; then exec startx; fi

Also define "not working", does it work if you launch startx manually? If not, examine your ~/.xinitrc first.

share|improve this answer
    
Executing startx manually works, updated question. –  user905686 Jan 27 '13 at 10:27
    
@user905686 check this link bbs.archlinux.org/viewtopic.php?pid=1188688 –  warl0ck Jan 27 '13 at 10:55
    
this doesn´t really help... –  user905686 Jan 27 '13 at 18:22
    
Ok I tried this now and it works. Any idea why the wiki instructions do not work? Can you also explain what your command does? The second part checks whether we are on tty3 so startx will really be executed only once, right? –  user905686 Mar 11 '13 at 12:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.