To protect against SD card corruption at powerloss, i want to force a filesystem check of the root partition /dev/memblk0p2 which is an ext4 partition as provided by the LEDE image.
I tried all options i could find on the internet, but either they are outdated or not relevant to LEDE:
tune2fs -c 1 /dev/memblk0p2
This sets the partition to be checked on boot; but i get only a message i should check the filesystem.the check is not executed
touch /forcefsck
does nothing aside from creating /forcefsck
appending the cmdline.txt with fsck.mode=force and fsck.repair=yes
does nothing
shutdown -rF
not available on LEDE
modifying /etc/options/fstab
file not available on LEDE
So can anyone please tell me the proper method to enable fsck at boot in a recent LEDE/OpenWRT?
e2fsprogs is of course installed and fsck.ext4 and e2fsck are available.
But it is impossible to check the root-fs while it is mounted; this needs to be done before mount by the kernel as i understand. And i am not getting this to execute at boot.
Alright, remounting in read-only mode did the trick; thank you!
Somehow i thought of ro-mode as not useful and write-protected also for fsck. But fsck and tune2fs can modify the filesystem in ro-mode.
Now i will combine it with another tip to put the check before rw-remount in:
/lib/preinit/80_mount_root
or i will wait for boot-completion and do the check with a few remounts.
So while this is possible to have the running system fsck'ed i wonder why the process of checking and fixing is not supported by LEDE/OpenWRT on its own? Sudden powerloss accidents do happen from time to time ...
I'm not sure which exact command @conner2 used but I had success on the Raspberry Pi (running 17.01 based system) by modifying the /lib/preinit/80_mount_root file adding this new line (you need to have the e2fsprogs package installed): /usr/sbin/e2fsck -y -v -f /dev/mmcblk0p2
before this existing line: [ "$INITRAMFS" = "1" ] || boot_hook_add preinit_main do_mount_root
Also I tested the in-built "check filesystem" option under the menu System->Mount Points but it didn't appear to work and in most cases gave a 'Bad Gateway' error after which the only recovery path was a reboot/power cycle.
Anyway it would be great if there was working support for filesystem checks in OpenWRT/LEDE as some storage systems and set ups aren't quite so reliable.
On desktop systems, it behaves like this...on OpenWRT/LEDE it does NOT!
As stated in the initial post, no method whatsoever will enable this at boot for the root partition.
My solution is to drive the system in read-only mode for all filesystems that reside on the sd-card. I additionally mount an USB-stick with ext4 to write stuff. There it behaves like you would expect and properly recovers from power failures and such incidents.
When a file-system has gone to read-only state, you can fsck and repair it from within a running running system...even if it is the root partition. And then you can force it to stay read-only as i have explained above. Or you need to take out the sd-card, check and repair it on a desktop system and then prevent it from going to write-mode ever again if you want to protect it.
can you translate that to simpler terms?. The reference link is way over my head. I have a USB3 external drive and would like to have the fsck run on boot. Where exactly is this line placed (in what config file)? Thanks.
Oh, wow, that was easy. Under the "System", "Mount Points" following down the list of topics there is a section "Mount Points" with the USB drive is in the list and is checked if it is enabled. If you click the "Edit" option, then on the "Advanced settings" is a check box for "Run system file check" (on boot). Excellent! Thanks!!