| 1 |
#!/sbin/runscript
|
| 2 |
# Copyright 1999-2005 Gentoo Foundation
|
| 3 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
|
| 5 |
depend() {
|
| 6 |
before *
|
| 7 |
}
|
| 8 |
|
| 9 |
start() {
|
| 10 |
local retval=0
|
| 11 |
|
| 12 |
if [[ ! -f /fastboot && -z ${CDBOOT} ]] && ! is_net_fs / ; then
|
| 13 |
if touch -c / >& /dev/null ; then
|
| 14 |
ebegin "Remounting root filesystem read-only"
|
| 15 |
mount -n -o remount,ro /
|
| 16 |
eend $?
|
| 17 |
fi
|
| 18 |
|
| 19 |
if [[ -f /forcefsck ]] || get_bootparam "forcefsck" ; then
|
| 20 |
ebegin "Checking root filesystem (full fsck forced)"
|
| 21 |
fsck -C -a -f /
|
| 22 |
# /forcefsck isn't deleted because checkfs needs it.
|
| 23 |
# it'll be deleted in that script.
|
| 24 |
retval=$?
|
| 25 |
else
|
| 26 |
# Obey the fs_passno setting for / (see fstab(5))
|
| 27 |
# - find the / entry
|
| 28 |
# - make sure we have 6 fields
|
| 29 |
# - see if fs_passno is something other than 0
|
| 30 |
if [[ -n $(awk '($1 ~ /^(\/|UUID|LABEL)/ && $2 == "/" \
|
| 31 |
&& NF == 6 && $6 != 0) { print }' /etc/fstab) ]]
|
| 32 |
then
|
| 33 |
ebegin "Checking root filesystem"
|
| 34 |
fsck -C -T -a /
|
| 35 |
retval=$?
|
| 36 |
else
|
| 37 |
ebegin "Skipping root filesystem check (fstab's passno == 0)"
|
| 38 |
retval=0
|
| 39 |
fi
|
| 40 |
fi
|
| 41 |
|
| 42 |
if [[ ${retval} -eq 0 ]] ; then
|
| 43 |
eend 0
|
| 44 |
elif [[ ${retval} -eq 1 ]] ; then
|
| 45 |
ewend 1 "Filesystem repaired"
|
| 46 |
elif [[ ${retval} -eq 2 || ${retval} -eq 3 ]] ; then
|
| 47 |
ewend 1 "Filesystem repaired, but reboot needed!"
|
| 48 |
echo -ne "\a"; sleep 1; echo -ne "\a"; sleep 1
|
| 49 |
echo -ne "\a"; sleep 1; echo -ne "\a"; sleep 1
|
| 50 |
ewarn "Rebooting in 10 seconds ..."
|
| 51 |
sleep 10
|
| 52 |
einfo "Rebooting"
|
| 53 |
/sbin/reboot -f
|
| 54 |
else
|
| 55 |
if [[ ${RC_FORCE_AUTO} == "yes" ]] ; then
|
| 56 |
eend 2 "Rerunning fsck in force mode"
|
| 57 |
fsck -y -C -T -a /
|
| 58 |
else
|
| 59 |
eend 2 "Filesystem couldn't be fixed :("
|
| 60 |
/sbin/sulogin ${CONSOLE}
|
| 61 |
fi
|
| 62 |
einfo "Unmounting filesystems"
|
| 63 |
/bin/mount -a -o remount,ro &> /dev/null
|
| 64 |
einfo "Rebooting"
|
| 65 |
/sbin/reboot -f
|
| 66 |
fi
|
| 67 |
fi
|
| 68 |
|
| 69 |
# Should we mount root rw ?
|
| 70 |
if mount -vf -o remount / 2> /dev/null | \
|
| 71 |
awk '{ if ($6 ~ /rw/) exit 0; else exit 1; }'
|
| 72 |
then
|
| 73 |
ebegin "Remounting root filesystem read/write"
|
| 74 |
mount -n -o remount,rw / &> /dev/null
|
| 75 |
if [[ $? -ne 0 ]] ; then
|
| 76 |
eend 2 "Root filesystem could not be mounted read/write :("
|
| 77 |
if [[ ${RC_FORCE_AUTO} != "yes" ]] ; then
|
| 78 |
/sbin/sulogin ${CONSOLE}
|
| 79 |
fi
|
| 80 |
else
|
| 81 |
eend 0
|
| 82 |
fi
|
| 83 |
fi
|
| 84 |
|
| 85 |
if [[ ${BOOT} == "yes" ]] ; then
|
| 86 |
local x=
|
| 87 |
local y=
|
| 88 |
|
| 89 |
#
|
| 90 |
# Create /etc/mtab
|
| 91 |
#
|
| 92 |
|
| 93 |
# Don't create mtab if /etc is readonly
|
| 94 |
if ! touch /etc/mtab 2> /dev/null ; then
|
| 95 |
ewarn "Skipping /etc/mtab initialization (ro root?)"
|
| 96 |
return 0
|
| 97 |
fi
|
| 98 |
|
| 99 |
# Clear the existing mtab
|
| 100 |
> /etc/mtab
|
| 101 |
|
| 102 |
# Add the entry for / to mtab
|
| 103 |
mount -f /
|
| 104 |
|
| 105 |
# Don't list root more than once
|
| 106 |
awk '$2 != "/" {print}' /proc/mounts >> /etc/mtab
|
| 107 |
|
| 108 |
# Now make sure /etc/mtab have additional info (gid, etc) in there
|
| 109 |
for x in $(awk '{ print $2 }' /proc/mounts | sort -u) ; do
|
| 110 |
for y in $(awk '{ print $2 }' /etc/fstab) ; do
|
| 111 |
if [[ ${x} == ${y} ]] ; then
|
| 112 |
mount -f -o remount $x
|
| 113 |
continue
|
| 114 |
fi
|
| 115 |
done
|
| 116 |
done
|
| 117 |
|
| 118 |
# Remove stale backups
|
| 119 |
rm -f /etc/mtab~ /etc/mtab~~
|
| 120 |
fi
|
| 121 |
}
|
| 122 |
|
| 123 |
|
| 124 |
# vim:ts=4
|