1

I made a bone-headed mistake in one of my init.d scripts which gets stuck in an infinite loop during the boot process and blocks the completion. I therefore can not get to a shell and fix it. How can I boot and not perform all the boot scripts? I have root if necessary.

dacracot
  • 469
  • 2
  • 12
  • 28
  • I think Red Hat used to have a feature where at some point in the boot it asked if you wanted to continue automatically or manually select for each service if it was to be started or not. I don't know if the feature is still available or if your error happens before that is possible. – ptman Jun 16 '11 at 04:00

2 Answers2

6

Passing 1 on the kernel line in the bootloader should start it in single user mode, which should not start the initscript unless it is severely broken. If booting into single mode does not work then you will need to get the install disc and boot into rescue mode using it.

Ignacio Vazquez-Abrams
  • 45,019
  • 5
  • 78
  • 84
  • 1
    in the grub menu press "e" to edit the menu selection, then 'e' again on the second line, which should contain kernel arguements, then "return" then 'b' on the line to boot it – bobby Jun 16 '11 at 02:00
  • you can also use "s" on the line for single user mode. easier to remember for some (like me). – Sirex Jun 16 '11 at 08:49
  • I confirm that this works. Got me out of a hole when I screwed up an init.d script. Simply logged on at run level 1, mounted the drive as RW and rm'd the offending script. Boom! –  Sep 11 '13 at 06:07
6

As Ignacio suggested, the simplest solution is to boot into single user mode. To do this press any key on the countdown splash screen before it boots into the kernel. From here highlight the proper kernel and press e. Press e again to edit the cmdline and at the end at either S, s, single, or 1. Press return and then b to boot. This won't run your init script unless you've explicitly configured it to be part of single user mode, which is unlikely.

However, if you still have problems at this point, you don't need the install disk. You can add the following to your kernel command line:

init=/bin/bash

This will cause the kernel to start /bin/bash as pid 1, rather than init. At this point none of the system initialization scripts will have run, so you should be able to take care of things. Note that you'll probably have a read-only root filesystem, which you should be able to take care of like this:

mount -o remount,rw /

...or you can remove the ro option from the kernel command line.

Wilshire
  • 538
  • 6
  • 19
larsks
  • 41,276
  • 13
  • 117
  • 170
  • I dont believe this will work, at least not as simply as wished. RHEL uses an initrd, and I believe the only shell available on the initrd is nash, which really really sucks. But I could be wrong, going off memory. – phemmer Jun 16 '11 at 02:47
  • 1
    The initrd loads and transitions to the real root as normal. You're simply loading /bin/bash instead of /sbin/init. This is a common recovery scenario; nothing special happening here. – larsks Jun 16 '11 at 03:37
  • i believe larsks is correct, this is a viable option. – Sirex Jun 16 '11 at 08:50