mikey32094
Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 12:22 am

Hey all,

I was just wondering if you think it'd make sense to add a delay during the shutdown process, such that the Pi would wait an extra 30 seconds or so before actually powering off.. and if so, how to go about doing that?

I just got this idea thinking about the last few times I borked my OS. Each time I had just done a heavy apt update then quickly issued a "sudo reboot". Now I'm wondering if perhaps the SD card didn't have enough time to commit all the new data, and this lead to corruption.

Is this a reasonable assumption? Wrong?

User avatar
DougieLawson
Posts: 37732
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 12:23 am

There is a delay. The green activity LED winks 10 times after the system shuts down to tell you when it is safe to pull the power.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

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

Re: Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 12:36 am

The easy solution is just to not remove power - ever.

And note that OP said he did a "sudo reboot" - which implies that he was just rebooting - which would mean never removing power. In which case, there cannot be any card corruption.

So either OP is confused or there's something he is not telling.
If this post appears in the wrong forums category, my apologies.

wildfire
Posts: 581
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Re: Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 12:50 am

mikey32094 wrote: Is this a reasonable assumption?
No
Wrong?
Yes, as explained above there's missing/misleading information in your post.

How often have you borked your SD card? Is it the same one or different one's? Are they from the same supplier? Are they reputedly from the same manufacturer?
E8 85 A2 64 C9 64 81 94 64 81 95 64 89 84 89 96 A3
Still NF Shirls

mikey32094
Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Re: Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 8:43 am

Hmmm great tip on not yanking the power right away. I'm sure I've done that more than once on accident.

Regarding the "sudo reboot" being misleading. No that's really what I'd done.

I updated my Pi from a remote location a few times. Basically the process was:
  • SSH in, Enter "screen" to protect from disconnect
  • sudo apt-get update;sudo apt-get upgrade -y;sudo apt-get dist-upgrade -y;sudo reboot;
Back at my location I'd then close the terminal and ping the Pi. It'd eventually stop responding (supposedly meaning the reboot process had started) and just never come back up. I'd then go home and hook it up to my monitor and note that apt was spitting out weird messages, systemd seemed to be corrupted, etc.

The only missing thing maybe is I can't with 100% certainty guarantee I didn't yank the power cable when I got home, under the assumption the reboot never came back up due to the ping failure. Hmmm.....

By the way, is there a way to tell the Pi to blink indefinitely once poweroff is complete? I'm sure I'll miss those 10 blinks ....

chuckc192000
Posts: 18
Joined: Mon Nov 21, 2016 2:59 am

Re: Protecting SD Card: Delay before poweroff?

Tue Jan 03, 2017 7:06 pm

I never realized that SD card corruption was a danger when cutting the power to the RPi. That makes it a little impractical to use as an embedded device (imagine having to do a graceful shutdown when you unplug your microwave oven or TV).

mikey32094
Posts: 38
Joined: Sat Jul 25, 2015 10:07 am

Re: Protecting SD Card: Delay before poweroff?

Wed Jan 04, 2017 11:09 am

chuckc192000 wrote:I never realized that SD card corruption was a danger when cutting the power to the RPi. That makes it a little impractical to use as an embedded device (imagine having to do a graceful shutdown when you unplug your microwave oven or TV).
Well technically you can boot with the OS in read-only mode, or mount frequently written files to a USB stick/disk. I personally mount /var/log to my thumb drive, along with swap, and my corruptions have become much less frequent.



UPDATE: Pi3 corrupted again while waiting for replies to this thread. All I did this time was disable a couple services do updates, issue reboot, all over SSH; No power unplugging :(

Luckily it was a few random packages this time, and not actual apt or systemd, so debsums saved me again.

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

Re: Protecting SD Card: Delay before poweroff?

Wed Jan 04, 2017 12:01 pm

chuckc192000 wrote:I never realized that SD card corruption was a danger when cutting the power to the RPi. That makes it a little impractical to use as an embedded device (imagine having to do a graceful shutdown when you unplug your microwave oven or TV).
This depends on, how you try to specify an "embedded system"!
Of course there will it be problem if there are tens of services/databases running or probably a graphical interface with active users is active etc.

But for simpler approaches (only for examples: as dhcp-server, as web-server, as music-player) you can:
- make the system read-only (as said in the the post before)
- put all your stuff in an initramfs (theoretical it is possible, to remove the SD-card after startup done)
- or if you use an RPi3 boot all your stuff via network (no SD-card at all, only for initial setup)
May be, you'll find no pre-made things for such "specials", but that's the fine point in linux: You can build it yourself, if you only want ...

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!

ElEscalador
Posts: 786
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

Re: Protecting SD Card: Delay before poweroff?

Wed Jan 04, 2017 1:57 pm

Are you allowing these processes to complete before issuing reboot or disconnecting?

If you are closing the connection before upgrades are done who knows what was in the middle of happening (I learned the hard way that closing the connection kills processes started from the remote computer).

I instead often VNC into a pi and open a terminal on that vnc session - then it stays running when I close the connection. A program called Screen would also allow you to open a terminal session and leave and come back to that same session that remains running the whole time. I haven't used it yet, though.
Robotics tips, hacks, book extras https://youtube.com/c/practicalrobotics

Return to “General discussion”