Autorun fsck / -y when readonly filesystem?

Sometimes, my Pi memory card will corrupt. This is almost certainly always resolved by running fsck / -y

I wonder, is it possible for this command to run when a readonly filesystem is detected?

I notice my other usual crontabs dont work when the system is in readonly state.

Is this possible at all?

Needs an initramfs for this to reliably work

Sam

Thanks Sam.

Is that something that could be considered as a feature request?

It would be great, especially for the newbie to have a self-repairing filesystem for small corruption problems.

I will do some research on how to do this.

I’m not too eager to put in an initramfs as it will slow down the boot and could break some things. If it’s to be done, it would be done near the end of the year.

Sam

For the systems I manage I just modified /etc/fstab to run it every time. On a clean file system it is near instantaneous. This saves me a lot of headache and gas (driving to fix family members PI’s.)

You could do the same.

2 Likes

Thanks Shadow, I will take a look at that!

What exactly did you type in fstab?

I just changed the last 0 to a 1 for the root partition and a 2 for the boot partition

/dev/mmcblk0p1 /boot vfat defaults,noatime 0 2
/dev/mmcblk0p2 / ext4 defaults,noatime 0 1

Here is some quick docs on fstab options
https://wiki.archlinux.org/index.php/Fsck#fstab_options

1 Like

I’ve made the changes, so now that all partitions will be scanned, will they also be fixed on boot if necessary?

Why hasn’t this been the default?

Yes they get fixed if needed.

1 Like

Any reason why this wasn’t enabled by default?

Just to add, I have some memory cards that were stuck in read-only mode with corruption. I edited the fstab in a VM, booted and the filesystems were repaired and then booted!

This should be enabled by default!

We are investigating the safety of enabling it by default.

It’s not as simple a change as it appears though, first of all we would have to parse your (possibly customised) copy of fstab and attempt to change only those two lines (this can be done with sed, but we have to be very careful) secondly enabling automatic fsck on boot potentially means that if the corruption is severe enough that it will stop the bootup process and ask the user some questions on how to proceed with the repair - which is a big problem if you (a) don’t have a keyboard to answer the questions and (b) can’t read the questions due to the overscan on your TV… :wink:

Automated fsck with forced repair does come with it’s own risks.

1 Like

I hear you DBMandrake.

However if you have reached the point of corruption, your main choice to repair the filesystem is to unmount the microsd, mount it elsewhere, repair it, then return it.

For average joe with no huge skills or access to other linux machines, this means the usual solution is to completely reimage.

For user-friendlyness, this option should be changed.

I agree with yhs4260.
+1

Not so! The emergency recovery console is still an option.
https://osmc.tv/help/wiki/console

I see, but for people like my mother who don’t even have a keyboard a recovery console is well beyond their skillset!

an automated disk repair is simpler in such circumstances, to make things super user friendly.