User avatar
KnightOfPi
Posts: 50
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 6:05 pm

Hi all!

I made a software for a commercial application. I didn't design the hardware, and in the current design, the power is just switched off without a software shutdown. So, the internet says that's pretty bad for the SD card and the file system.

But how bad is it really?
How many life cycles can i expect, given good SD cards are used?

Thanks for your attentation!
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

User avatar
mikronauts
Posts: 2732
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 6:12 pm

Extremely bad, especially if the application writes to the SD card.

Mount your root partition read only, use a ram based temporary fs for logs, and move application data to a USB flash drive mounted with a sync flag to minimize issues.
KnightOfPi wrote:Hi all!

I made a software for a commercial application. I didn't design the hardware, and in the current design, the power is just switched off without a software shutdown. So, the internet says that's pretty bad for the SD card and the file system.

But how bad is it really?
How many life cycles can i expect, given good SD cards are used?

Thanks for your attentation!
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
KnightOfPi
Posts: 50
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 6:32 pm

Extremely bad, especially if the application writes to the SD card.

Mount your root partition read only, use a ram based temporary fs for logs, and move application data to a USB flash drive mounted with a sync flag to minimize issues.
Hey mikronauts,

thanks for your reply!

The device does not write explicitely to the SD card; it's a touchscreen interface for a video player, more or less, based on kivy.
I'll see if i can turn off all logging kivy may do in the background.

Is this approximately quantifiable?
Like, "more than 500 cold shutdowns and the card will be broken"?

There will be a virtual shutdown button, but i do expect people to forget that often...
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 6:51 pm

I don't believe there will be many people who know the answer to that. Any research that was carried out was probably in 2012, when Raspbian did not avoid writing to the filesystem as much as it does now. The only data I have is the trickle of people saying they corrupted their SD card, and that would not have been after 500 shutdowns, more like less than 100. On the other hand, that might be the thin end of the bell curve.

You could carry out some original research. You are unlikely to destroy the SD card, only corrupt the data on it, and a Raspberry Pi with a relay could easily make an automated test rig, so it needn't be expensive.

User avatar
davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 8:38 pm

The "standard model" of SD card corruption is that the card is vulnerable if a write operation is in progress when the power fails. So there are two factors: the likelihood of a write operation at any given time, and the likelihood of corruption when that coincides with a power failure. Quantifying the first factor comes from knowledge of your system, the second probably needs the research rurwin suggests (and may depend on the specific card make, or other factors in any one of the three Rumsfeldian classes of knowledge).

Then monitor your actual experience in case there is a flaw in the standard model :shock: :? :roll:
Signature retired

User avatar
jojopi
Posts: 3085
Joined: Tue Oct 11, 2011 8:38 pm

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 8:53 pm

You cannot really quantify the risk in terms of number of power cycles. Every time you do something unsafe, you could get unlucky.

If you remove power during or immediately after a write (when the card is still erasing blocks, reallocating data, or updating its flash translation layer), I suspect that the risk of data corruption is actually quite significant. Many people will not notice it unless it happens to hit something important and the operating system can no longer boot. That is not a argument for ignoring the problem.

On the other hand, I am happy to power off my Pies without shutdown if I know they are idle or read only.
mikronauts wrote:move application data to a USB flash drive mounted with a sync flag to minimize issues.
I would recommend not using the sync option. It prevents the kernel from buffering writes, and instead sends them all to the device straight away. That is less efficient, so it means there will be more windows during which it is not safe to remove power.

If there are specific files that need to be written out urgently, use facilities such as fdatasync(), as sparingly as possible.

Navyscourge
Posts: 258
Joined: Sat Oct 24, 2015 1:50 pm

Re: How bad is shutting down the Raspberry Pi cold?

Tue Feb 02, 2016 9:03 pm

Investigate a battery and a power-loss detection circuit that can trigger a GPIO pin and run a proper shutdown. There are a few commercial ones available, or you can find instructions to make your own

User avatar
DougieLawson
Posts: 36522
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How bad is shutting down the Raspberry Pi cold?

Wed Feb 03, 2016 9:36 am

KnightOfPi wrote: I made a software for a commercial application. I didn't design the hardware, and in the current design, the power is just switched off without a software shutdown. So, the internet says that's pretty bad for the SD card and the file system.
Why can't the software have a call to "sudo poweroff" and a menu option to drive that?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: How bad is shutting down the Raspberry Pi cold?

Wed Feb 03, 2016 9:54 am

DougieLawson wrote:Why can't the software have a call to "sudo poweroff" and a menu option to drive that?
KnightOfPi wrote:There will be a virtual shutdown button, but i do expect people to forget that often...

User avatar
DougieLawson
Posts: 36522
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How bad is shutting down the Raspberry Pi cold?

Wed Feb 03, 2016 1:03 pm

rurwin wrote:
DougieLawson wrote:Why can't the software have a call to "sudo poweroff" and a menu option to drive that?
KnightOfPi wrote:There will be a virtual shutdown button, but i do expect people to forget that often...
Then some careful use of a clue stick, an educational baseball bat or a lump of clue by four becomes the optimal way to get folks to do the right thing.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

mardor
Posts: 4
Joined: Wed Feb 03, 2016 2:30 pm

Re: How bad is shutting down the Raspberry Pi cold?

Wed Feb 03, 2016 3:11 pm

I have 1 original Rev B board (with 256KB) that has one class 10 16GB SD card.
SD card = 60MB /boot (fat) (mmcblk0p1), 3.6GB / (ext4) (mmcblk0p2), 12GB /opt1 (mmcblk0p3)

Has been up and running for 1.5 years...
Has seen about 4-5 power cycle reboots
Has seen over 500 watchdog reboots
Has (ext4) journaling
Has dump1090, faup1090, piaware running with MLAT
Has been hovering about 25-30% CPU usage
Has seen 3 log files (dump1090, piaware, and ntp) logfile always being written to in /var/log (mmcblk0p2)
Has seen syslog log file in /opt1/syslog always being written to (last 4 days growth is 115MB) (mmcblk0p3)

and
Has seen zero SD card corruption
PS I do have another SD card to swap in if its ever needed.

User avatar
KnightOfPi
Posts: 50
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: How bad is shutting down the Raspberry Pi cold?

Thu Feb 04, 2016 8:34 am

Woha, all, thanks a lot for the many and proficient replies!

We will add some learning sticks, bats and mines to the manual
and try to implement a clean physical shutdown button in the next edition of the device.

I need to check kivy for logging, but besides that nothing will be written to the SD, so hopefully the device will be somewhat stable.
The first edition will be no more then 20 units, so support won't require too much effort.

One solution sprang to my mind:
would it be difficult to take a standard ATX poweroff button and fit it to my RPi + circuit system?

Thanks again!
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

fruitoftheloom
Posts: 21043
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: How bad is shutting down the Raspberry Pi cold?

Thu Feb 04, 2016 8:38 am

KnightOfPi wrote:Woha, all, thanks a lot for the many and proficient replies!

We will add some learning sticks, bats and mines to the manual
and try to implement a clean physical shutdown button in the next edition of the device.

I need to check kivy for logging, but besides that nothing will be written to the SD, so hopefully the device will be somewhat stable.
The first edition will be no more then 20 units, so support won't require too much effort.

One solution sprang to my mind:
would it be difficult to take a standard ATX poweroff button and fit it to my RPi + circuit system?

Thanks again!
http://iot-projects.com/index.php?id=ra ... own-button
Retired disgracefully.....
This at present is my daily "computer" https://www.asus.com/us/Chrome-Devices/Chromebit-CS10/

Return to “Advanced users”