8

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
CLEAR? no

[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 [email protected]:/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
3
  • Hm, what is your fstab? I heard creating a (presumably blank) forcefsck file in / (root) might work. Might give it a try.
    – Seth
    Commented Jun 7, 2014 at 4:37
  • 1
    touch /forcefsck didn't do it.
    – Alex G
    Commented Jun 7, 2014 at 17:35
  • Are you using "initramfs" ?
    – SHW
    Commented Mar 21, 2016 at 6:43

4 Answers 4

3

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.

1

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
  • 1
    Support for /etc/rc.early is now deprecated
    – Alex G
    Commented Jun 15, 2014 at 21:08
1

/etc/rc.initial.reboot uses the nextboot command to reboot an run fsck 5 times:

/sbin/nextboot -e "pfsense.fsck.force=5"

You can run this manually or add it to any script to trigger fsck the next time it boots.

I tested this in version 2.5.0.

0

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.

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

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

. /etc/rc.subr

name="root"
start_cmd="root_start"
stop_cmd=":"

root_start()
{
    # 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
        fi
        ;;
    esac

    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
    fi
}

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .