Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Solved: Pull the plug

Sun Nov 18, 2018 11:20 pm

Hi mates! According to the oficial FAQ O shouldn't just unplug the pi from the wall as it might corrupt the SD Card. If I use any other media to boot the OS (SSD,hdd,usb thumb drive), will I get the same problem? If so is there any workaround? I've thought of using a button to shutdown the pi (through a python/shell script) but as I'll not be the one operating it I don't really like that solution. Thanks in advance!
Last edited by Zizico2 on Wed Nov 21, 2018 11:09 am, edited 3 times in total.

Andyroo

Re: Pull the plug

Mon Nov 19, 2018 12:56 am

No matter what the media is there is a chance that the disk will corrupt as Linux can cache data before its flushed to disk.

There are many ways to use a button to both shutdown and power on the Pi but they require the machine to be operational.

Best bet is to use the shutdown command after programs are closed.

User avatar
HawaiianPi
Posts: 5206
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Pull the plug

Mon Nov 19, 2018 2:35 am

The above statements are true for Raspbian, but there are other options (like Tiny Core Linux, which is an OS that runs entirely from RAM). Persistence is the main issue. If you don't need to save data between boots, then something like Tiny Core could allow powering off at any time.

If you DO need to save data, then it gets more complicated, because you would have to ensure that important data is written out before the system is powered down. The safest way to do that is with a proper software shutdown, then wait for the ten flashes of the green activity LED, and then disconnect the power. You could disable write caching to minimize the risk of data corruption in the event of a sudden power loss, but that's not 100% guaranteed to work. Data could be saved to the cloud or a server (depending on what you need to save).

A button on GPIO with a script or software that performs a proper shutdown could be combined with another button on the run header to start the system back up, without actually disconnecting the power (it only draws a tiny amount of power when shutdown).

Not really sure what you need because you didn't explain what you are trying to accomplish.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Pull the plug

Mon Nov 19, 2018 3:03 am

While any reasonable OS is going to cache data, some options are less likely to cause FS curruption depending on application.

RISC OS is not as likely to cause curruption from a hard power down like that. Then there are even other non-Linux options, some of which are not as lazy about flushing out cache, and thus reduce the probability of curruption.

Put simply it is the same reason that, before you umount a mass storage device, you manually flush the cache with the sync command in Linux and most other Unix like systems, or by using the Dismount command in RISC OS.

It is just safe practice.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

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

Re: Pull the plug

Mon Nov 19, 2018 3:24 am

The simplest way to set up a "pushbutton to shut down" is to add "dtoverlay=gpio-shutdown" to /boot/config.txt and rig a NO momentary contact switch across pins 5 and 6. Push once to shut down the system. Push again to reboot it.

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Pull the plug

Mon Nov 19, 2018 5:00 am

HawaiianPi wrote:
Mon Nov 19, 2018 2:35 am
The above statements are true for Raspbian, but there are other options (like Tiny Core Linux, which is an OS that runs entirely from RAM). Persistence is the main issue. If you don't need to save data between boots, then something like Tiny Core could allow powering off at any time.

If you DO need to save data, then it gets more complicated, because you would have to ensure that important data is written out before the system is powered down. The safest way to do that is with a proper software shutdown, then wait for the ten flashes of the green activity LED, and then disconnect the power. You could disable write caching to minimize the risk of data corruption in the event of a sudden power loss, but that's not 100% guaranteed to work. Data could be saved to the cloud or a server (depending on what you need to save).

A button on GPIO with a script or software that performs a proper shutdown could be combined with another button on the run header to start the system back up, without actually disconnecting the power (it only draws a tiny amount of power when shutdown).

Not really sure what you need because you didn't explain what you are trying to accomplish.
How would I go about running tinyCore entirely from RAM? While saving data would be the optimal cenario I can live without it. And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?

EDIT: Ignore the first question xd.
Last edited by Zizico2 on Mon Nov 19, 2018 5:16 am, edited 1 time in total.

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

Re: Pull the plug

Mon Nov 19, 2018 5:11 am

Zizico2 wrote:
Mon Nov 19, 2018 5:00 am
HawaiianPi wrote:
Mon Nov 19, 2018 2:35 am
The above statements are true for Raspbian, but there are other options (like Tiny Core Linux, which is an OS that runs entirely from RAM). Persistence is the main issue. If you don't need to save data between boots, then something like Tiny Core could allow powering off at any time.

If you DO need to save data, then it gets more complicated, because you would have to ensure that important data is written out before the system is powered down. The safest way to do that is with a proper software shutdown, then wait for the ten flashes of the green activity LED, and then disconnect the power. You could disable write caching to minimize the risk of data corruption in the event of a sudden power loss, but that's not 100% guaranteed to work. Data could be saved to the cloud or a server (depending on what you need to save).

A button on GPIO with a script or software that performs a proper shutdown could be combined with another button on the run header to start the system back up, without actually disconnecting the power (it only draws a tiny amount of power when shutdown).

Not really sure what you need because you didn't explain what you are trying to accomplish.
How would I go about running tinyCore entirely from RAM? While saving data would be the optimal cenario I can live without it. And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?

Tiny Core Linux:

http://forum.tinycorelinux.net/index.ph ... ,57.0.html
Retired disgracefully.....
......to a more gentile life !

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

Re: Pull the plug

Mon Nov 19, 2018 5:40 am

Zizico2 wrote:
Mon Nov 19, 2018 5:00 am
And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?
Doable? Yes. Easy? Not so much. The best way to handle that scenario is to get a UPS designed for the Pi. The big problem here is that most people think "Batteries...Li Ion/LiPo." The problem with that is that very few commercial battery packs permit charging while in use (charging Lithium batteries is tricky and if done wrong makes for truly spectacular results...that you wouldn't like). The attached UPS I'm most familiar with are the MoPower units. They can use most types of batteries other than Lithium. They will permit what you want to do, though.

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Pull the plug

Mon Nov 19, 2018 6:17 am

W. H. Heydt wrote:
Mon Nov 19, 2018 5:40 am
Zizico2 wrote:
Mon Nov 19, 2018 5:00 am
And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?
Doable? Yes. Easy? Not so much. The best way to handle that scenario is to get a UPS designed for the Pi. The big problem here is that most people think "Batteries...Li Ion/LiPo." The problem with that is that very few commercial battery packs permit charging while in use (charging Lithium batteries is tricky and if done wrong makes for truly spectacular results...that you wouldn't like). The attached UPS I'm most familiar with are the MoPower units. They can use most types of batteries other than Lithium. They will permit what you want to do, though.
Thanks! I'll look into it.

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Pull the plug

Mon Nov 19, 2018 6:24 am

W. H. Heydt wrote:
Mon Nov 19, 2018 5:40 am
Zizico2 wrote:
Mon Nov 19, 2018 5:00 am
And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?
Doable? Yes. Easy? Not so much. The best way to handle that scenario is to get a UPS designed for the Pi. The big problem here is that most people think "Batteries...Li Ion/LiPo." The problem with that is that very few commercial battery packs permit charging while in use (charging Lithium batteries is tricky and if done wrong makes for truly spectacular results...that you wouldn't like). The attached UPS I'm most familiar with are the MoPower units. They can use most types of batteries other than Lithium. They will permit what you want to do, though.
Wait... Could I not do this with a good ol' battery bank I have laying around?

morticiaskeeper
Posts: 101
Joined: Mon Aug 27, 2012 6:05 pm

Re: Pull the plug

Mon Nov 19, 2018 6:48 pm

I have been running a HUD speedo on a Pi Zero for almost two years.

Approximately twenty times a day, five days a week, it has had the power supply cut when I switch off the ignition. Never had a problem.

Over the last month, I've also had a SQL database recording up to four thousand records per day. I put a shutdown button, but have forgotten it a few times, still without problems.

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

Re: Pull the plug

Mon Nov 19, 2018 8:34 pm

morticiaskeeper wrote:
Mon Nov 19, 2018 6:48 pm
Approximately twenty times a day, five days a week, it has had the power supply cut when I switch off the ignition. Never had a problem.
Some people can step into roads without ever looking and never get run over. Some people smoke 40 cigarettes a day and never get cancer or COPD. Some people regale others with entertaining tales of how often they have 'electrocuted' themselves, have been hit by lightning, have been involved in car crashes, or falls from high up.

Not everyone is so lucky. And I would never bank on an outcome being the same as for anyone who has been. Especially when the evidence is that most people's experience diverges from that.

"Never had a problem" is not "won't ever have a problem". Not so far, no.

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

Re: Pull the plug

Mon Nov 19, 2018 9:28 pm

hippy wrote:
Mon Nov 19, 2018 8:34 pm
Some people can step into roads without ever looking and never get run over. Some people smoke 40 cigarettes a day and never get cancer or COPD. Some people regale others with entertaining tales of how often they have 'electrocuted' themselves, have been hit by lightning, have been involved in car crashes, or falls from high up.
Ah...so you've heard of James Nicoll.

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

Re: Pull the plug

Mon Nov 19, 2018 9:28 pm

Zizico2 wrote:
Mon Nov 19, 2018 6:24 am
W. H. Heydt wrote:
Mon Nov 19, 2018 5:40 am
Zizico2 wrote:
Mon Nov 19, 2018 5:00 am
And an idea I just had was to include a battery that charges while the whole thing is plugged in. And when the device would get unplugged It would trigger a gpio pin and run the shutdown command, with the battery powering the Pi.
Do you think it is doable?
Doable? Yes. Easy? Not so much. The best way to handle that scenario is to get a UPS designed for the Pi. The big problem here is that most people think "Batteries...Li Ion/LiPo." The problem with that is that very few commercial battery packs permit charging while in use (charging Lithium batteries is tricky and if done wrong makes for truly spectacular results...that you wouldn't like). The attached UPS I'm most familiar with are the MoPower units. They can use most types of batteries other than Lithium. They will permit what you want to do, though.
Wait... Could I not do this with a good ol' battery bank I have laying around?
What kind of "good ol' battery bank"?

User avatar
rpdom
Posts: 16124
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Pull the plug

Mon Nov 19, 2018 10:52 pm

hippy wrote:
Mon Nov 19, 2018 8:34 pm
Some people can step into roads without ever looking and never get run over. Some people smoke 40 cigarettes a day and never get cancer or COPD. Some people regale others with entertaining tales of how often they have 'electrocuted' themselves, have been hit by lightning, have been involved in car crashes, or falls from high up.
I had a friend like that. He had all sorts of crazy bad things happen to him, but kept on going. We buried him earlier this year, along with his SD cards. (actually, that second part isn't true. The cards were reused).

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

Re: Pull the plug

Tue Nov 20, 2018 1:14 am

hippy wrote:
Mon Nov 19, 2018 8:34 pm
morticiaskeeper wrote:
Mon Nov 19, 2018 6:48 pm
Approximately twenty times a day, five days a week, it has had the power supply cut when I switch off the ignition. Never had a problem.
Some people can step into roads without ever looking and never get run over. Some people smoke 40 cigarettes a day and never get cancer or COPD.
Even without cancer a significant amount of smoking will result in physiological changes that, even if unnoticed, are measurable and not insignificant. With an SD card, there are so many files that are unused on a typical Raspbian system that significant data corruption could go unnoticed for a long time: The system continues to boot and appears to function normally. On the other hand, files not in use are also less likely to be corrupted by a sudden power loss.

What brand of SD card are you using that appears resilient to data corruption when pulling the plug?

morticiaskeeper
Posts: 101
Joined: Mon Aug 27, 2012 6:05 pm

Re: Pull the plug

Tue Nov 20, 2018 8:04 pm

All my cards are Sandisk. I don't buy them online, I just go down to Argos.

My HUD speedo was designed for a car with van with permanent power, but the later vans cut the power, so I haven't had much choice. The SQL unit has a shutdown button, but I have forgotten a few times.

I do try to shut down my pi's properly, but it doesn't worry me too much to pull the plug. I know of a commercial pi based system that is always has the plug pulled, but the card is very tightly controlled in the app.

Zizico2
Posts: 11
Joined: Sun Nov 18, 2018 11:11 pm

Re: Pull the plug

Tue Nov 20, 2018 10:48 pm

W. H. Heydt wrote:
Mon Nov 19, 2018 9:28 pm
Zizico2 wrote:
Mon Nov 19, 2018 6:24 am
W. H. Heydt wrote:
Mon Nov 19, 2018 5:40 am

Doable? Yes. Easy? Not so much. The best way to handle that scenario is to get a UPS designed for the Pi. The big problem here is that most people think "Batteries...Li Ion/LiPo." The problem with that is that very few commercial battery packs permit charging while in use (charging Lithium batteries is tricky and if done wrong makes for truly spectacular results...that you wouldn't like). The attached UPS I'm most familiar with are the MoPower units. They can use most types of batteries other than Lithium. They will permit what you want to do, though.
Wait... Could I not do this with a good ol' battery bank I have laying around?
What kind of "good ol' battery bank"?
One with power passthrough and without a power button xd

Return to “General discussion”