2013-12-22 02:21:11 +05:30
|
|
|
#!@SBINDIR@/openrc-run
|
2015-12-05 04:22:19 +05:30
|
|
|
# Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
|
|
|
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
|
|
|
#
|
|
|
|
# This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
# the LICENSE file found in the top-level directory of this
|
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
2008-01-31 21:40:18 +05:30
|
|
|
|
|
|
|
description="Check and repair filesystems according to /etc/fstab"
|
2008-05-26 04:00:31 +05:30
|
|
|
_IFS="
|
2008-02-20 06:03:38 +05:30
|
|
|
"
|
2008-01-31 21:40:18 +05:30
|
|
|
|
|
|
|
depend()
|
|
|
|
{
|
2017-03-16 20:46:39 +05:30
|
|
|
after clock
|
2008-10-10 14:07:21 +05:30
|
|
|
use dev clock modules
|
2016-07-31 23:31:17 +05:30
|
|
|
keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -timeout -vserver -uml
|
2008-01-31 21:40:18 +05:30
|
|
|
}
|
|
|
|
|
2008-02-29 00:13:47 +05:30
|
|
|
_abort() {
|
2015-10-25 04:25:59 +05:30
|
|
|
yesno ${fsck_abort_on_errors:-yes} && rc-abort
|
2008-02-29 02:44:59 +05:30
|
|
|
return 1
|
2008-02-29 00:13:47 +05:30
|
|
|
}
|
|
|
|
|
2008-02-29 00:43:36 +05:30
|
|
|
# We should only reboot when first booting
|
|
|
|
_reboot() {
|
2009-04-27 13:21:18 +05:30
|
|
|
if [ "$RC_RUNLEVEL" = "$RC_BOOTLEVEL" ]; then
|
2008-02-29 02:44:59 +05:30
|
|
|
reboot "$@"
|
|
|
|
_abort || return 1
|
2008-02-29 00:43:36 +05:30
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-12-28 20:55:40 +05:30
|
|
|
_forcefsck()
|
|
|
|
{
|
|
|
|
[ -e /forcefsck ] || get_bootparam forcefsck
|
|
|
|
}
|
|
|
|
|
2008-01-31 21:40:18 +05:30
|
|
|
start()
|
|
|
|
{
|
2008-11-04 13:15:05 +05:30
|
|
|
local fsck_opts= p= check_extra=
|
2008-02-20 06:03:38 +05:30
|
|
|
|
2008-04-09 05:51:49 +05:30
|
|
|
if [ -e /fastboot ]; then
|
|
|
|
ewarn "Skipping fsck due to /fastboot"
|
|
|
|
return 0
|
|
|
|
fi
|
2008-12-28 20:55:40 +05:30
|
|
|
if _forcefsck; then
|
2009-04-27 13:21:18 +05:30
|
|
|
fsck_opts="$fsck_opts -f"
|
2008-04-17 05:39:34 +05:30
|
|
|
check_extra="(check forced)"
|
2009-12-11 04:00:56 +05:30
|
|
|
elif ! yesno ${fsck_on_battery:-YES} && ! on_ac_power; then
|
2009-05-30 01:36:59 +05:30
|
|
|
ewarn "Skipping fsck due to not being on AC power"
|
|
|
|
return 0
|
2008-04-17 05:39:34 +05:30
|
|
|
fi
|
2008-04-09 05:51:49 +05:30
|
|
|
|
2009-04-27 13:21:18 +05:30
|
|
|
if [ -n "$fsck_passno" ]; then
|
|
|
|
check_extra="[passno $fsck_passno] $check_extra"
|
2011-11-26 13:51:21 +05:30
|
|
|
if [ -n "$fsck_mnt" ]; then
|
2011-11-23 00:26:29 +05:30
|
|
|
eerror "Only 1 of fsck_passno and fsck_mnt must be set!"
|
|
|
|
return 1
|
|
|
|
fi
|
2008-04-22 19:16:53 +05:30
|
|
|
fi
|
2009-04-27 13:21:18 +05:30
|
|
|
ebegin "Checking local filesystems $check_extra"
|
2011-11-23 00:26:29 +05:30
|
|
|
# Append passno mounts
|
2009-04-27 13:21:18 +05:30
|
|
|
for p in $fsck_passno; do
|
|
|
|
local IFS="$_IFS"
|
|
|
|
case "$p" in
|
|
|
|
[0-9]*) p="=$p";;
|
2008-02-20 06:03:38 +05:30
|
|
|
esac
|
2009-04-27 13:21:18 +05:30
|
|
|
set -- "$@" $(fstabinfo --passno "$p")
|
2008-02-20 06:03:38 +05:30
|
|
|
unset IFS
|
|
|
|
done
|
2011-11-23 00:26:29 +05:30
|
|
|
# Append custom mounts
|
|
|
|
for m in $fsck_mnt ; do
|
|
|
|
local IFS="$_IFS"
|
|
|
|
set -- "$@" "$m"
|
|
|
|
unset IFS
|
|
|
|
done
|
2008-02-01 16:18:21 +05:30
|
|
|
|
2009-04-27 13:21:18 +05:30
|
|
|
if [ "$RC_UNAME" = Linux ]; then
|
2012-05-17 09:16:21 +05:30
|
|
|
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-23 00:26:29 +05:30
|
|
|
if [ -z "$fsck_passno" -a -z "$fsck_mnt" ]; then
|
2013-04-27 20:56:37 +05:30
|
|
|
fsck_args=${fsck_args:--A -p}
|
2008-02-20 06:03:38 +05:30
|
|
|
if echo 2>/dev/null >/.test.$$; then
|
|
|
|
rm -f /.test.$$
|
2009-04-27 13:21:18 +05:30
|
|
|
fsck_opts="$fsck_opts -R"
|
2008-02-20 06:03:38 +05:30
|
|
|
fi
|
2008-01-31 21:40:18 +05:30
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2008-05-27 15:55:29 +05:30
|
|
|
trap : INT QUIT
|
2013-04-27 20:56:37 +05:30
|
|
|
fsck ${fsck_args:--p} $fsck_opts "$@"
|
2008-01-31 21:40:18 +05:30
|
|
|
case $? in
|
2008-11-04 13:15:05 +05:30
|
|
|
0) eend 0; return 0;;
|
|
|
|
1) ewend 1 "Filesystems repaired"; return 0;;
|
2009-04-27 13:21:18 +05:30
|
|
|
2|3) if [ "$RC_UNAME" = Linux ]; then
|
2008-11-04 13:15:05 +05:30
|
|
|
ewend 1 "Filesystems repaired, but reboot needed"
|
|
|
|
_reboot -f
|
|
|
|
else
|
2009-03-17 03:11:23 +05:30
|
|
|
ewend 1 "Filesystems still have errors;" \
|
|
|
|
"manual fsck required"
|
|
|
|
_abort
|
2008-11-04 13:15:05 +05:30
|
|
|
fi;;
|
2009-04-27 13:21:18 +05:30
|
|
|
4) if [ "$RC_UNAME" = Linux ]; then
|
2009-03-17 03:11:23 +05:30
|
|
|
ewend 1 "Fileystem errors left uncorrected, aborting"
|
|
|
|
_abort
|
2008-11-04 13:15:05 +05:30
|
|
|
else
|
|
|
|
ewend 1 "Filesystems repaired, but reboot needed"
|
|
|
|
_reboot
|
|
|
|
fi;;
|
|
|
|
8) ewend 1 "Operational error"; return 0;;
|
2011-10-17 04:32:21 +05:30
|
|
|
12) ewend 1 "fsck interrupted";;
|
2008-11-04 13:15:05 +05:30
|
|
|
*) eend 2 "Filesystems couldn't be fixed";;
|
2008-01-31 21:40:18 +05:30
|
|
|
esac
|
2008-11-04 13:15:05 +05:30
|
|
|
_abort || return 1
|
2008-01-31 21:40:18 +05:30
|
|
|
}
|
2008-01-31 22:42:54 +05:30
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
2008-02-29 00:43:36 +05:30
|
|
|
# Fake function so we always shutdown correctly.
|
|
|
|
_abort() { return 0; }
|
|
|
|
_reboot() { return 0; }
|
2008-12-30 04:36:22 +05:30
|
|
|
_forcefsck() { return 1; }
|
2008-12-28 20:19:07 +05:30
|
|
|
|
2009-04-27 13:21:18 +05:30
|
|
|
yesno $fsck_shutdown && start
|
2008-01-31 22:42:54 +05:30
|
|
|
return 0
|
|
|
|
}
|