dirthurts
Posts: 32
Joined: Fri Dec 23, 2016 4:04 am

Pulling the Power Cord

Mon Jan 09, 2017 3:37 pm

Hello fellow Pi fans.

I was wondering, has anyone actually damaged a Raspberry Pi by pulling the power? I'm putting in a unit as a video display, and it's going to be mounted without a keyboard or mouse. It's going to run 24/7, and I'm wondering, if it crashes or locks up, is pulling the power going to actually cause any damage?

I'm sure the SD card runs a risk of being corrupted, but other than that is there really anything to worry about? It doesn't seem that different from just toggling a power switch (which I considered adding to the unit).

Thanks in advance.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6074
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Pulling the Power Cord

Mon Jan 09, 2017 3:39 pm

Likelihood of SD corruption will depends on what it's doing at the time and the card itself, but other that that, it's fine.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5370
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Pulling the Power Cord

Mon Jan 09, 2017 3:44 pm

I've never heard of anything worse than sdcard corruption caused by pulling the power. I don't think you'll damage the hardware.

Whether you corrupt the sdcard seems to depend somewhat on the make/model and also on how much writing is going on.
I find you usually get away with it, but if you do it repeatedly you'll have trouble eventually.

A couple of backup sdcards in a drawer may be a good idea.

W. H. Heydt
Posts: 11070
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Pulling the Power Cord

Mon Jan 09, 2017 3:56 pm

If the Pi crashes or locks up, by the time you get to it and pull the cord, any SD card activity will be long over. The bigger (potential) risk would be a loss of power. In that case, when the power comes back on, the Pi will reboot if the SD card has survived the sudden drop.

User avatar
TimG
Posts: 294
Joined: Tue Apr 03, 2012 12:15 am
Location: Switzerland

Re: Pulling the Power Cord

Mon Jan 09, 2017 4:05 pm

I've permanently damanged two uSD cards by wiggling a power connector (two RPis on one power supply, both uSDs died simultaneously). My guess is that I induced a series of rapid power glitches and triggered an error detection system in the uSDs, causing them to become read-only to protect themselves from further data corruption.

I've never damanged anything with a "clean" power interruption (via a switch), or even by cutting the mains from the power supply, although I have caused unrecoverable filesystem corruption a few times. I'm currently testing a RPi with a read-only filesystem which has so-far withstood several hundred power cycles without any proper software-controlled shutdown.

ejolson
Posts: 3811
Joined: Tue Mar 18, 2014 11:47 am

Re: Pulling the Power Cord

Mon Jan 09, 2017 8:46 pm

dirthurts wrote:I was wondering, has anyone actually damaged a Raspberry Pi by pulling the power?
The sdcard of a standard Raspbian installation will likely become unbootable with multiple and repeated power interruptions. Each time an unscheduled interruption happens, the filesystem will need to be rebuilt by playing back log files and possibly scanning the entire sdcard. If you are particularly unlucky, the wear leveling microcontroller in the sdcard itself could enter an inconsistent state. This is the opposite of a reset to a known-good initial state that you want when the system locks up.

Using a read only root filesystem allows for a powercycle to reset the system to a known-good state.

Heater
Posts: 13879
Joined: Tue Jul 17, 2012 3:02 pm

Re: Pulling the Power Cord

Mon Jan 09, 2017 9:05 pm

If you want reliable 24/7 operation, especially if it has to survive random power outages, then you need to make the boot media immutable. That is to say read-only.
Memory in C++ is a leaky abstraction .

dirthurts
Posts: 32
Joined: Fri Dec 23, 2016 4:04 am

Re: Pulling the Power Cord

Mon Jan 09, 2017 9:14 pm

Thanks for all the replies guys.

So, if I want to make the card read-only, is there a way to reverse this later if I want to edit to it? How would one approach such a magical task as to make a card read only?

Thanks again, this has been very helpful.

jahboater
Posts: 4832
Joined: Wed Feb 04, 2015 6:38 pm

Re: Pulling the Power Cord

Mon Jan 09, 2017 9:18 pm

You can reduce the risk of SD card corruption due to dirty pages in the OS disk cache being lost, by increasing the flush rate. This can be done by adding the commit option in /etc/fstab.

Code: Select all

/dev/mmcblk0p2  /   ext4    defaults,noatime,commit=1  0  1
You can also experiment with /proc/sys/vm/dirty_writeback_centisecs
and dirty_expire_centisecs (use sysctl -w).

As heater says, a read-only SD card is the safest option.

ejolson
Posts: 3811
Joined: Tue Mar 18, 2014 11:47 am

Re: Pulling the Power Cord

Tue Jan 10, 2017 3:39 am

dirthurts wrote:So, if I want to make the card read-only, is there a way to reverse this later if I want to edit to it? How would one approach such a magical task as to make a card read only?
If you read the whole thread I linked to earlier you will see after configuring things that the read-only nature of the root filesystem can be turned on and off by changing one or two lines in some configuration files that reside in the /boot partition.

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Pulling the Power Cord

Tue Jan 10, 2017 6:44 am

FWIW, wouldn't the new "PXE" boot option (part of the new vaunted "USB booting" feature) really be the solution here?

AIUI (having not actually tried it), if you boot from the network, you don't need to have any media at all on the local machine - i.e., no SD card, no USB (flash drive or hard drive). So, nothing to corrupt...
If this post appears in the wrong forums category, my apologies.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5370
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Pulling the Power Cord

Tue Jan 10, 2017 3:16 pm

Martin Frezman wrote:AIUI (having not actually tried it), if you boot from the network, you don't need to have any media at all on the local machine - i.e., no SD card, no USB (flash drive or hard drive). So, nothing to corrupt...
I typically run from an nfs mounted root fs. True you'll never corrupt the filesystem itself, but you can still break things by powering off at an inopportune time.
Suppose you were in the middle of writing a file when the power was cut. You are likely to end up with a truncated file that is probably unusable.

I've seen this when building code. Zero length object files are created on the network drive. Next time you try to build, the makefile is happy the files exist and have a newer timestamp than the source.
But it can't link them. You won't be able to build again until you have deleted and recreated these files.

Martin Frezman
Posts: 1020
Joined: Mon Oct 31, 2016 10:05 am

Re: Pulling the Power Cord

Tue Jan 10, 2017 3:21 pm

Yeah, I get it (and thanks for the confirmation).

But you got to admit that corrupted files are basically First World Problems compared to corrupting the fs itself. I.e., you should have a pretty good idea what you were doing when the power went out - and thus have a pretty good idea of what needs fixing.
If this post appears in the wrong forums category, my apologies.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5370
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Pulling the Power Cord

Wed Jan 11, 2017 1:37 pm

Martin Frezman wrote: But you got to admit that corrupted files are basically First World Problems compared to corrupting the fs itself. I.e., you should have a pretty good idea what you were doing when the power went out - and thus have a pretty good idea of what needs fixing.
Yes, it's a much smaller issue. But make sure you don't yank the power on the nfs file server when you are writing files. It can suffer filesystem corruption just like the Pi...

alphanumeric
Posts: 2156
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Pulling the Power Cord

Wed Jan 11, 2017 2:10 pm

Not a direct answer to your question but there is an alternative to pulling the power plug when you want it to restart after a lock up. Or just start up again after doing a shutdown. I have a switch wired up to the two Reset contacts on the Pi. It's a normally open momentary contact push button. Like the power and reset buttons on a PC case. On my KODI Pi I just shut down an leave it powered up. When I want to boot it up again I just give the switch one tap. A lot easier than unplugging and plugging it back in every time you want to boot up again. I just solder in a 2 pin header like what's used for the GPIO header. Then solder two female jumper wires to the switch. Just don't press it while its running normally, it will reboot immediately without shutting down first.

Return to “General discussion”