Enabling File System Check on Boot?

Hello,

I’d like to enable periodic file system check on boot for both the root (ext4) and boot (fat) volumes. Particularly as I have to hard reboot the Pi from time to time, I’d like to make sure the boot volume especially gets checked.

Here’s what I got re: mounting and checking from dumpe2fs.

  1. No idea what’s wrong with the last mount time. Any ideas?

  2. The maximum mount count is clearly disabled.

  3. I’ve read the arch wiki’s entry on this, and it gives a couple of different options. What’s the best way to do it on a Raspberry Pi using an NVME SSD?

  4. What’s the best way to automatically check the boot partition from time to time?

If you are asking how to enable it:
sudo tune2fs -c 10 /dev/sda2
(for instance)

1 Like

Check fsck.mode=force fsck.repair=yes boot parameters

1 Like

The pi probably doesn’t have a RTC, so the time might not be set correctly right at the start. It looks like it’s set to epoch time minus 6 hours, likely because of your time zone I’d guess.

1 Like

@minWi Where would I set these? In the boot cmdline.txt file?
I’m guessing I’d need to remove them every time I did not want the file system check to run? OTOH, my boot volume is only 150MB, so perhaps it wouldn’t hurt to let it run every time…

This is my boot command, presently. Would I add it to this?

❯ cat /boot/cmdline.txt
root=LABEL=ROOT_MNJRO rw rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop usbhid.mousepoll=8 snd-bcm2835.enable_compat_alsa=0 audit=0 cgroup_enable=memory swapaccount=1

@Nachlese , thanks! I’ll study the man page to make sure I know how this works before I try it. How often would you recommend auto-checking an ext4 drive? It doesn’t get rebooted too often, unless I’m installing things.

I have it set at 10 - but that is totally arbitrary.
If the filesystem is clean, the test and check runs really fast - a few seconds
maybe two to three
on my spinning hdd of 1TB.
And even in case it wasn’t clean, the check and repair only takes marginally longer.
On SSD it’s likely hardly even noticeable.

man tune2fs

I also set/tune the reserved block percentage via the -m option.
On filesystem creation, this gets set to 5% - which is a huge waste of space on a large drive
since this is inaccessible to anyone but root - not ideal for a $HOME partition where practically nothing is owned by root.

I also made it redundant by making sure that a check and repair is run (forced) every time the filesystem is unclean for any reason - this works differently on ARM than it works on my laptop - the others here already covered it, probably.
I don’t have any experience with Pi or ARM devices in general - the configuration of that is different there.

In Megabytes:


In Blocks:

I haven’t looked at this since I set up timeshift to backup my system files. Why is my root partition using some timeshift related thing as the mount point?! I mean, I could google this, but I just saw it 5 seconds ago and now am mildly alarmed.)

The total size of my SSD is 500GB, for reference. I assumed it was showing as 465.4GB due to the usual file system/partition format overhead.


So, yeah, ~5 percent of my blocks are reserved.

Is a 500GB drive big enough to be worth adjusting this value? In 2021, “large drive” does not mean what it did when I was rocking an 88MB HDD back in 1992. :stuck_out_tongue:

It actually was less waste than it is now - and was a sensible amount.
~ 4 MB reserved for root

5% of 500 GB → 25 GB only accessible by root

ps:
can’t you copy/paste text - and mark it as preformatted text - when you post here
instead of posting pictures?
They look pretty and all - but are annoying to read …

Thanks.

Reserving 2 percent would put me at 10 GB. I’m guessing that’s still more than enough. I’m not entirely clear what this space is used for. I think it has something to do with the scenario where non-root users are not allowed to access the drive, but root users can still get at that reserved portion?

And yes, I will use the text paste from now on. I was having trouble getting it to format right at one point, so I got in the (bad) habit of posting screen captures.

EDIT: I have it set to 2 percent now. Painless. Thanks!

EDIT 2: So, following the directions at the ArchWiki for boot-time checking (fsck - ArchWiki) is a bit confusing. It doesn’t really cover FAT32 file systems.

Based this thread, I did this:

  1. Changed the boot command line in cmdline.txt: root=LABEL=ROOT_MNJRO rw rootwait console=ttyAMA0,115200 console=tty1 selinux=0 plymouth.enable=0 smsc95xx.turbo_mode=N dwc_otg.lpm_enable=0 kgdboc=ttyAMA0,115200 elevator=noop usbhid.mousepoll=8 snd-bcm2835.enable_compat_alsa=0 audit=0 cgroup_enable=memory swapaccount=1 fsck.mode=force fsck.repair=yes

  2. Set the pass field on the boot partition to 1 (it was 0). It is my understanding that the boot-time auto-checker will only auto-check partitions having a pass value greater than 0.

EDIT 3: The system came back up after doing this, so at minimum I guess I didn’t accidentally destroy the boot partition. Is there a way to tell when the FAT filesystem was last checked? I only know how to do this with ext4…

Am I missing anything?

It’s mostly used for system drives. Linux needs to create some files and have room to write to certain files on start, so this is a safeguard that a normal user can’t put the machine in a state where it no longer can operate normally basically, if I remember right.

1 Like

Thanks!

How will I know if I didn’t leave it enough space? It’s got ~10GB now.