30

My Raspberry Pi was running fine for two months. Then some files in /usr/bin got corrupted and there were many errors on reboot.

I tried to write a fresh image but dd would block and do nothing.

sudo dd if=~/2013-02-09-wheezy-raspbian.img of=/dev/mmcblk0 bs=4M

I noticed that my SD card was not listed as compatible, so I started with a new supported SD card a week ago and now the same thing has happened.

The cards seem to be stuck in a read-only state, and dd and fdisk have no impact.

I did pull the power cord a few times to reboot after ssh stopped working - I run it without a monitor and keyboard.

Is it possible to permanently damage an SD card by pulling the power cord?

I have read about corrupted SD cards and would like to get to the bottom of that problem, but my current concern is that I need to buy a new SD card each time I try. For other people they seem to be able to start again by writing a new image.

Is there anything else I can try to get the SD cards working again?

If I try to format the card with my camera it says 'format error'.

When I insert the SD card dmesg shows

...
[52254.614980] end_request: I/O error, dev mmcblk0, sector 1696056
[52254.614983] end_request: I/O error, dev mmcblk0, sector 1696064
[52254.614987] end_request: I/O error, dev mmcblk0, sector 1696072
[52254.615058] Aborting journal on device mmcblk0p2-8.
...
[52666.031183] journal commit I/O error
[52666.031186] journal commit I/O error
....
[52666.031220] journal commit I/O error
[52666.031227] journal commit I/O error
[52666.083902] EXT4-fs error (device mmcblk0p2): ext4_put_super:819:     
Couldn't clean up the journal
[52666.083910] EXT4-fs (mmcblk0p2): Remounting filesystem read-only

Update: I have managed to write a fresh image to the second SD card, but the first card (Kingston 8 GB class 4, not on the supported list) is still broken. As it's only one card which seems broken I am not so concerned that it will keep happening. I guess this was a one-off.

My Raspberry Pi now rarely boots. I checked the voltage on the Raspberry Pi, and it is quite low, so I suspect that it is the cause of my troubles. I have ordered a new power supply. However, I don't know why the Raspberry Pi worked for so long before.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
Thomas Rynne
  • 401
  • 1
  • 4
  • 4

5 Answers5

12

Issues and Potential Damage

Yes, shutting down the Raspberry Pi by pulling out the cord can cause damage. In fact, there was an answer which detailed this issue exactly. This issue is not specific to the Raspberry Pi. Taking the power cable out without warning to the OS can cause issues - I corrupted my Windows kernel that way.

How to fix

  1. Mac

Plug the SD card into the Mac. Then, open Disk utility and delete your partitions. Then restore. Finally, re-image the card. If you need any more help, please see this tutorial.

  1. Windows

Use the Win32 Disk Imager Software. Again, delete the partitions, restore it, and then re-image the card.

  1. Linux

To reset the SD to read-write, type hdparm -r0 /dev/xxx into the terminal. You may have to delete the partitions first.

How to avoid

From now on, you should never shut down the Raspberry Pi by unplugging it. Instead, go to the console and type:

sudo shutdown -h now

Or, if you are using startx, click the log off button and select shutdown.

xxmbabanexx
  • 3,278
  • 7
  • 36
  • 56
5

The problem is that you can't go to the console as the Raspberry Pi is hung, SSH works partly but won't accept a password, and Adafruit's WebIDE is hung and will not accept input. There is no choice but to pull the plug. About 25% of the time this works but it is inevitable that the file system gets corrupted eventually. It gets worse as even though the boot loader drops you to the kernel it too is hung and you can't type anything to fsck the card. Reimaging means losing all of your work. We definitely need a better solution.

dwwaddell
  • 81
  • 1
  • 3
2

You can use 'hdparm -r0 /dev/xxx' to reset it to read-write. I personally had to delete the partitions and reinsert the sdcard to be able to use dd to copy a new image to the card.

0

There is a better solution - just put the card into a reader attached to another machine and run fsck from that machine [then hope it works!]. Of course, the real issue is having to run fsck in the first place - which can often be avoided by shutting down the machine properly as opposed to pulling power, regardless of whether or not it's headless.

syb0rg
  • 8,178
  • 4
  • 38
  • 51
JustMe
  • 1
0

After dd failed on an SD card repeatedly, I used a Windows 7 machine to delete the partitions and reformat as FAT32. Only then would dd give me a working Raspberry Pi image.

Now I often run the following before dd(or dcfldd)-ing a new image:

time dcfldd if=/dev/zero of=/dev/sdc statusinterval=1 sizeprobe=of

The source suggesting /dev/zero did note that the process may shorten the life of the card.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
rob
  • 2,813
  • 4
  • 22
  • 31