I was working on my Pi and accidentally disconnected it from power. I have read that disconnecting power while the SD card is being written to can cause SD card corruption. How often does that really happen?


Rarely, but still happens. Besides, there are a lot of factors to consider to guess the chance of SD card corruption including but not limited to:

  • How busy the card was when power got disconnected
    • What the operation was before power was disconnected (read or write)
  • How often a "dirty" shutdown is done
  • Electrostatic discharge (ESD)
  • Whether the SD card is mounted as read-only or writable
  • SD card quality
  • Bad luck or someone wishing bad luck upon you. Pointed out by SlySven
  • Software quality (whether what the software does causes corruption or not)
  • Power noise
  • Voltage to the SD card
  • Clock stability to the SD card
  • Processor and friends' clock speed (GPU, SDRAM, etc.)
    • Overclocks are known to cause corruption
  • Software configuration
  • File system contingency plans (how the file system handles corruption)
  • OS' contingency plans (how the OS handles data corruption)
  • Data redundancy
  • SD card temperature (you should not put a lighter or stove under an SD card)
  • How much stress the SD card is having (physical stress, bending, etc.)
  • SD card connection quality
  • SD card connector quality
  • Normal wear and tear
  • Magnetic fields
    • Most SD cards are immune to this
  • Cosmic rays
  • Environmental radioactivity
    • An SD card is more likely to get corrupted inside a nuclear reactor
  • Acts of God
  • War (regular or nuclear)
  • Apocalyptic scenario
  • Rogue computer virus destroying everything
  • Corrosion from normal wear and tear

My point is that SD card corruption is hard to guess, but using common sense will save you the hassle of recovering corrupted data.

Shut down using the command sudo shutdown -h now and wait for the green LED to blink. That's the "clean" way of shutting down.

  • 1
    "Whether the SD card is read-only or writable" - remembering of course that the read-only position detector switch on the card holder in the original A & B modules was not wired up and was therefore ineffective - the "write protect" slider does not work on the standard size SD cards in the RPi - but does of course when you plonk it back into your PC to re-flash it again! 8-O – SlySven Feb 28 '16 at 4:14
  • 2
    "War (regular or nuclear)" - the EMP from nuclear explosions being particularly nasty - and the radiation (alpha, beta, gamma, X-Ray, Neutron) all have bad effects on semiconductor structures - which is a big issue on the ISS where radiation-hardening against Cosmic Rays is a really important issue. – SlySven Feb 28 '16 at 4:31
  • 1
    @SlySven wrapping aluminium foil around both Pi and your own head will also protect against various government conspiracy spy programs. Ridicul aside, having corrupted SD cards [in most of the general consumer Pi usage base] is IMHO a matter of having bad luck rather than bad or neglected software configuration. raspberrypi.stackexchange.com/questions/42647/… – EDP Feb 28 '16 at 6:05
  • @SlySven First comment: I was referring to it being mounted as read-only or read-write. All in all, it's great info. Answer updated :) – Gene Feb 28 '16 at 7:16
  • Nice summary of causes, but you get a bit distracted near the end. – CousinCocaine Apr 26 '16 at 14:40

I think PandaLion98's answer is fairly comprehensive so this is more of an anecdotal observation based on:

  • Having owned at least one pi for more than three years.
  • Having had one pi (first a B, then a B+) on 24/7 for most of that 3 years.
  • Having a few other pi's (another B, and a 2B) that I normally use headless.

In the last category, I'm regularly doing things that may leave a pi in an unresponsive, or at least network disconnected state, and the way I have networking configured once it is down I would have to plug a screen and keyboard in to get it back up again. This is pretty easy since I have them at hand but to be honest: I don't bother unless I am curious about investigating something that happened, which usually I'm not because the information relevant to me is logged anyway.

So I just pull the plug. The number of times that happens is anywhere between several times a day and several times a month. I have no qualms or worries about this because never once in all that time, on any of the pis have I seen any sign of SD card corruption having occurred. There's also occasional power outages here, power bars get accidently turned off or unplugged, etc. There's also one I use with a camera and battery pack outside and I sometimes just let it keep going until it runs of of juice.

That said, there are a few caveats to this anecdote:

  • Generally the pis are not very busy WRT to SD card I/O. I'm not running them as Tor nodes, etc. This is significant because if the power is cut while a lot of I/O is going on, there is more likely to be corruption. However, corruption of that sort, based on my experience with other linux machines over the past decade or so, is almost always fixable by fsck at boot, which unless you've screwed with the configuration will happen in such cases. I have a couple of times seen a (spinning disk) drive left in an unusable state, and in both cases the root problem turned out to be hardware failure. Spinning disks do not last for ever (and neither do SD cards; if you want some of my thoughts on that see here).

  • I tend to use a power supply (2-2.5 amps) that is ample for what I am doing -- wifi dongle, sometimes RF keyboard/mouse combo, maybe an external HD (only works without a hub on the B+ and 2B), maybe a small servo. However, occasionally I've used them with smaller ones, down to 1 and I think even 0.75 A.

  • I don't spend a lot of money on SD cards. Not because I have anything against brand names (I have at least one Sandisk one) but because I've gotten them together in kits that included a power supply and case and those are unbranded. They do usually have class 10 stamped on them. Also there's a near-by electronics store that sometimes has unbranded micro-SDs in a jar on sale at the cash register. Finally, I don't think it matters much on the pi, the controller itself is too slow and the machine itself is just not high performance.

    Note that all this doesn't mean I have a pile of them and are switching them in and out all the time; I don't -- once I have one in the state I want it usually stays in the pi for months, I'm sure there's one that's been there for more than a year running 24/7.

There seems to be an IMO highly unusual degree of paranoia about SD cards amongst pi users. I say that because our use of them is statistically irrelevant -- I like many other people also use them in phones, tablets, and cameras, and have never had an issue there either. What's more, if there were a real problem, that statistical use is so high it would probably make TV network news. I'd think photographers are the ones with the best experience regarding how long an SD card can last and what difference the various qualities of cards really amounts to.

Anyway, I'd put that paranoia down to two causes:

  1. There's this issue that may have affected some people for some period of time, I don't know, but it is in the past now.

  2. People don't rant online about how their equipment is working just fine. An absolutely horrible form of reasoning is to claim that "there must be problem because I've seen hundreds of complaints about this issue online". First, there have been millions (as in 2-4+ by now, I think) of pis sold. Second, a lot of those complaints (which I think realistically would be better measured in the dozens) are obviously by the same irate/upset/frustrated person posting multiple places, or having someone else re-post it for whatever reason. Third, from observing things here over the past 2-3 years, a lot of problems come down to ignorance and incompetence. There is nothing shameful about incompetence, I am incompetent on a unicycle, however, I am sensible enough not to blame it when I fall down.

  • 1
    Spot on. This rant about SD cards has been going on for about 6 months. My opinion is, that the card you currently have in your Pi, will outlive the next couple of your phones, and if you're not using it related to tor or torrent, it will probably outlive your next car also. – EDP Feb 28 '16 at 10:42
  • Do you own a uni-cycle - and are there any photos of you falling down from one? P-) – SlySven Feb 28 '16 at 22:20
  • @SlySven Actually no but there is a highwire in the backyard. Unfortunately I cannot put pictures of me or anyone else falling from that on the internet because of the top secret tile mosiac work I am doing in the same yard for an unamed arm of the US DoD (hint: it involves experiments with extraterrestrial communication). – goldilocks Feb 29 '16 at 8:35
  • Well we have 2 RPi and the cards corrupt in about 6 months at top. Wel not the cards but the file-system. Once we clean the card, run checks on it everything goes well. Put it back into RPi, reinstall and after 4-6 months we have another corruption. They are stored on the shelf, no physical contact. Can't figure out what's going on there... – pagep May 16 '18 at 13:38

How likely is it? I just had one crashed today. I had an RCD failure. Turned the relay on again, failure again after a few seconds. Found disconnected the suspected Christmas light, and turned the relay on again, then it worked.

20 seconds later the power went again. This time my 10 year old son stod with a grin on his face, he had turned the RCD relay off for fun. I gave him a scold that it was not good for the computers.

Now I can also tell him that he broke a RPi installation.

And what did I find. /bin/dash had been replaced by a section of syslog. During startup, there usually is heavy writing to the SD card, and syslog is taking a lot of data.

And do we want to put syslog in ramdisk???

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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