Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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

share|improve this question
2  
Is your card on this list –  Butters Jun 15 '13 at 2:05
    
@user2301728 Yes, thanks though, –  coding_corgi Jun 15 '13 at 2:28
    
have you ever thought about UPS ? –  lenik Jun 15 '13 at 7:29
    
@lenik Are you saying I should have something like a surge protector? –  coding_corgi Jun 15 '13 at 13:53
1  
@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 '13 at 23:52
show 7 more comments

8 Answers

up vote 16 down vote accepted
+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
share|improve this answer
    
Wait, I can't write to my SD card if I do this? Or only at boot? –  coding_corgi Jun 19 '13 at 2:02
1  
@coding_corgi This should stop writing to the SD card entirely. –  anorton Jun 19 '13 at 2:04
    
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 '13 at 2:06
    
@anorton this stops write access to the first two partitions on SD card, but nobody says you cannot create another partition, or use different media to save the data. for example, read-only RasPi writing data over the network -- could be a very reliable solution. –  lenik Jun 19 '13 at 2:07
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. –  ppumkin Jun 19 '13 at 9:26
show 26 more comments

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."

share|improve this answer
add comment

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.

share|improve this answer
    
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. –  coding_corgi Jun 17 '13 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. –  ppumkin Jun 24 '13 at 7:40
    
thanks, something weird is going on, definetly not a virus though... –  coding_corgi Jun 24 '13 at 13:26
add comment

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.

share|improve this answer
    
I have not overclocked my CPU, thanks though –  coding_corgi Jun 17 '13 at 22:00
    
try another RPi to exclude the chance that yours is somehow flawed or even broken –  jitter Jun 18 '13 at 1:13
    
I only have one –  coding_corgi Jun 18 '13 at 1:16
    
you may run out of options and request a RMA.. –  jitter Jun 18 '13 at 1:19
    
RMA? What's that? –  coding_corgi Jun 18 '13 at 1:34
show 2 more comments

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.

share|improve this answer
    
No, I have a steady 5.1V @ 2100 A, and I always properly shutdown –  coding_corgi Jun 21 '13 at 14:13
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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