How to automatically force fsck disks after crash in `systemd`? - does not mean anything.

Setting fsck_y_enable="YES" and background_fsck="NO" in /etc/rc.conf don't do anything.

My root file system is not clean and has a lot of errors (due to a power outage - unexpected shutdown, not because hard drive or hardware are bad).

fsck shows errors:

root@host2:/usr/home/alex # fsck
** /dev/mirror/gm0p2 (NO WRITE)
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=8268305  OWNER=root MODE=140777
SIZE=0 MTIME=Jun  6 21:58 2014

[skipped 100+ lines]

I don't have physical or KVM access to the server. This is gmirrored drive

FreeBSD host2.domain.tld 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013 root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

# Device                Mountpoint      FStype  Options Dump    Pass#
/dev/mirror/gm0p2       /               ufs     rw      1       1
/dev/mirror/gm0p3       none            swap    sw      0       0
  • Hm, what is your fstab? I heard creating a (presumably blank) forcefsck file in / (root) might work. Might give it a try. – Seth Jun 7 '14 at 4:37
  • 1
    touch /forcefsck didn't do it. – Alex G Jun 7 '14 at 17:35
  • Are you using "initramfs" ? – SHW Mar 21 '16 at 6:43

FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /), do fsck manually (fsck -y /) and then reboot the machine.


If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early

something like fsck -fy / added to that file will force it to do a scan and answer 'yes' to all prompts.

Do not forget to remove it from rc.early when you are done, else it will run on every startup

  • 1
    Support for /etc/rc.early is now deprecated – Alex G Jun 15 '14 at 21:08

As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root to run /sbin/fsck -fy /.

Here is the current script, modified to include that command commented out; uncomment to perform the fsck.

# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $

# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail

. /etc/rc.subr


    # root normally must be read/write, but if this is a BOOTP NFS
    # diskless boot it does not have to be.
    case ${root_rw_mount} in
    [Nn][Oo] | '')

       # Uncomment the below line to run fsck on root during boot:
       #/sbin/fsck -fy /

        if ! mount -uw /; then
            echo 'Mounting root filesystem rw failed, startup aborted'
            stop_boot true

    umount -a >/dev/null 2>&1

    # If we booted a special kernel remove the record
    # so we will boot the default kernel next time.
    if [ -x /sbin/nextboot ]; then
        /sbin/nextboot -D > /dev/null 2>&1

load_rc_config $name
run_rc_command "$1"
  • That's a little hacky, but working. But it should be /sbin/fsck -fy / – Jimmy Koerting Sep 27 '17 at 15:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.