annlee
Posts: 111
Joined: Thu Sep 03, 2015 5:32 am

Will it break by continously improper shutdown?

Fri Jan 15, 2016 6:54 am

hi there, got a rpi 2B (DietPi) embedded system which autoboots and startup a program that reads from grove sensors and write data every 3 seconds

this system is isolated and electricity comes up and down being shutdown many times (so no proper "shutdown now" command to do so),

do you think the rpi or the filesystem may break at some point? if so, how to prevent it?

Thanks in advance~

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 7:29 am

You may want to look at a UPS device for the Pi, you're going to have corruption with constant unplanned shutdowns. It's just a matter of when and how often you need to re-image the SDCard...
Account Inactive

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:32 am

What sort of data? Where's it being written?

You may be safer using a USB attached hard disk as the data storage medium and just having /boot on your SDCard (as that's read-only). If you write to an SQL database engine which maintains a journal then your data should be consistent to the last commit() call (because that's what the journal is there for).
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
karrika
Posts: 1072
Joined: Mon Oct 19, 2015 6:21 am
Location: Finland

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:52 am

I would recommend a journaling filesystem and a very simple write to file protocol. Because a journaling file system is just appending things to the end. So an abrupt blackout should only lose the last entry.

Storing data could also be as atomic as possible. Like

echo 3.14 >> 2015-01-16.dat

It opens, appends and closes the file in one go. Using any SQL in an unstable environment sounds problematic to me.

annlee
Posts: 111
Joined: Thu Sep 03, 2015 5:32 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 3:52 pm

DougieLawson wrote:What sort of data? Where's it being written?

You may be safer using a USB attached hard disk as the data storage medium and just having /boot on your SDCard (as that's read-only). If you write to an SQL database engine which maintains a journal then your data should be consistent to the last commit() call (because that's what the journal is there for).
the data stored are 2 CSV into the microsd card:
1º) a CSV file rewritten all time 1 field of the CSV with the most recent data (less than 1kB of size)
2º) a CSV file that is growing up all time with that 1 field

but what I fear most is to break the filesystem itself, in otherwords, to make the system not to boot or to run the program

consider this system should be mean to have such disconnections

the journaling solution can save the data from CSV but what I care most is to not to break the system itself, or writing the CSV files into a usb drive

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 6:01 pm

If you never write to the device that holds the kernel, /bin, /sbin, /etc and /lib it will always boot.

To be safe move /var to a USB device and write your data in a sub-folder under there. My data logging system mounts an NFS share on /srv and writes data to a sub-folder under /srv/data. The thing that kills that system is loss of the network.
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.

annlee
Posts: 111
Joined: Thu Sep 03, 2015 5:32 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 6:19 pm

DougieLawson wrote:If you never write to the device that holds the kernel, /bin, /sbin, /etc and /lib it will always boot.
it is a big relief to expect the system will always work even when being shutoff by supply cut off many times a day, I guess that is what you mean

regarding data safety of CVS for now it is not so important, but after I may implement ur solution in pendrive :mrgreen:

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 6:53 pm

I don't hit them hard very often, but pulling the power doesn't do any damage if the filesystem isn't being written.
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.

annlee
Posts: 111
Joined: Thu Sep 03, 2015 5:32 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 8:38 pm

DougieLawson wrote:I don't hit them hard very often, but pulling the power doesn't do any damage if the filesystem isn't being written.
uhmmm so I guess you are not completely 100% sure if will cause dmg to the filesystem, don't worry

this decission is very important for the design of the system, having it the whole time connected to a battery or like it is now getting cut off several times a day, I'm confused now :o

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 9:19 pm

Pulling the plug is like playing Russian Roulette - your card may survive 1 shutdown, 100 or even 1000. There is a chance it will be corrupted, and that chance increases if the card is being written to. How easy / long would it be to fix a corrupted card?

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 9:31 pm

It seems to have got better with the sdhost driver (it replaces the mmc driver). The problem, as you say is the unpredictabilty, you could pull the power hundreds, maybe thousands of times with no adverse effects then one time it's going to trash things.

I guess the best mitigation is always having a SDCard handy that you can swap out with the broken filesystem. That gives more reason for having data on a USB device as you'll only lose the current data not the historical archive when things go wrong. That's a common thing with IT systems in general is how much can you lose on the unexpected outage (and how much does it cost you). It's part of my day-job doing that stuff.
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.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 9:32 pm

annlee wrote:uhmmm so I guess you are not completely 100% sure if will cause dmg to the filesystem, don't worry

this decission is very important for the design of the system, having it the whole time connected to a battery or like it is now getting cut off several times a day, I'm confused now :o
I think that the other poster is saying that if you mount the os itself on its own drive and never write to it, you won't mess that up and therefore it should continue to boot. You would then write to another drive, say a thumb drive in one of the USB ports.

But there is no reason to think that writing to that while turning off power won't corrupt it. The plan would be to hope that you could fix that corruption because you could still boot from the other drive, the sdcard.

If you could wifi into a system that didn't have power issues and drop your data there, leaving the system you are worried about with only read only drives, that would seem far better.

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 9:38 pm

The reason I mentioned a UPS or a battery systems is because you said that the Pi would be located in an isolated location. I took that to mean that it would be difficult to get to in order to swap out the cards if you ended up with corruption due to power loss.
Account Inactive

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:01 pm

SonOfAMotherlessGoat wrote:The reason I mentioned a UPS or a battery systems is because you said that the Pi would be located in an isolated location. I took that to mean that it would be difficult to get to in order to swap out the cards if you ended up with corruption due to power loss.
If there's any warm body anywhere near the machine then sending a replacement SDCard by the postal service is cheap and easy and simple to implement. The warm body can pull power, swap cards, plug power back in and send the damaged SDCard back for analysis, recovery and reformatting.
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.

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:23 pm

DougieLawson wrote:If there's any warm body anywhere near the machine then sending a replacement SDCard by the postal service is cheap and easy and simple to implement. The warm body can pull power, swap cards, plug power back in and send the damaged SDCard back for analysis, recovery and reformatting.
Point well taken.
Account Inactive

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

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:28 pm

I've used that technique already. The folks I was working with even sent three Raspberry Pi model Bs for me to analyse. They didn't pay my invoice so I kept those three as part payment.
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
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Will it break by continously improper shutdown?

Fri Jan 15, 2016 10:29 pm

It's not possible to call a proper `shutdown` command whenever the Pi is done with whatever it's doing? How often does it need to shut down and start up?

Maybe a Pi isn't the best tool for the job. A micro controller pulls micro amps when it's in sleep mode. 3 seconds is an eternity, and the only sleep mode on a Pi is (indeed) to shut it down.

An Adafruit Adalogger for example, has an SD card and 3.7V LiPo battery connection ready to go: https://www.adafruit.com/products/2795

Have it `sleep()` all the time and trigger an interrupt every 3 seconds. Runs on a battery forever.
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

annlee
Posts: 111
Joined: Thu Sep 03, 2015 5:32 am

Re: Will it break by continously improper shutdown?

Sat Jan 16, 2016 6:26 am

panik wrote:It's not possible to call a proper `shutdown` command whenever the Pi is done with whatever it's doing? How often does it need to shut down and start up?

Maybe a Pi isn't the best tool for the job. A micro controller pulls micro amps when it's in sleep mode. 3 seconds is an eternity, and the only sleep mode on a Pi is (indeed) to shut it down.

An Adafruit Adalogger for example, has an SD card and 3.7V LiPo battery connection ready to go: https://www.adafruit.com/products/2795

Have it `sleep()` all the time and trigger an interrupt every 3 seconds. Runs on a battery forever.
my system has a grovepi+ with tons of sensors so rpi is pretty much best solution for ease implementation

I think I am going to have it plugged to a battery permanently (besides having a backup microsd with the img), ty everyone for the help

paulv
Posts: 558
Joined: Tue Jan 15, 2013 12:10 pm
Location: Netherlands

Re: Will it break by continously improper shutdown?

Sat Jan 16, 2016 9:35 pm

Maybe the solution in this post or one of the links within it will help you.
viewtopic.php?f=37&t=132201
Enjoy!
Last edited by paulv on Thu Jan 21, 2016 6:21 pm, edited 1 time in total.

Slackware
Posts: 131
Joined: Mon Jan 18, 2016 3:45 pm

Re: Will it break by continously improper shutdown?

Thu Jan 21, 2016 5:31 pm

it is called BACKUPS. keep a backup of the OS and you can then repair the corrupt system. go the extra mile and backup partition table info as well. data is on the disk platters, it is the file structure to find the data that makes it seem to be missing. at most you would kill one disk sector that was being written, and journaling filesystem keeps track of that sector write.
Put external drive on battery backup so it can finish it's write.

Killertechno
Posts: 181
Joined: Wed Jan 02, 2013 8:28 am

Re: Will it break by continously improper shutdown?

Fri Apr 01, 2016 9:27 am

Hi guys, I try to post here without open new thread: I need to write telemetry data every 30 seconds (about 200 bytes).
To do this I could use dedicated Raspberry SD card partition or external USB flash drive.
Now, it has been said I have to make OS read-only to extend SD card life and avoid filesystem corruption from improper shutdown (I'm working in 12V system, so using 12C to 5V DC/DC).
I'm confused, what about data?
Let's suppose I'll update daily file (if I'll append 200 bytes at time, 200 bytes every 30 seconds are 576'000 Bytes file), if power fails during writing?
I've read ext4 is journaling filesystem, but next boot may I find corrupted data file?
Or simply non-updated file?
Thanks.

edo1
Posts: 136
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: Will it break by continously improper shutdown?

Fri Apr 01, 2016 6:29 pm

Killertechno wrote:To do this I could use dedicated Raspberry SD card partition or external USB flash drive.
your data could be lost anyway.
but second approach give more chances to keep system bootable after disaster. I don't know does it matter to you or not.
Let's suppose I'll update daily file (if I'll append 200 bytes at time, 200 bytes every 30 seconds are 576'000 Bytes file), if power fails during writing?
I've read ext4 is journaling filesystem, but next boot may I find corrupted data file?
Or simply non-updated file?
In theory you can lose a few last records at worst. But in practice there are no warranties. It could be broken file, broken filesystem or broken device.
Now, it has been said I have to make OS read-only to extend SD card life and avoid filesystem corruption from improper shutdown (I'm working in 12V system, so using 12C to 5V DC/DC).
I'm confused, what about data?
I have a similar requirements. I've used USB flash on hundred devices for several years, it is unreliable solution.
In my new project I made a decision to do not use writable SD or USB flash devices at all.
I use read-only SD for a system, all data is stored on the remote server, circular buffer in SPI-connect NOR-flash is used to do not loss unsent data in case of power loss.

P.S. I haven't had enough statistics with this approach yet. But I believe it should be pretty reliable.

Killertechno
Posts: 181
Joined: Wed Jan 02, 2013 8:28 am

Re: Will it break by continously improper shutdown?

Sat Apr 02, 2016 11:25 am

Unfortunately I need to save data locally due I could not have connection, and I need removable support (so USB or OS uSD card or HD up to 2TB).
Actually I'm using Li-Ion battery backup system to supply Raspberry only for shutdown when detected power outage using microcontroller.
This works but I supposed there could be smarter way...

Return to “Beginners”