fsck is a system utility that performs a file system consistency check. In my experience, running fsck on the Raspberry Pi is rarely useful. However, if you've run into problems, and you don't have a backup of your filesystem, you have nothing to lose by trying; e.g. for an ext4 filesystem, run e2fck -p.
As a fine point, fsck simply calls e2fsck to do the real work - at least for ext4 filesystems. In current versions of the RPi OS, fsck serves as a "wrapper" or "front-end" to provide legacy support. Note that calling fsck will get the job done in most cases, but it may not be capable of passing all of the options you wish to use with e2fsck. Note also that fsck (and e2fsck) can not run on a mounted file system. There are options, but the most straightforward method for running fsck on a root filesystem (/) is to run it during the boot process - before the root filesystem is mounted. An alternative is to remove the SD card, insert it into a USB-microSD adapter, and plug the adapter & questionable SD card into another RPi/linux computer.
That said, and given that RPi OS uses systemd here's the recommended way to run fsck on every boot:
Recommended: Use your editor to add the following line to /boot/cmdline.txt or /boot/firmware/cmdline.txt:
fsck.mode=force
$ nano /boot/cmdline.txt
...
# FROM:
console=serial0,115200 console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
# TO:
console=serial0,115200 console=tty1 root=PARTUUID=6c586e13-02 rootfstype=ext4 elevator=deadline fsck.mode=force fsck.repair=yes rootwait
You can also use the legacy technique of creating a file named forcefsck in the root of the filesystem /; i.e. sudo touch forcefsck. However, this may be ill-advised:
-
the file
/forcefsckis removed before booting is completed - which means you'll need to automate adding it (e.g. acron @reboot job) following each reboot. -
a warning to use the method above (
fsck.mode=force) will be issued bysystemdtovar/log/syslog:
Please pass 'fsck.mode=force' on the kernel command line rather than creating /forcefsck on the root file system.
fsck results are logged to var/log/syslog by default. Following is one way to view the results:
$ less /var/log/syslog
This will load the log into the less pager. Once the logfile is loaded, search and highlight all instances of fsck by entering /fsck from within less. You may now scroll through the logfile, and your attention will be drawn to each highlighted entry for fsck. This has the advantage of seeing potentially relevant events which are not generated by fsck.
As an alternative to the above, if you strictly want to see log entries generated by fsck, journalctl is a friend:
$ journalctl -u systemd-fsck*