openrc/init.d/fsck.in
Roy Marples d6da8e8c48 sysinit is now a real runlevel that handles things like udev, dmesg and
mounting various bits in /dev and /sys.
init.sh JUST mounts /lib/rc/init.d (and /proc for Linux systems)
To make development of this easier we now return an empty RC_STRINGLIST
instead of a NULL for empty things.

If you don't have a udev init script installed, don't reboot your box OR
roll back to an older OpenRC version.
2008-10-10 08:37:21 +00:00

89 lines
1.9 KiB
Plaintext

#!@PREFIX@/sbin/runscript
# Copyright 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
description="Check and repair filesystems according to /etc/fstab"
_IFS="
"
depend()
{
use dev clock modules
keyword nojail noopenvz noprefix notimeout novserver
}
_abort() {
rc-abort
return 1
}
# We should only reboot when first booting
_reboot() {
if [ "${RC_RUNLEVEL}" = "${RC_BOOTLEVEL}" ]; then
reboot "$@"
_abort || return 1
fi
}
start()
{
local reboot_opts= fsck_opts= p= check_extra=
if [ -e /fastboot ]; then
ewarn "Skipping fsck due to /fastboot"
return 0
fi
if [ -e /forcefsck ] || get_bootparam forcefsck; then
fsck_opts="${fsck_opts} -f"
check_extra="(check forced)"
fi
if [ -n "${fsck_passno}" ]; then
check_extra="[passno ${fsck_passno}] ${check_extra}"
fi
ebegin "Checking local filesystems ${check_extra}"
for p in ${fsck_passno}; do
local IFS="${_IFS}"
case "${p}" in
[0-9]*) p="=${p}";;
esac
set -- "$@" $(fstabinfo --passno "${p}")
unset IFS
done
if [ "${RC_UNAME}" = "Linux" ]; then
fsck_opts="${fsck_opts} -C0 -T"
if [ -z "${fsck_passno}" ]; then
fsck_args=${fsck_args--A -p}
if echo 2>/dev/null >/.test.$$; then
rm -f /.test.$$
fsck_opts="${fsck_opts} -R"
fi
fi
reboot_opts="-f"
fi
trap : INT QUIT
fsck ${fsck_args--p} ${fsck_opts} "$@"
case $? in
0) eend 0; return 0;;
1) ewend 1 "Filesystems repaired"; return 0;;
2|3|4) ewend 1 "Filesystems repaired, but reboot needed"
_reboot ${reboot_opts} || return 1;;
8) ewend 1 "Operational error"; return 0;;
12) ewend 1 "fsck interupted"; return 1;;
*) eend 2 "Filesystems couldn't be fixed"
_abort || return 1;;
esac
}
stop()
{
# Fake function so we always shutdown correctly.
_abort() { return 0; }
_reboot() { return 0; }
yesno "${fsck_shutdown}" && start
return 0
}