5

I have found this thread on how to switch boot default behaviour on Raspbian Jessie from boot to command-line to boot to GUI and back.

Booting to command-line:

sudo systemctl set-default multi-user.target

Booting to GUI:

sudo systemctl set-default graphical.target

However, the same thread also indicates how to disable autologin, and while I got this to work for booting to command-line (and switching it back to autologin), booting to GUI always autologins. Are these commands incorrect?

Manual login:

ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service

Autologin:

ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
7

This can easily be done with raspi-config.

  1. Run the command sudo raspi-config
  2. Select Boot Options
  3. Choose Desktop
  4. Exit the prompt and restart the RPi

Edit:

To address you wanting to do this from the command line for a bash script, I suggest we look at the actual source of raspi-config (which is written in bash).

if [ $SYSTEMD -eq 1 ]; then
  systemctl set-default multi-user.target
  ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
else
  [ -e /etc/init.d/lightdm ] && update-rc.d lightdm disable 2
  sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/d$
fi
  • This works, but how do I do it from the command-line directly? My purpose is to have a bash script doing this. – tlhIngan May 24 '16 at 3:35
  • @tlhIngan: I added an excerpt from the raspi-config script. – Jacobm001 May 24 '16 at 3:42
  • The answer was in the raspi-config source. The commands I was using from the other thread obvisouly came from here, but the GUI boot needs an additional command. – tlhIngan May 24 '16 at 3:57
  • For posterity, the additional command for enabling/disabling the GUI autologin is, after the ln -fs command, sed /etc/lightdm/lightdm.conf -i -e "s/^autologin-user=pi/#autologin-user=/" to disable autologin, and sed /etc/lightdm/lightdm.conf -i -e "s/^#autologin-user=,*/autologin-user=pi/" to re-enable it. – tlhIngan May 24 '16 at 4:16
  • @Jacobm001 the raspi-config does not work in my case. Everytime I perform the same steps on Jessie 8.0 it wont boot to CLI. It always boots to GUI. However when this sudo systemctl set-default multi-user.target only then it boots to CLI on boot – Shan-Desai Aug 5 '16 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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