Skip to content

Latest commit

 

History

History
50 lines (29 loc) · 2.75 KB

fsckForRaspberryPi.md

File metadata and controls

50 lines (29 loc) · 2.75 KB

Running fsck on the Raspberry Pi

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 don't have a backup of your filesystem, you have nothing to lose by trying.

As a fine point, fsck simply calls e2fsck to do the real work. 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.

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:

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

Not recommended: Another method to run fsck at boot:

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 /forcefsck is removed before booting is completed - which means you'll need to automate adding it (e.g. a cron @reboot job) following each reboot.

  • a warning to use the method above (fsck.mode=force) will be issued by systemd to var/log/syslog:

Please pass 'fsck.mode=force' on the kernel command line rather than creating /forcefsck on the root file system.

Logging fsck results:

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*