2013-12-21 14:51:11 -06:00
|
|
|
#!@SBINDIR@/openrc-run
|
2009-05-01 15:11:40 +01:00
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2011-06-29 19:46:31 -04:00
|
|
|
# Released under the 2-clause BSD license.
|
2008-01-31 16:10:18 +00:00
|
|
|
|
|
|
|
description="Check and repair filesystems according to /etc/fstab"
|
2008-05-25 22:30:31 +00:00
|
|
|
_IFS="
|
2008-02-20 00:33:38 +00:00
|
|
|
"
|
2008-01-31 16:10:18 +00:00
|
|
|
|
|
|
|
depend()
|
|
|
|
{
|
2008-10-10 08:37:21 +00:00
|
|
|
use dev clock modules
|
2013-08-16 09:47:09 +04:00
|
|
|
keyword -jail -openvz -prefix -timeout -vserver -lxc -uml
|
2008-01-31 16:10:18 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 18:43:47 +00:00
|
|
|
_abort() {
|
2008-02-28 21:14:59 +00:00
|
|
|
rc-abort
|
|
|
|
return 1
|
2008-02-28 18:43:47 +00:00
|
|
|
}
|
|
|
|
|
2008-02-28 19:13:36 +00:00
|
|
|
# We should only reboot when first booting
|
|
|
|
_reboot() {
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ "$RC_RUNLEVEL" = "$RC_BOOTLEVEL" ]; then
|
2008-02-28 21:14:59 +00:00
|
|
|
reboot "$@"
|
|
|
|
_abort || return 1
|
2008-02-28 19:13:36 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-12-28 15:25:40 +00:00
|
|
|
_forcefsck()
|
|
|
|
{
|
|
|
|
[ -e /forcefsck ] || get_bootparam forcefsck
|
|
|
|
}
|
|
|
|
|
2008-01-31 16:10:18 +00:00
|
|
|
start()
|
|
|
|
{
|
2008-11-04 07:45:05 +00:00
|
|
|
local fsck_opts= p= check_extra=
|
2008-02-20 00:33:38 +00:00
|
|
|
|
2008-04-09 00:21:49 +00:00
|
|
|
if [ -e /fastboot ]; then
|
|
|
|
ewarn "Skipping fsck due to /fastboot"
|
|
|
|
return 0
|
|
|
|
fi
|
2008-12-28 15:25:40 +00:00
|
|
|
if _forcefsck; then
|
2009-04-27 07:51:18 +00:00
|
|
|
fsck_opts="$fsck_opts -f"
|
2008-04-17 00:09:34 +00:00
|
|
|
check_extra="(check forced)"
|
2009-12-10 22:30:56 +00:00
|
|
|
elif ! yesno ${fsck_on_battery:-YES} && ! on_ac_power; then
|
2009-05-29 21:06:59 +01:00
|
|
|
ewarn "Skipping fsck due to not being on AC power"
|
|
|
|
return 0
|
2008-04-17 00:09:34 +00:00
|
|
|
fi
|
2008-04-09 00:21:49 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -n "$fsck_passno" ]; then
|
|
|
|
check_extra="[passno $fsck_passno] $check_extra"
|
2011-11-26 03:21:21 -05:00
|
|
|
if [ -n "$fsck_mnt" ]; then
|
2011-11-22 12:56:29 -06:00
|
|
|
eerror "Only 1 of fsck_passno and fsck_mnt must be set!"
|
|
|
|
return 1
|
|
|
|
fi
|
2008-04-22 13:46:53 +00:00
|
|
|
fi
|
2009-04-27 07:51:18 +00:00
|
|
|
ebegin "Checking local filesystems $check_extra"
|
2011-11-22 12:56:29 -06:00
|
|
|
# Append passno mounts
|
2009-04-27 07:51:18 +00:00
|
|
|
for p in $fsck_passno; do
|
|
|
|
local IFS="$_IFS"
|
|
|
|
case "$p" in
|
|
|
|
[0-9]*) p="=$p";;
|
2008-02-20 00:33:38 +00:00
|
|
|
esac
|
2009-04-27 07:51:18 +00:00
|
|
|
set -- "$@" $(fstabinfo --passno "$p")
|
2008-02-20 00:33:38 +00:00
|
|
|
unset IFS
|
|
|
|
done
|
2011-11-22 12:56:29 -06:00
|
|
|
# Append custom mounts
|
|
|
|
for m in $fsck_mnt ; do
|
|
|
|
local IFS="$_IFS"
|
|
|
|
set -- "$@" "$m"
|
|
|
|
unset IFS
|
|
|
|
done
|
2008-02-01 10:48:21 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ "$RC_UNAME" = Linux ]; then
|
2012-05-16 23:46:21 -04:00
|
|
|
local skiptypes
|
|
|
|
skiptypes=$(printf 'no%s,' ${net_fs_list} ${extra_net_fs_list})
|
|
|
|
[ "${skiptypes}" = "no," ] && skiptypes=""
|
|
|
|
fsck_opts="$fsck_opts -C0 -T -t ${skiptypes}noopts=_netdev"
|
2011-11-22 12:56:29 -06:00
|
|
|
if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then
|
2013-04-27 10:26:37 -05:00
|
|
|
fsck_args=${fsck_args:--A -p}
|
2008-02-20 00:33:38 +00:00
|
|
|
if echo 2>/dev/null >/.test.$$; then
|
|
|
|
rm -f /.test.$$
|
2009-04-27 07:51:18 +00:00
|
|
|
fsck_opts="$fsck_opts -R"
|
2008-02-20 00:33:38 +00:00
|
|
|
fi
|
2008-01-31 16:10:18 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-05-27 10:25:29 +00:00
|
|
|
trap : INT QUIT
|
2013-04-27 10:26:37 -05:00
|
|
|
fsck ${fsck_args:--p} $fsck_opts "$@"
|
2008-01-31 16:10:18 +00:00
|
|
|
case $? in
|
2008-11-04 07:45:05 +00:00
|
|
|
0) eend 0; return 0;;
|
|
|
|
1) ewend 1 "Filesystems repaired"; return 0;;
|
2009-04-27 07:51:18 +00:00
|
|
|
2|3) if [ "$RC_UNAME" = Linux ]; then
|
2008-11-04 07:45:05 +00:00
|
|
|
ewend 1 "Filesystems repaired, but reboot needed"
|
|
|
|
_reboot -f
|
|
|
|
else
|
2009-03-16 21:41:23 +00:00
|
|
|
ewend 1 "Filesystems still have errors;" \
|
|
|
|
"manual fsck required"
|
|
|
|
_abort
|
2008-11-04 07:45:05 +00:00
|
|
|
fi;;
|
2009-04-27 07:51:18 +00:00
|
|
|
4) if [ "$RC_UNAME" = Linux ]; then
|
2009-03-16 21:41:23 +00:00
|
|
|
ewend 1 "Fileystem errors left uncorrected, aborting"
|
|
|
|
_abort
|
2008-11-04 07:45:05 +00:00
|
|
|
else
|
|
|
|
ewend 1 "Filesystems repaired, but reboot needed"
|
|
|
|
_reboot
|
|
|
|
fi;;
|
|
|
|
8) ewend 1 "Operational error"; return 0;;
|
2011-10-16 19:02:21 -04:00
|
|
|
12) ewend 1 "fsck interrupted";;
|
2008-11-04 07:45:05 +00:00
|
|
|
*) eend 2 "Filesystems couldn't be fixed";;
|
2008-01-31 16:10:18 +00:00
|
|
|
esac
|
2008-11-04 07:45:05 +00:00
|
|
|
_abort || return 1
|
2008-01-31 16:10:18 +00:00
|
|
|
}
|
2008-01-31 17:12:54 +00:00
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
2008-02-28 19:13:36 +00:00
|
|
|
# Fake function so we always shutdown correctly.
|
|
|
|
_abort() { return 0; }
|
|
|
|
_reboot() { return 0; }
|
2008-12-29 23:06:22 +00:00
|
|
|
_forcefsck() { return 1; }
|
2008-12-28 14:49:07 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
yesno $fsck_shutdown && start
|
2008-01-31 17:12:54 +00:00
|
|
|
return 0
|
|
|
|
}
|