Raspberry Pi SD cards: fsck them often
Part of the Raspberry Pi Reliability series.
Here’s a (rare) quick entry in this series, with few if any caveats.
If your Raspberry Pi is not using a read-only filesystem, I recommend setting the Pi to run a filesystem check on its root filesystem at every boot.
This will (hopefully) help you catch a problem sooner rather than later, and the resulting recovery effort will potentially be easier. The only downside I see is that reboots take a bit longer.
First, find the name of the block device mounted to /
. In this example from a Raspberry Pi Zero W, it’s mmcblk0p2
; YMMV:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
mmcblk0 179:0 0 58.3G 0 disk
├─mmcblk0p1 179:1 0 256M 0 part /boot
└─mmcblk0p2 179:2 0 58G 0 part /
Then, tell the Pi it needs to check that filesystem every time it’s mounted:
sudo tune2fs -c 1 /dev/mmcblk0p2
The tune2fs
command works on ext2/ext3/ext4 filesystems. If you didn't set up your Pi using a non-default filesystem — you would know if you did! — don't worry about this. If your Pi is using an unusual filesystem, you'll have to figure this one out on your own.
All done!
To verify that this change was made, you can look at /etc/fstab
and verify the root filesytem has a 1
in its sizth column. For example, from the same device as before:
$ cat /etc/fstab
# <output snipped by cdzombak>
PARTUUID=48777bef-02 / ext4 defaults,noatime,commit=900 0 1