Tuesday, April 16, 2013

How to fix Raspberry Pi boot problems

If you have any problems with your SD card messing up or your Pi not booting, this is an attempt at documenting my issues with booting or SD card corruption and how I fixed them.

This can range from problems with rpi-update to changing the /boot/config.txt file to restoring the SD card superblocks from the superblock backup to Oh No my SD card is hosed and I need to recover files. We've all been there so need to be embarrassed about messing something up. Things mess up a lot.

Boot Problems

First of all, this is a great reference that I use a lot.
Start by figuring out what changed.
  • Did you just change your /boot/config.txt?
  • Did you delete any important files?
  • Did you run rpi-update?
  • Did you add a new device?
  • Did you overclock too much?
  • Do you get a kbd prompt?
  • Did it run some weird commands on the shutdown about "device still open for writing"?
If you just changed your config.txt, you should change it back and then change line by line while rebooting until you see what option is causing the error.

If you deleted any files, restore them.

If you ran rpi-update and it won't reboot, try making your /boot/config.txt the default one. The cma_lwm and cma_hwm options sometimes cause the new firmware to break.
If that doesn't work or you have flashing light errors, restore the old boot files by copying the /boot.bak/ files into /boot/
sudo cp -ap /boot.bak/* /boot/

If you recently overclocked, try reducing it back down. I run 1100 MHz easily but 1200 MHz tends to be unstable for me.

If you get a kbd prompt or error, check your power supply to make sure its supplying enough voltage, then reduce any overclocking or overvolting in your config.txt, then (if the first two don't solve it) replace the boot files like described above.

If you have a kbd prompt that you couldn't fix, you get read/write or I/O errors on shutdown or startup, or 
it can't find the ext4 partition, then you have been a victim of SD card corruption.
Don't worry though. There are still ways to recover your files.

The first thing you should do is make a copy of your SD card image.
Plug the card into another computer with linux and use dd to copy the image. Then you can try to fix the image file without further corrupting the data.
The first thing to try to do is replace your superblock with a backup. To do that click here.
If that doesn't work and all else fails, it is possible to use scalpel and custom recovery configuration to get your files. See here for how to do that.

Consider donating to further my tinkering


Places you can find me

5 comments:

  1. I've had the problem of my SD card filesystem getting corrupted all the time. It might have been a problem of a cheap SD card or to many writes on a single location or something like that. The card I still had lying around was only 512MB so I decided to use that for booting only. I use it in read-only mode (hardware protection lever down) and boot from USB.

    I've posted a blog here: http://bneijt.nl/blog/post/boot-into-usb-disk-with-raspberry-pi/

    ReplyDelete
  2. @bmm I've been having the same problem on a project with 10 Pi's, then I noticed that the recommended power supply was not giving out enough voltage. It was from Farnell (element14), I'm now using a better one from RS which hopefully will cure the problem.

    ReplyDelete
    Replies
    1. That's actually a pretty common problem, that's why I put it on there to make sure it's getting the right voltage. I had one supply that would make the keyboard and mouse mess up because the voltage was too low.

      Delete
  3. My raspberry pi is saying segmentation core dump. I have not installed anything new, it was working last night. I don't even write code someone made it for me.

    ReplyDelete
  4. boot directory is empty. used sudo cp -ap /boot.bak/* /boot/ to fix it. Get Cannot create regular file /boot .....:read-only file system. How can I fix this

    ReplyDelete