11

So I have a bug in a script in my init.d directory and bottom line...I can't completely boot the pi.

How can I boot into runlevel 1 (single user mode) so I can fix the bug?

3
  • 1
    Check this link for several options raspberrypi.org/phpBB3/viewtopic.php?f=28&t=16185 Commented Nov 27, 2012 at 4:42
  • If you want to access and change SD card Linux partition files from Windows you can do it with one of these utilities.
    – avra
    Commented Nov 27, 2012 at 11:34
  • I couldn't find a way to force the pi to boot into runlevel 1 so I fired up a fedora live disk I had laying around and used the terminal to remove the script in question from the /etc/init.d directory
    – Deac Karns
    Commented Nov 28, 2012 at 1:58

4 Answers 4

17

That's not exactly a way to enter runlevel 1, but there is "safe mode" boot option in raspberry Pi firmware. To enable it, you have to insert a jumper between pins 5 and 6 on P1 (GPIO) header when booting.

Safemode pins

If you do this, bootloader will ignore the config.txt file (except from avoid_safe_mode option which can be used to disable this feature) and will try to boot kernel_emergency.img (if available) instead of kernel.img.

Default kernel_emergency.img has special emergency initramfs build in and it will boot to this busybox based OS so that you can fix the problems in your OS manually (or change kernel boot parameters to run runlevel 1 at next boot). Remember to run sync before powering down since reboot or shutdown commands may not work.

1
  • That's exactly what I was looking for.
    – Deac Karns
    Commented Dec 2, 2012 at 2:32
6
  • Hit shift when starting up.
  • Hit "e" to edit config
  • tab over to cmdline.txt
  • add to the end of the line

    init=/bin/sh

  • hit ok, then Esc to boot...... it will boot you in to a command line

    # /etc/init.d/mountall.sh (this will do something)

    # mount -n -o remount,rw / (this will remount / so you can make changes)

  • now you should be able to edit the init.d config......

  • when you reboot again.... hold shift and remove the init=/bin/sh
1
  • Excellent! I'd found instructions to init sh but was missing the remount stuff I needed. Thanks! Commented May 13, 2016 at 7:18
3

Several of the other answers here are now incorrect:

  • The GPIO jumper pin method was removed from the upstream OS, so it only works now if you're using a NOOBS image

  • Raspbian Jessie's move to systemd breaks the init=/bin/sh hack. When you do this, it complains, can't access tty: job control turned off

Fortunately, there is a solution that works, which actually gives real single-user access: add a space and a 1 at the end of cmdline.txt, right after the rootwait parameter.

The hold-Shift boot menu doesn't exist with the stock Raspbian Jessie OS image, so you'll have to do this by editing /boot/cmdline.txt from another computer if you aren't using the NOOBS image.

1
  • Hmmm, for what it's worth, this only half-way worked on the image I have. It gave a thing for a "rescue mode", but that gave an error message saying it Cannot open access to console, the root account is locked. -- did I miss a step? Or did they just increase security at some point? Or... ?
    – lindes
    Commented Mar 19, 2021 at 2:10
1
  1. Boot into runlevel 1

    $ sudo init 1
    
  2. After booting into runlevel 1

    $ passwd
    

NOTE: to runlevel 1, change the file /etc/inittab from id:2:initdefault: to something similar like: id:1:initdefault:

2
  • 2
    Is that really booting into runlevel 1, though? I mean, it can hardly be done if the machine isn't booted in the first place, can it?
    – Bex
    Commented Sep 10, 2014 at 17:34
  • No, it certainly is not. What it is, is changing run level on a running system. Commented May 1, 2020 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.