3

I'm hoping to use a Raspberry Pi as the basis of an in-car infotainment system. I've followed a number of guides on reducing boot times, but the Pi will often take a long time to boot—about 20 s longer than usual—apparently due to fsck running on the root filesystem on the SD card. These happen unpredictably: I've observed several slow warm (re)boots in a row, and several fast/normal ones in a row. I'm using sudo reboot and sudo shutdown now to restart or halt the Pi, and waiting for LED activity to cease before removing power.

Using systemd-analyze blame picarputer.service reveals the following for a slow boot:

         19.798s dev-mmcblk0p7.device
         18.968s systemd-fsck-root.service
          6.395s hciuart.service
          2.417s raspi-config.service
          1.911s networking.service
          1.571s sysstat.service
          1.557s dhcpcd.service
          1.487s monit.service
           806ms ssh.service
           ...

For a fast boot, the following is typical:

          6.479s hciuart.service
          1.781s networking.service
          1.657s dev-mmcblk0p7.device
          1.641s dhcpcd.service
          1.520s raspi-config.service
          1.284s plymouth-read-write.service
           543ms systemd-fsck-root.service
           ...

Running mount confirms that the mmcblk0p7 partition holds the root filesystem:

/dev/mmcblk0p7 on / type ext4 (rw,noatime,stripe=32596,data=ordered)

To simplify troubleshooting in the face of complications such as fake-hwclock, NTP and the lack of a BBU-RTC, I've deactivated the time-based fsck interval (tune2fs -i 0). I tried deactivating mount-count-based fsck scheduling entirely with tune2fs -c -1 but found that fsck was often still running.

I'm checking the mount counts using sudo tune2fs -l /dev/mmcblk0p7 | grep -i mount, which produces output such as:

Default mount options:    user_xattr acl
Last mount time:          Wed Oct 13 01:44:35 2021
Mount count:              2
Maximum mount count:      -1

After a slow boot, the mount count field has been reset to 1, and systemd-analyze shows ~20 s due to the root fsck. After a fast boot, the mount count field has incremented by 1 since the previous boot.

So, it seems that something is sometimes resetting the mount count, which causes a boot-time fsck. Sometimes the mount count increments monotonically each reboot, in which case boot times are reasonable, but when there is a slow boot, I find that the mount count has reset to 1. I don't know what would be resetting the mount count, whether it's happening at shutdown/umount or at boot time, or why it would only happen sometimes!

Hardware is a Raspberry Pi 3 Model B+. lsb_release -a returns the following:

Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.4 (stretch)
Release:    9.4
Codename:   stretch

Kernel version is:

4.14.74-v7+ #1149 SMP Mon Oct 8 17:39:42 BST 2018 armv7l GNU/Linux
3
  • 2
    "So, it seems that something is sometimes resetting the mount count, which causes a boot-time fsck."" -> That's backward. The mount count is reset because fsck was run, fsck does not run because something else reset it. Ie., what you describe is the expected behaviour (also, you don't have mount count dependent checking enabled, which means this number doesn't influence the decision). If you are shutting down properly, there is still no explanation of why it is happening. You can disable checks by adding fsck.mode=skip to /boot/cmdline.txt (or changing the value that's there already).
    – goldilocks
    Oct 12, 2021 at 14:05
  • It probably runs fsck because a dirty filesystem is found.
    – joan
    Oct 12, 2021 at 15:14
  • Good points, thank you. With fsck.mode=pass, the system rebooted 20 times in a row with no fsck (and didn't fsck even when the mount count limit was reached). tune2fs -l output shows the filesystem state as clean. After reverting to fsck.mode=auto, I get the irregular pattern of fast and slow boot times. Here are the mount counts for a series of reboots (slow boot/fsck each time it resets to 1): 1,2,3,4,5,6,1,1,2,3,4,1,2,3,1,1,1,1,2,1,2,1,2,3. Is fsck output logged somewhere? Am I allowed to make a "what the fsck" joke yet? ;)
    – screwtop
    Oct 13, 2021 at 0:09

1 Answer 1

0

You are using an old OS (soon to be obsolete) which appears to be installed over NOOBS. (Or wait a month for Bullseye to be released.)

You are probably also using an old SD Card.

Do a fresh install on a new SD Card.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.