Page 1 of 1

Pulling the Power Cord

Posted: Mon Jan 09, 2017 3:37 pm
by dirthurts
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 3:39 pm
by ShiftPlusOne
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 3:44 pm
by dom
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 3:56 pm
by W. H. Heydt
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 4:05 pm
by TimG
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 8:46 pm
by ejolson
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 9:05 pm
by Heater
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 9:14 pm
by dirthurts
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.

Re: Pulling the Power Cord

Posted: Mon Jan 09, 2017 9:18 pm
by jahboater
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.

Re: Pulling the Power Cord

Posted: Tue Jan 10, 2017 3:39 am
by ejolson
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.

Re: Pulling the Power Cord

Posted: Tue Jan 10, 2017 6:44 am
by Martin Frezman
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...

Re: Pulling the Power Cord

Posted: Tue Jan 10, 2017 3:16 pm
by dom
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.

Re: Pulling the Power Cord

Posted: Tue Jan 10, 2017 3:21 pm
by Martin Frezman
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.

Re: Pulling the Power Cord

Posted: Wed Jan 11, 2017 1:37 pm
by dom
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...

Re: Pulling the Power Cord

Posted: Wed Jan 11, 2017 2:10 pm
by alphanumeric
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.