Anonymous213
Posts: 2
Joined: Thu Oct 17, 2013 8:45 am

Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 9:11 am

Good day,

I (and I expect many others) made the experience that shutting down the Raspberry Pi without using the shutdown command ("hard kill") often results in data loss on the SD-Card and therefore in unbootable devices. Or as written here:
http://www.raspberrypi.org/phpBB3/viewt ... 28&t=58151:
Lastly, if you finally have managed to boot your PI for the fist time, (I recommend you try it the first time with Raspbian) make sure to do a proper shutdown.
[...]
Not following this procedure may lead to corruption of the cards contents.
I think this makes the Raspberry Pi for many purposes usless. Most people (me included) want a raspberry that does sth. in the background and that can be turned on and off whenever needed. E.g. if the Raspberry Pi is used as a additional media-device with your TV: If I go to bed I simply switch off the extension lead where all devices are connected (Raspberry, TV, Receiver, ...). I dont want to log first into the Raspberry Pi and to write "sudo shutdown ...". So I need a "hard kill" functionality.

--------------------------

What are possible solutions to avoid this? My ideas:

1.) Always booting with a filesystem check and automatic repair
Would it be possible to boot with a filesystem check performed? Sth. like this:

Code: Select all

sudo /usr/sbin/fsck.ext4  -f /dev/sdcx
Could this fix possible problems after a hard kill?

2.) Using an external Harddrive / SSD
The SD-Card will always be necessary to boot. However, maybe it is possible to store all other stuff on a "real" Harddisk which is more stable? Or is the problem of corrupt filesystem entries not connected to the SD-Card but to the filesystem itself?

3.) ???

Do you have further ideas? Thanks for helping

User avatar
rpdom
Posts: 12949
Joined: Sun May 06, 2012 5:17 am
Location: Ankh-Morpork

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 9:59 am

1.) The filesystem will always be checked after an improper shutdown. However it cannot recover data that was waiting to be written at the time, and the SD card can suffer a fatal error if turned off while doing some of its internal wear-levelling and other functions.

2.) Yes. It is quite easy to transfer the root "/" filesystem to a USB hard disk. The /boot area must be on the SD card though, but that is rarely written to.

3.) I can't think of any other ideas. A "proper" shutdown is always the best way to go. The Pi, like most computers, is not designed to be "just switched off" like a cable-box or DVD player.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 10:00 am

This is an interesting problem. I have never done this but I do have an idea which I think could work. The idea would be to create a ram drive in memory (ramfs) which you transfer a system to. You then chroot that as the main drive and then unmount the SD card ext4 partition. Do all that at boot time so that the Pi is only using the SD card when you first turn it on. Then I presume it would be safe to just power it off.

Best to get a second opinion from one of the hardware guys though.
Have a look at this topic also; http://www.raspberrypi.org/phpBB3/viewt ... 84#p119884

pjc123
Posts: 913
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 10:52 am

You might want to search this forum as this topic has been discussed to death.
My Raspberry Pi Project Page:
https://www.flaminghellmet.com/launch/

Anonymous213
Posts: 2
Joined: Thu Oct 17, 2013 8:45 am

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 11:12 am

So it would be kind if you would provide a link since it seems that my search-skills are not good enough (could not find a solution)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 1:13 pm

Every time this comes up, the OP is told to "buck up" and "That's the way it is.".

But the fact is that the complaint is legitimate. The Pi *shouldn't* be this sensitive. It *should* be like a "set top box" (or a "media streaming box"). Think about it. For example, the Roku is based on the same SOC as the Pi, so it should be at least comparable. Yet, I highly doubt that the Roku blows up and becomes unusable every time there is a power failure (or the user pulls the plug).

Now, having said that, here's what I really think. Having never had a problem myself (knock, knock wood, and all that...), I often think that this whole "SD card corruption" thing is a smokescreen. It may well be that when people complain about "corruption", it's really that they did something dum^H^H^Hunwise and the "gentle" answer is to "blame" it on "SD card corruption".
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

fredoll
Posts: 220
Joined: Thu Jan 10, 2013 10:30 am

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 1:17 pm

read-only file system ?

hippy
Posts: 4031
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 1:23 pm

Davespice wrote:Do all that at boot time so that the Pi is only using the SD card when you first turn it on. Then I presume it would be safe to just power it off.
One would have thought so but I recall posts where people have used the SD card entirely read-only and were still reporting SD card corruptions, and if I recall right, with just resets and without pulling the plug.

I cannot find that thread at the moment and don't remember if there ever was a cause found or a resolution to the issue.

If the SD card is used read-only, nothing is ever written to it or deleted, there never should be any corruption unless the card itself is doing something whilst idle when power disappears.

Some people pull the plug regularly and never see any problems while some people seem to see frequent corruption even when seemingly doing things properly. I believe there needs to be a deeper investigation before that mystery can be solved.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 2:22 pm

Anonymous213 wrote:3.) ???

Do you have further ideas? Thanks for helping
My solution is "Clean shutdown by battery (Ni-MH-accu) if mains power is lost". So clean shudown is always done and you can simply "pull the plug". Using this on 2 different raspi-systems (MPD-server and backup-fileserver) and had never any problems ...

MfG, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Turning off Raspberry PI without proper shutdown

Thu Oct 17, 2013 4:09 pm

My solution is ...
That doesn't account for the case of when the machine crashes (and you have no other choice for recovery than pulling the plug).

Not to mention the fact that the Pi draws so little power that there's not really any need to ever turn it off anyway (OTHER THAN when it crashes, of course...)
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

rn43x
Posts: 10
Joined: Sun Aug 31, 2014 12:38 pm

Re: Turning off Raspberry PI without proper shutdown

Sun Aug 31, 2014 2:21 pm

so, almost a year went by and here we are again :)

There was a post by FM81 and I think that is the most reliable and elegant solution.

@FM81: can you give us details (how to connect, necessary scripts)?

Best regards

rn43x
"To the rational mind nothing is inexplicable, only unexplained ..."
(Robots of Death, 1977)

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Turning off Raspberry PI without proper shutdown

Sun Aug 31, 2014 4:49 pm

Its a problem for some people, my continuously running Pi (about 2 years now) has an unscheduled power off event on average once a month (Usually an "accident" with the toaster that trips the earth leakage circuit breaker, taking everything on the circuit down). Its never corrupted an SD card. If I want to stop it, I shut it down properly, but it dies due to power loss far more often.

I put it down to my use of "boring" Sandisk 8GB Class 4 cards. (This forum has a fixation with big class 10s) The power supply is nothing special (1 amp no name bought off Ebay) and its run headless. The power supply feeds an Arduino and numerous sensors and 2 USB webcams (no hub) as well as the Pi.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

elliott954
Posts: 1
Joined: Tue Nov 11, 2014 2:38 pm
Location: Houston, Tx.
Contact: Website

Re: Turning off Raspberry PI without proper shutdown

Tue Nov 11, 2014 2:49 pm

I wanted to solve the same problem, plus add a UPS to my pi I combined both ideas into one, and built a circuit that incorporates an Arduino Micro. It works very well.

If this sounds like it might meet your needs, see it at http://solutionsuncommon.com/raspberry- ... sequencer/

sporex
Posts: 14
Joined: Thu Jan 23, 2014 3:25 pm

Re: Turning off Raspberry PI without proper shutdown

Wed Jan 18, 2017 4:26 pm

Davespice wrote:This is an interesting problem. I have never done this but I do have an idea which I think could work. The idea would be to create a ram drive in memory (ramfs) which you transfer a system to. You then chroot that as the main drive and then unmount the SD card ext4 partition. Do all that at boot time so that the Pi is only using the SD card when you first turn it on. Then I presume it would be safe to just power it off.

Best to get a second opinion from one of the hardware guys though.
Have a look at this topic also; http://www.raspberrypi.org/phpBB3/viewt ... 84#p119884
Yes indeed an interesting problem that I'am also facing.
I am constructing a telephone device with voice streaming over IP for a Railway operator.
Most probably, for maintenance works by the local staff, the Pi will be just powered off.

How big are the chances that the SD card will be damaged?
If it's a 1:500 - 1:200 chance then it will be acceptable for the device. If it's more, then I have to look for annother solution.

Does anyone have experiences with this probabilities?

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: Turning off Raspberry PI without proper shutdown

Thu Jan 19, 2017 4:58 am

I am constructing a telephone device with voice streaming over IP for a Railway operator.
So I assume using a RPi3 and boot it via network, can NOT be a solution in this case?
How big are the chances that the SD card will be damaged?
If you use an initramfs-approach, it will tend down to zero (may be not reaching it), because there is no need to have the SD-card mounted after boot-up is done. (In theory you can pull the card, after startup is done.)
If it's a 1:500 - 1:200 chance then it will be acceptable for the device.
In the past I've used an normal, but readonly mounted system. There sould be no problems too, but in practice there was a chance for corruption too (because of wear-leveling on some cards, also when used read-only), nearly in the range of numbers, as you've described. At least in my case ...

Greetings, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

User avatar
Gavinmc42
Posts: 2204
Joined: Wed Aug 28, 2013 3:31 am

Re: Turning off Raspberry PI without proper shutdown

Thu Jan 19, 2017 5:34 am

I use piCore Linux for stuff that has to survive power outages.
It boots from SDcard into ram,. it only write back to the card if you tell it too.
It is also much smaller so with less flash used on the card less chance of a single bit errors...

A good way to make a Raspbian OS survive is to make sure there is no net connectivity.
I have found Raspbian will last longer that way. Still a pain to back up a 8GB card.

These days I use Ultibo, no OS at all, power gets pulled on them all the time.
I even pull the SDcard out when powered up, copy new kernel on and use reset pins to reboot.
I use my oldest 128MB card for testing, larger micron size, less bit errors.
Actually been looking for small capacity micro SD's.
Application Kernel is only 2-3MB, don't really care how slow it is as it still boots in under 2 seconds.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

sporex
Posts: 14
Joined: Thu Jan 23, 2014 3:25 pm

Re: Turning off Raspberry PI without proper shutdown

Thu Jan 19, 2017 9:27 am

So I assume using a RPi3 and boot it via network, can NOT be a solution in this case?
Could be a solution, but would not be the optimal one, as there are chances that the network is not entirely available at boot of the device. (LAN segments are spread over a number of microwave links)
In the past I've used an normal, but readonly mounted system. There sould be no problems too, but in practice there was a chance for corruption too (because of wear-leveling on some cards, also when used read-only), nearly in the range of numbers, as you've described. At least in my case ...
I think I will go for this solution. It seems simple and straightforward.

Greetings Sporex,

User avatar
Greg Erskine
Posts: 78
Joined: Sat Sep 15, 2012 4:20 am

Re: Turning off Raspberry PI without proper shutdown

Thu Jan 19, 2017 9:44 am

Gavinmc42 wrote:I use piCore Linux for stuff that has to survive power outages.
It boots from SDcard into ram,. it only write back to the card if you tell it too.
It is also much smaller so with less flash used on the card less chance of a single bit errors...
+1
Fresh Linux install on every boot.

Return to “Troubleshooting”