Freebsd – Force fsck at boot time on the root file system (prior to mounting file systems, without Single-User mode)

freebsdfsck

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

Best Answer

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.

Related Question