2

I wrote a program which automatically shuts down a Raspberry Pi 3b (Ubuntu Server 16.04) as soon as a button is pressed. It's nothing than a small bash script which reads a GPIO pin of the Pi every second and shuts down the device if the button is pressed.

However, I made a mistake and the condition is always true, meaning that the program shuts down the Pi as soon as it is started. Because of incredible stupidness, I already linked this program to systemd ('After=multi-user.target'). Meaning: as soon as the Pi finished booting, it shuts itself down again. I don't see any chance to interrupt this process. Is there a way to edit the '/boot/config.txt' in a way that certain 'systemd' processes are suppressed? Any other idea how I could fix this system? On my Mac I only see the boot partition and my Linux computer has no SD Card slot.

P.S.: I flashed one of these images to the SD card in the beginning https://ubuntu-pi-flavour-maker.org/download/ using 'dd'. P.S.2: Shutdown is initialized by 'poweroff'

  • 1
    Common sense says it is time to buy an adapter. – Rui F Ribeiro Jun 23 '18 at 19:44
  • Have you tried forcing the system to boot into a different systemd target other than multi-user ? Check this answer which describes setting it up during boot. unix.stackexchange.com/a/252953/151609 – Jeff H. Jun 24 '18 at 1:36
  • The thing was that I somehow could not interrupt the boot process by key combinations. Not sure if this is a Pi specific thing. – h_uat Jun 24 '18 at 6:04
  • SD card adapter is ordered ;) – h_uat Jun 24 '18 at 6:05
3

With systemd for init, systemd's rescue target can be reached by appending systemd.unit=rescue.target (or emergency.target if that fails) to the boot command line in /boot/cmdline.txt.

If this doesn't work for some reason, or on a non-systemd system, instead add init=/bin/sh to the end of the line, which will cause the system to completely bypass anything to do with systemd.

In both cases, you will need to mount the filesystem read-write in order to make any modifications. You may do this by appending rw to the boot command line, or issue mount -o remount,rw / upon boot.

  • This is exactly what I was searching for! By adding init=/bin/sh to /boot/cmdline.txt I could edit my script after remounting the sd card by mount -o remount.rw /. Thanks a million, you saved my day / week! – h_uat Jun 24 '18 at 5:58
  • This answer is the wrong way around. Rescue and emergency modes, with -s and -b and their various synonyms, are the right first and second things to try, whereas init=/bin/sh is a poor idea for the reasons explained at unix.stackexchange.com/a/197472/5132 and unix.stackexchange.com/a/195978/5132 and should be a third choice, if used at all. The systemd doco also says this. – JdeBP Jun 24 '18 at 18:50
0

systemd scan kernel argument . to disable for example cron.service add to your boot loader:

systemd.mask=cron.service 

If you have access to config.txt , you must modify to cmdline.txt .

Source :

https://www.raspberrypi.org/documentation/configuration/config-txt/boot.md

Source : https://www.freedesktop.org/software/systemd/man/kernel-command-line.html

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.