0

Long story short, an unfortunate series of development mistakes on my part has led /etc/rc.local to quickly execute reboot (on a Pi in my case). The machine is now stuck in an infinite reboot loop.

Can I stop it? It reboots before the login prompt shows and I wouldn't have time to stop it even if it didn't.

Is there perhaps some magic keyboard shortcut that prevents /etc/rc.local from running?

I found Exiting out of an infinite reboot loop in startup (rc.local) here, but that actually deals with preemptive prevention of the issue, not fixing it after the fact. Whoops.

Jason C
  • 1,383
  • 3
  • 14
  • 29

1 Answers1

1

On a PC, you'd edit the kernel command line and (e.g.,) append one of:

  • systemd.unit=emergency.target to get just a shell (requires systemd);
  • systemd.unit=rescue.target to get some more stuff started, then a shell (requires systemd);
  • single to boot to single-user mode, on SysV init systems. Not entirely sure this will avoid rc.local on Wheezy, though; or
  • init=/bin/bash, which would avoid starting init at all, instead giving you a shell (where you could then remount the root filesystem read-write, and edit the broken file). I'm not entirely sure on a Pi, though, that this will give you a working keyboard. And it requires some knowledge as you'll be running without an init setting up the system for you; you can generally use exec /sbin/init to continue booting. (Works with any init system, because you completely bypass it).

I don't think there is a way to do that on a Raspberry Pi unless you're using NOOBS. In which case holding down shift should get you a recovery interface which will let you edit cmdline.txt—and this change the kernel command line. (Or, probably, just edit the broken file—I'd suggest doing that if possible)

The other alternative is to take your SD card out of the Pi, and use an SD card reader to mount either the boot partition (which I believe is FAT32, so you should be able to do this on Windows) or the root partition (which is likely ext4, so you'd need to be running Linux). Then you can either change the kernel command line in cmdline.txt or directly fix your rc.local. If you edit cmdline.txt on Windows, make sure to use an editor that understands Unix-style line endings and won't make a mess of them.

Personally, my approach would be to mount the Pi's root filesystem on a Linux box and edit the broken rc.local.

Once you've got your Pi booted again, remember to remove the any rescue options from cmdline.txt, of course.

derobert
  • 109,670
  • Didn't even think of pulling the SD card; the Pi is mounted in another device. Easy enough to disassemble. Problem solved, thanks. – Jason C Jan 28 '17 at 18:51
  • One can start up in emergency or rescue mode with just adjusted kernel command line arguments. – JdeBP Jan 28 '17 at 23:55
  • @JdeBP on a Raspberry Pi, there isn't a bootloader that lets you edit the kernel command line – derobert Jan 28 '17 at 23:58
  • I recommend reading your own answer, which talks about editing the kernel command line. (-: As I said, it takes no more than that to invoke emergency or rescue modes which are there for exactly such situations as this. Whereas abusing a shell for a process #1 program is not a good idea. – JdeBP Jan 29 '17 at 00:15
  • @JdeBP nothing wrong with it, really. You just exec /sbin/init (to continue booting) or remount root r/o, sync, and hit reset (to reboot). But yeah, I'll edit to mention single (for Wheezy) and systemd emergency mode. – derobert Jan 29 '17 at 00:23
  • @JdeBP OK, I've listed a bunch of rescue options now, does that look better? – derobert Jan 29 '17 at 00:39