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
  • 19
  • 33
  • n.b. raspi-config supports a nonint mode. If you want to configure this as part of a script, issue raspi-config nonint do_boot_behaviour Bn, where n is 1-4 depending on the boot mode you need. – Reinderien Apr 04 '20 at 19:24

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,898
  • 7
  • 46
  • 56
  • 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 03:35
  • @tlhIngan: I added an excerpt from the raspi-config script. – Jacobm001 May 24 '16 at 03: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 03: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 04: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 05 '16 at 16:40
  • It has an option login as ctrl-alt-delor but not for other users. I want it to login as one of the other users. – ctrl-alt-delor Jun 17 '18 at 15:26