61

I get an I/O error at boot and then get this 'error': (I am running the latest version of Raspbian)

Entering kdb (current=0xca82ac80, pid 1) due to keyboard entry
kdb> _

And I have seen it before, and was explained that my SD card got corrupted since I did not shutdown correctly. One week later, I didn't deal with this error, until the power flickered on/off thrice and now I can't boot again. It seems like I am re-preparing my SD card ever day!!! I don't like this, not to mention I love my Pi's capabilities. But this 'breakpoint' is driving me crazy! Is there some way I can prevent this or strengthen something so it doesn't happen if the power goes out? Any suggestions? Thanks!

P.S. My zip file was not corrupted and my extraction service is Win32DiskImager

12
  • 3
    Is your card on this list
    – Butters
    Jun 15, 2013 at 2:05
  • have you ever thought about UPS ?
    – lenik
    Jun 15, 2013 at 7:29
  • @lenik Are you saying I should have something like a surge protector?
    – user151324
    Jun 15, 2013 at 13:53
  • Because you power off the thing without a proper shutdown?
    – jippie
    Jun 15, 2013 at 15:13
  • 2
    @coding_corgi more likely something with a battery inside, that provides power for 5-10 minutes after the power outage, that allows you to ignore short power flicks and gives you time to shutdown (automatically?) your computer when power goes down for a long time. It's called "Uninterruptable Power Supply" or UPS for short.
    – lenik
    Jun 15, 2013 at 23:52

11 Answers 11

55
+50

I'm not going to write about checking your HW and compatible SD card lists, because you most probably have already checked all these. What I'm about to write is the permanent solution, that allows to nip the problem in the bud, and permanently fix the issue.

If you don't want your SD card to get broken when you flip the power switch, you have to use it in a read-only mode. If there's nothing being written to your SD card, it won't get damaged no matter what you do.

Obvious (but non-working) solution would be an attempt to flip "read-only" switch on the side of the SD card, unfortunately this does not work because the schematics shows this switch is routed nowhere and its position is generally ignored.

Another, more subtle (but working) approach would be modifying your /etc/fstab to mount all your partitions read-only. The drawback of this approach is your logs have to be written somewhere else (USB stick, RAM drive?) and in case of RAM drive the logs won't persist during reboot. To do this:

  1. Copy an RPi image to your SD card using any method you like.
  2. Boot from SD and raspi-config will start automatically. Do not "Expand filesystem", just set up your time zone and international settings.
  3. Run sudo fdisk /dev/mmcblk0, press 'p' to print the current partition table. Then enter the following commands:

    n        Create a new partition
    [enter]  Make a primary partition
    [enter]  Use the default number
    [#]      1 greater than the end of mmcblk0p2
    [enter]  Expand to the end of the SD card
    w        Write the partition table and exit
    
  4. Edit /etc/fstab. It should look something like the following:

    proc            /proc     proc    defaults 0 0
    /dev/mmcblk0p1  /boot     vfat    ro       0 0
    /dev/mmcblk0p2  /         ext4    ro       0 0
    /dev/mmcblk0p3  /home     ext4    defaults,errors=remount-ro  0  1
    none            /var/run  ramfs   size=1M  0 0
    none            /var/log  ramfs   size=1M  0 0
    
  5. Run sudo partprobe to recognize the new partition.

  6. Format your new partition with sudo mkfs --type ext4 /dev/mmcblk0p3.
  7. Reboot.

If for some reason you need to make changes to your system, you can remount the read-only partitions with write access:

sudo mount -o remount,rw /dev/mmcblk0p2
33
  • Wait, I can't write to my SD card if I do this? Or only at boot?
    – user151324
    Jun 19, 2013 at 2:02
  • 1
    @coding_corgi This should stop writing to the SD card entirely.
    – apnorton
    Jun 19, 2013 at 2:04
  • 1
    why do you need to write to your SD card? writing to SD + power down = FS corruption, you may use USB stick or create a separate partition on SD card if you need to save some data. in this case at least your system will get up and running, and then you may check your data for possible corruption.
    – lenik
    Jun 19, 2013 at 2:06
  • 1
    I write to my SD card video data from raspi cam and it died so many times! Not once did I have any issues with booting up, pulled wire out or system crash. Read only is good for production when you plug and play. This problem should not happen during development any way- I suspect even read only will mess up his data because something is happening at a higher level than kernel can handle.
    – Piotr Kula
    Jun 19, 2013 at 9:26
  • 7
    Modern versions of raspi-config offer a similar read-only overlayFS functionality out of the box! sudo raspi-config, go to Advanced Options, then enable the Overlay FS: Enable/Disable read-only filesystem feature. (I'd add this as an answer, but I do not have enough reputation yet.)
    – Shane S.
    Jul 26, 2020 at 4:53
5

Edit

The IPE home page seems to be no more accessible.

It should not be used since it seems not to be maintained anymore.

For the record, here is a link to the old IPE homepage at web.archive.org

Old post

Depending of what you use your RPi for, you may be insterested in IPE, which is a "blackout-proof flavour of Raspbian".

I plan to use it to boot my RPi. If I need data to be writen, I will use an USB drive that I'll mount readonly (I prefer my SD to be safe and corrupt an USB drive than having to repair my SD)

See the IPE homepage

As indicated there, "Also, use “ipe-rw” and “ipe-ro” to switch the root file system to writeable or read-only mode."

2
  • This IPE homepage brings to an empty page. Apr 19, 2020 at 19:09
  • Thanks for the information. Unfortunately it seems to be not maintained anymore. I edited my answer accordingly
    – lauhub
    Apr 20, 2020 at 12:18
3

I have overcome this issue by using a USB flash drive for my main partitions.

  1. Restore raspbian image to a USB drive

  2. Format an SD card to fat

  3. Copy contents of fat partition from USB drive onto SD card

  4. Modify config.txt on sd card to boot from /dev/sda

Essentially the rpi will still boot from the SD card, but will use the USB drive for the os and read/writes.

3

I'm using the UPS Pico a specially designed UPS for the Raspberry Pi and never have had such problems.

3

If your Raspberry Pi is frozen then you can not shutdown correctly, then this helps. I was broke my few SD cards before knew this:

Hold down both Alt+PrintScreen, and while holding those keys, hit the following keys in sequence, one at a time, with a few seconds pause between them.

Alt + PrintScreen + R E I S U O

or

Alt + PrintScreen + R E I S U B (reboot)

A handy mnemonic to remember that is, Reboot Even If System Utterly Broken.

Substitute "O" for "B" to shut down the system instead of rebooting (O=off, B=boot).

Source: https://www.raspberrypi.org/forums/viewtopic.php?t=176612#p1126262

0
1

please ensure your RPi is running on the default speeds (i.e. CPU at 700mhz). personally, i encountered storage corruptions with various SD cards - but only when running over the clock. unfortunately, some distributions (images) come with questionable settings in config.txt.

7
  • I have not overclocked my CPU, thanks though
    – user151324
    Jun 17, 2013 at 22:00
  • try another RPi to exclude the chance that yours is somehow flawed or even broken
    – jitter
    Jun 18, 2013 at 1:13
  • I only have one
    – user151324
    Jun 18, 2013 at 1:16
  • you may run out of options and request a RMA..
    – jitter
    Jun 18, 2013 at 1:19
  • RMA? What's that?
    – user151324
    Jun 18, 2013 at 1:34
1

Just to cover all ground, also check if your power supply is good enough. try other charger or plug the RPI to a PC USB port to test it. Remember that the recommended RPI supply is about 700mA, but some weak chargers might not sustain this at stable levels.

I had a router that start to act crazy for some days, then went ok, then again went crazy and later fine again ... i found that the power supply was outputting changing voltage (3V to 5.5V) on the time the router was crazy. Replaced that supply with a new one all is fine. So try replace the power supply and measure the output voltage.

Finally, turn off the RPI by shutting down the OS and only unplug the RPI when you got only one red led. the RPI is not really shutdown if you have other than one red led. Also, try to avoid disconnect the rpi by removing the power supply from the plug, it's better to remove the power from the RPI and only after remote the power supply from the plug.

1
  • No, I have a steady 5.1V @ 2100 A, and I always properly shutdown
    – user151324
    Jun 21, 2013 at 14:13
0

As found on the elinux site. I only selected what applies to your situation but please visit them for more information...

  • If you have problems, check you have latest firmware version with rpi-update
  • Some SD cards do not work on the R-Pi, so check the list of known SD cards.
  • If you are having problems setting up your SD card you might want to start by erasing it completely - especially if it has been used elsewhere and still contains data / partitions. It is good to do a FULL (low level) format any way as it can find bad sectors sometimes and add them to an ignore list.
    • Windows and Mac users can download a formatting tool from the SD Association: https://www.sdcard.org/downloads/formatter_3/
    • Reformatting cards is also easy to do in a digital camera.
    • If you are manually preparing your SD card on Linux or Mac OS using the dd command, this operation will completely erase any existing data and partitions. Make sure you write to the whole card (e.g. /dev/sdd) and not to an existing partition (e.g. /dev/sdd1).
  • If you have an sdcard that doesn't work with latest firmware, head over here.
  • Make sure you have a good power supply. Try and unplug everything and see how long it lasts. Plug items back in one by one testing the stability.

If you have followed all those steps then the only possible thing to try is use another SD Card carefully selected from the compatible list. Also make sure to buy original card from a trusted place. Not like ebay china or something.

3
  • I used 3 sd cards in the process (all supported) a SanDisk, a Kingston and a Lexar, I am not manually setting up my SD card either, I used the Win32DiskImager after trying on Ubuntu and Mac OS X.
    – user151324
    Jun 17, 2013 at 16:05
  • Its wierd that making your fs read only fixed it. You out of a millions of people has this issue. Maybe you got some rubbish/virus messing up your filesystem. Readonly root is a pain in the ass... wait and see.
    – Piotr Kula
    Jun 24, 2013 at 7:40
  • thanks, something weird is going on, definetly not a virus though...
    – user151324
    Jun 24, 2013 at 13:26
0

I have similar problems on a pi from RS Components. This is one of the pis made on China. Another one made in UK from Element 14 never had corruption with the same sdcard and powersupply. Might be some Hardwareflaw with the ra components units. Not sure of that of course, but everything seems to point in that direction.

0

I've also experienced SD Failures with my PI, sometimes 5 days in a row, sometimes it works for a month.

The only way I could get it to run reliable for more than a year now is to Boot from a USB stick. This way you don't use your SD card (only at boot) und just need about 500mb sd card (cheap) and a USB Stick.

0

I followed a hint that you can do sync before shutdown, and so far I had some success with this command:

sync; sudo shutdown -t 9 -r now
2
  • Are you still having problem with Raspberry using above solution? Mar 22, 2015 at 12:40
  • I don't think this will fix the issue. When you run a controlled shutdown, no damage should happen to your sd card by design. Corruption seems to happen mostly in cases in which the device is simply unplugged (or power outage occurs) which is unrelated to your sync or shutdown commands unless you run sync immediately before the (unexpected!) unplugging which seems unfeasible. Oct 30, 2015 at 4:05

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