Poor scripting stops my pi from booting


9 posts
by BPK » Fri Aug 31, 2012 11:42 pm
Hi,
Hope someone can help. I know just about enough to be dangerous now and think I have broken my pi.

I have created a bash script which runs continually (starting ffmpeg). I tried to put this to boot on startup using chkconfig at levels 3,4 and 5 but did not do it correctly and now when my pi boots up it just sticks on this script and does not complete the rest of the startup activities so I cannot get to a command line or SS in to do anything - namely stop the script running and correct my mistake.

I am using Debian Wheezy install which I don't think has a safe mode I can boot into.

Can anyone help at all as I am stuck. If not I suppose I will just have to use all the backup's I have made of all my hard work - unfortunately they are only backed up very poorly in my brain.

Thanks
Barnaby Kent
http://www.pi-cars.com
Control your radio controlled car through your Raspberry Pi
Posts: 30
Joined: Mon Jun 04, 2012 10:12 am
Location: Bristol, United Kingdom
by BPK » Fri Aug 31, 2012 11:42 pm
I meant SSH of course...
Barnaby Kent
http://www.pi-cars.com
Control your radio controlled car through your Raspberry Pi
Posts: 30
Joined: Mon Jun 04, 2012 10:12 am
Location: Bristol, United Kingdom
by dom » Fri Aug 31, 2012 11:52 pm
Safe mode will be available if you've run rpi-update in the last month or so.
You can also insert the sdcard in a windows machine and add
kernel=kernel_emergency.img
to config.txt.

Then you can boot on Pi, and mount /dev/mmcblk0p2 and remove your script.

Or you can do the same from a linux PC.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4043
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by jojopi » Sat Sep 01, 2012 12:10 am
Does debian have chkconfig?

Edit cmdline.txt on another machine and add "2" to boot in runlevel 2, or "single" for runlevel S.

(Or, if you have broken all runlevels, add "init=/bin/bash". But that will give you an empty /dev, so unless you happen to remember that mmcblk0 is block major 179, you may prefer the emergency initramfs.)
User avatar
Posts: 2122
Joined: Tue Oct 11, 2011 8:38 pm
by bredman » Sat Sep 01, 2012 6:44 am
Another option is to get another PC running Linux or OSX with an SD card reader. If you only have a Windows PC you can use a live CD (for example Ubuntu) to run Linux for just a few minutes.

On the PC, you can edit the contents of the SD card to undo the changes that caused the trouble in the first place.

This method doesn't work on a PC running Windows because Windows can't read the Linux file system.

You can use any Linux that you want. i recommend the Ubuntu live CD because
1. It automatically mounts and SD cards it finds, saving you a lot of trouble.
2. It is Debian in a fancy skin, so it works exactly like Raspbian.
Posts: 1413
Joined: Tue Jan 17, 2012 2:38 pm
by BPK » Sat Sep 01, 2012 11:31 am
Hi All,
Thanks for your help the option I went for in the end was:

- Put SD card into my windows laptop
- Browse to directory and open config.txt in Notepad++
- Add line kernel=kernel_emergency.img to the end of the config.txt file
- Put SD card back into RPi and boot
- This gave me a terminal I could do stuff on
- Made a rescue directory
Code: Select all
mkdir rescue

- Mounted the directory /dev/mmcblk0p2 to the newly created rescue directory with the following command
Code: Select all
mount /dev/mmcblk0p2 /rescue

- I could then browse into rescue directory and see my rpi filesystem
- I didn't actually want to get rid of my problematic script so went into each /etc/rcX.d directory and removed the link to my problematic script
- Unmounted my rescue directory (remember to browse to top directory - out of the rescue directory first
Code: Select all
umount rescue

- Turn off pi
- put SD card back into laptop
- comment out the kernel=kernel_emergency.img line in config.txt (let's not remove I will probably need again :)
- Save config.txt and put SD card back into pi
- rebooted pi and....
- Hooray back to life

As I said thanks for your help

@jojopi re chkconfig I had to install it, when I tried to set my script using chkconfig I did only specify levels 3,4 and 5 but I guess errors in the script or something else (maybe I did not have the levels set in my bash script) seemed to add it to all levels
Barnaby Kent
http://www.pi-cars.com
Control your radio controlled car through your Raspberry Pi
Posts: 30
Joined: Mon Jun 04, 2012 10:12 am
Location: Bristol, United Kingdom
by jwlittle » Sat Oct 27, 2012 11:43 pm
BPK
thanks for the clear instructions - saved me when a chmod went wrong and took X from /etc.
Posts: 2
Joined: Tue Oct 23, 2012 11:36 am
by avra » Tue Nov 27, 2012 11:38 am
If someone wants to access Linux partition files from Windows, that can be done with one of the utilities found here: http://www.howtoforge.com/access-linux- ... om-windows
Posts: 7
Joined: Mon Jan 09, 2012 11:48 am
by abalki » Thu Apr 04, 2013 4:03 am
BPK,
This is excellent. I wrote a script that gets triggered on boot and required user input (just says OK and user has to knock off the dialog). The keyboard and mouse are not yet activated when this script runs (init.d + update-rc). I stayed awake all night brooding a raspbian rebuild and your post helped me recover from that situation. You rock!
Thanks,
Bala
Posts: 1
Joined: Thu Apr 04, 2013 3:58 am