#StackBounty: #mount #init-script #fsck #root-filesystem How to perform a hot repair of a functioning, but limping rootfs with the swit…

Bounty: 50

I have an extreme edge case that I may never see again, but I’d like to be prepared. I have an embedded system (u-boot) whose primary disk has 4 partitions. One of the partitions is the rootfs (ext4) and unfortunately it is rw. The ext4 does a great job of handling rough interactions, but I saw an issue with it for the first time today. The mount was still functional but systemd-fsck-root.service failed and indicated it required a CTRL-D to continue and told me to run fsck.

systemd-fsck[1130]: /dev/mmcblk1p4: Superblock last mount time is in the future.
systemd-fsck[1130]:         (by less than a day, probably due to the hardware clock being incorrectly set)
systemd-fsck[1130]: /dev/mmcblk1p4 contains a file system with errors, check forced.
systemd-fsck[1130]: /dev/mmcblk1p4: Inodes that were part of a corrupted orphan linked list found.
systemd-fsck[1130]: /dev/mmcblk1p4: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
systemd-fsck[1130]:         (i.e., without -a or -p options)
systemd-fsck[1130]: fsck failed with error code 4.
systemd-fsck[1130]: Running request emergency.target/start/replace

My kernel does not have initramfs or a backup partition. All I have is:

  • A mostly unused partition next to the rootfs one
  • the switch_root command

My plan is the following:

  1. Copy the basic files I need to run linux on a different partition
  2. Copy fsck and anything else I need to repair the rootfs to the empty partition
  3. Jump over to the other partition with switch_root
  4. Umount the primary rootfs and perform the fsck fix
  5. reboot and the bootloader should just poitn back to the fixed primary

The main things I don’t know are:

  • Will this work?
  • What are the basic files I need for #1? Do I need to include loaded kernel modules or will those stay in the kernel?
  • What would a very simple init script look like to facilitate the switch_root jump?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.