systemd fsck – How to Automatically Force Disk Check After Crash

fscksystemd

How to set systemd for automatically force fsck disks after crash (hard poweroff)?

When I used sysvinit (in Arch Linux) as /sbin/init I used the hack: in the rc.local I create /forcefsck file; in the rc.local.shutdown I remove it. At boot-up rc.sysinit enable force fsck if /forcefsck exists.

How to do same in systemd? Maybe it has built-in facilities for automatic fsck after crush?

Best Answer

You can force fsck at boot time by passing fsck.mode=force (auto is default and skip can be used to skip checking at all) as a kernel command line parameter (as of systemd v. 213, there's also a second parameter: fsck.repair - to control how fsck shall deal with unclean file systems at boot; possible values are: preen to fix what can be safely fixed, yes to answer yes to all questions and no is default).


Note that systemd-fsck does not know any details about specific filesystems, and simply executes file system checkers specific to each filesystem type (/sbin/fsck.*).
Now, if your filesystem is xfs or btrfs it will execute /sbin/fsck.xfs or /sbin/fsck.btrfs respectively. If that does not seem to work maybe you should check the manual page for fsck.xfs or fsck.btrfs respectively and examine the contents of the said files in /sbin.

Related Question