Page 1 of 1

Resilience to hard shutdown

Posted: Fri Jan 24, 2014 4:40 pm
by pleriche
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

Re: Resilience to hard shutdown

Posted: Fri Jan 24, 2014 4:44 pm
by RaTTuS
a battery backed system which shutsdown down nice on power fail

Re: Resilience to hard shutdown

Posted: Fri Jan 24, 2014 8:44 pm
by DougieLawson
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).

Re: Resilience to hard shutdown

Posted: Sat Jan 25, 2014 10:22 pm
by Heater
fsck as much as you like. In an embedded system I would want the SD mounted readonly. It will fail eventually otherwise.

Re: Resilience to hard shutdown

Posted: Sun Jan 26, 2014 1:23 am
by jojopi
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.

Re: Resilience to hard shutdown

Posted: Sun Jan 26, 2014 8:11 am
by Paul Moir
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.