How to mount root partition as read only on boot

I’m trying to mount the root partition of my sd card as read-only to repair some severe corruption of the partiton. Although system seems to be working properly, I can’t upgrade it and I’m seeing disk i/o errors in logs.
I don’t have physical access to it because it’s a remote machine so I was trying to mount as read only modifying the /etc/fstab file, adding ro as parameter to this partition.
The issue is fstab is always overwritten during boot to defaults values so not mounting root partition as read-only. How can I modify fstab avoind being it overwritten?.

How would you repair a partition if you mount it read-only?

Could it be that your SD Card is broken which means it seems to accept your writes but they are actually not put on the card? To prove that just create another file (e.g. /etc/test123) reboot and check if the file survive

If you are making system changes that are not persistent after reboot, this is a highly likely indicator that your sdcard has already failed… Replace it.

The card might be corrupt and require a reinstall (or be replaced) but a way to run a fsck on the root partition is to edit the file /lib/init/ and set FSCKFIX=yes

Then reboot.

OSMC already attempts to fsck corrupted partitions on boot.

So what happens when FSCKFIX=yes is used? Any difference in behaviour?

I don’t know… Try it… :wink:

System changes persists over reboots including creating new files, so I expect that theses errors I’m suffering could be related to some inode issues that I could repair with fsck, without replacing the sd card.
But to be able to confirm it, I need first to run fsck over root partition in a remote machine, something that it’s not possible if the file system is mounted in rw mode. I expected that mounting it as ro during boot I could run fsck over it.
How can I modify fstab avoiding it to be overwritten on boot?

P.D.: From what I could read in the forum, running FSCKFIX=yes only seems to fix light errors automatically. Indeed partition seems to be clean when booting seeing dmesg messages:

[ 2.752214] fsck: Filesystem UUID: 2a94b5d0-675e-4299-b13a-649302000e9d
[ 2.752463] fsck: /dev/mmcblk0p2: clean, 65014/962880 files, 1186961/3848704 blocks

But this doesn’t imply that after booting I can see randomly inode errors in logs later.

fsck ideally should not run on a partition mounted in any read configuration… It really sounds like you are avoiding the cause of your problems and only attempting to fix the symptoms here…

How did you get into this issue in the first place?

No, after you…

This method would be acceptable in OSMC.
sudo touch /forcefsck && sudo reboot and OSMC will run a full filesystem check on reboot.

As to how it works, for all I know, it may simply implement the same steps you provided above…

I detected it when trying to upgrade from kodi 16.2 to 17.1. During the update process launched with MyOSMC app, it reported issues during the upgrade process with different packages in different tries, reverting always back.
Looking dmesg/journalctl logs I detected some inode issues during these tries.
Probably I will have to replace the sd card and reinstall it, but before doing it I prefer to be totally sure that this is the cause because it’s a remote machine, so it’s not so easy/quickly that it could be expected. This is why I was trying to run fsck over root partititon.

In another test I just detected some new files I created are missing now after reboot, and I don’t have any inode errors in logs. Initially I thought fstab was overwritten by some process like initramfs automatically, but the cause could be the card is already broken as it’s pointed.
Partition is correctly mounted in rw:
/dev/mmcblk0p2 on / type ext4 (rw,noatime,stripe=1024,data=ordered)

Try sudo apt-get update && sudo apt-get dist-upgrade && reboot

After boot, provide grab-logs -a

Additionally, try:

echo “test” > test.txt

and after reboot

cat test.txt

If result is “file not found” then SD Card gone

Upgrade process failed also in command line. Attached the logs:

The test file is missing after reboot… :angry: Bye Bye sd Card…

Anyway, Thank you very much for your help!

Unforutunate, though I think >1yr is a reasonably good run on an SDcard… Good luck! Don’t forget that the OSMC store offers high performance SDcards as well!

Suggested that test 10 posts before :wink:

1 Like