pleriche
Posts: 90
Joined: Mon Oct 14, 2013 8:44 am

Resilience to hard shutdown

Fri Jan 24, 2014 4:40 pm

In an embedded application it's likely that a Pi will be shut down by summarily removing power. A couple of times when I've done that accidentally it's resulted in an unbootable SD card, which I fixed quite easily by running fsck on it under Linux running on my laptop. This implies that there's no automatic fsck run if the file system isn't clean. Can I easily enable it, or is there another accepted way to make it resilient to hard shutdowns?

Regards - Philip

User avatar
RaTTuS
Posts: 10487
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Resilience to hard shutdown

Fri Jan 24, 2014 4:44 pm

a battery backed system which shutsdown down nice on power fail
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

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

Re: Resilience to hard shutdown

Fri Jan 24, 2014 8:44 pm

sudo touch /forcefsck
will get a fsck on reboot.

That /forcefsck file gets removed so you may want to add a @reboot in root's crontab to touch it on every reboot.

Or you can add forcefsck to the /boot/cmdline.txt file to get the same effect (doesn't get disabled).
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.

Heater
Posts: 13608
Joined: Tue Jul 17, 2012 3:02 pm

Re: Resilience to hard shutdown

Sat Jan 25, 2014 10:22 pm

fsck as much as you like. In an embedded system I would want the SD mounted readonly. It will fail eventually otherwise.
Memory in C++ is a leaky abstraction .

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

Re: Resilience to hard shutdown

Sun Jan 26, 2014 1:23 am

pleriche wrote:This implies that there's no automatic fsck run if the file system isn't clean.
Of course. If the root filesystem has errors that prevent it from mounting at boot time, then there is no way to run the e2fsck program.

You could try to work around that by building a custom initramfs that runs e2fsck before mounting the real root filesystem. However, the ext4 journal already protects against filesystem-level inconsistencies due to sudden power loss. Your corruption must have a lower-level cause, such as the SD card itself losing power during an internal erase cycle or block reallocation for wear levelling. fsck cannot necessarily repair that anyway.

The only guaranteed way to avoid data loss on a power cycle is to have the card mounted read only.

Paul Moir
Posts: 46
Joined: Wed Dec 04, 2013 7:25 pm
Location: Nova Scotia, Canada

Re: Resilience to hard shutdown

Sun Jan 26, 2014 8:11 am

That's what I do too: it makes a lot of sense for an embedded system. I use IPE R1 which is already setup readonly and a usb stick for logged (R/W) data. The stick is automounted with usbmount, and it's mounted with the option "sync" to force all writes immediately with no caching. An even better method would be to send all writes to a remote NFS server, assuming it has network access.

Return to “Raspbian”