11

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
tlhIngan
  • 3,372
  • 5
  • 21
  • 33

1 Answers1

14

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
Jacobm001
  • 11,904
  • 7
  • 47
  • 58