0

I would like to know if there is a way to change the Raspberry Pi OS boot options to CLI in a headless manner before first boot; much like enabling SSH by creating a file in /boot or by setting up wifi using wpa_supplicant.conf

Currently, once booted, I have to run raspi-config which presents an ncurses type CLI interface which I then have to use manually to select CLI from boot options.

Failing that, a single command line option would be good for scripting.

4
  • 3
    Why don't you just use the "lite" version?
    – goldilocks
    Sep 12 '20 at 17:25
  • It would have taken you longer to ask this than fix it.
    – Milliways
    Sep 13 '20 at 5:07
  • @goldilocks I should have read the specs closer, I didn't realise the lite version came without the GUI..
    – myol
    Sep 13 '20 at 12:06
  • I just connected my USB-serial adapter to the Pi and booted and it worked out of the box. rapsi-config runs fine on the serial console. Sep 27 '20 at 16:34
3

Not easily as the process requires a couple of steps to set up CLI boot:

systemctl set-default multi-user.target
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service

and the removal of /etc/systemd/system/getty@tty1.service.d/autologin.conf if it exists...

If you think you need to GUI at some point, then I would install the GUI version, add the SSH enable file and then run sudo raspi-config post first boot via SSH and work through the options you need. No need even to see the GUI, connect a keyboard / mouse or screen.

Above is based on the code on GITHUB for raspi-config 3rd Sept 2020 commit 2125ae6d1876231ae94ff28547bd5aba25463de3

1
  • Pretty sure all "systemctl set-default" does is rearrange symlinks. On Raspbian, that's /lib/systemd/system/default-target -> /lib/systemd/system/multi-user.target, so you could try this without booting first. There maybe some gotchas, I'm not sure if I've ever tried it with Raspbian, but it works elsewhere and should be much the same.
    – goldilocks
    Sep 12 '20 at 19:13
1

To enable autologin, raspi-config does the following:

systemctl set-default multi-user.target
ln -fs /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
        cat > /etc/systemd/system/getty@tty1.service.d/autologin.conf << EOF
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin $USER --noclear %I \$TERM
EOF

There's no easy way to make this happen before first boot but you can unpack the distribution onto a fresh SD card, mount the root filesystem on some other computer, make the changes, then re-pack the distribution.

For example:

unzip -p ~/Downloads/2020-08-20-raspios-buster-armhf-lite.zip | sudo dd of=/dev/sdd bs=4M conv=fsync status=progress

Remove and reinsert the sd card; the two filesystems will be mounted as /media/$USER/boot and /media/$USER/rootfs (by Ubuntu on the desktop). If not automatically mounted, mount them.

Change directory to .../rootfs and execute the ln and cat commands above, after removing the leading slash from the pathnames (lest you edit your computer's files, rather than those on the sd card).

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.