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?


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.

| improve this answer | |
  • 2
    For example with Grub: edit /etc/default/grub, then append fsck.mode=force to the value of GRUB_CMDLINE_LINUX_DEFAULT. Then run update-grub and reboot. – Yvan Sep 6 '16 at 8:38
  • 3
    doesn't work for xfs btw. but hey. this is the future. – Florian Heigl Oct 13 '16 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy