/[baselayout]/trunk/init.d/checkroot
Gentoo

Contents of /trunk/init.d/checkroot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2775 - (show annotations) (download)
Fri Jul 13 00:04:20 2007 UTC (7 years ago) by uberlord
File size: 3468 byte(s)
Use echo instead of touch - saves on forking
1 #!/sbin/runscript
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 description="Check the root filesystem according to /etc/fstab for errors \
6 and optionally repair them."
7
8 do_mtab() {
9 # Don't create mtab if /etc is readonly
10 if ! echo 2>/dev/null >/etc/mtab ; then
11 ewarn "Skipping /etc/mtab initialization" "(ro root?)"
12 return 0
13 fi
14
15 # Add the entry for / to mtab
16 mount -f /
17
18 # Don't list root more than once
19 grep -v "^[^ ]* / " /proc/mounts >> /etc/mtab
20
21 # Now make sure /etc/mtab have additional info (gid, etc) in there
22 local mnt= mnts="$(mountinfo | sed -e "s/^/'/g" -e "s/$/'/g")"
23 eval set -- ${mnts}
24 for mnt in "$@" ; do
25 if fstabinfo --mountcmd "${mnt}" >/dev/null ; then
26 mount -f -o remount "${mnt}"
27 fi
28 done
29
30 # Remove stale backups
31 rm -f /etc/mtab~ /etc/mtab~~
32 }
33
34 do_fsck() {
35 local retval=0 opts="-F"
36 [ "${RC_UNAME}" = "Linux" ] && opts="-T -C0"
37
38 # Don't bother doing a fsck on these
39 if [ -n "${CDBOOT}" ] || is_net_fs / || is_union_fs / ; then
40 return 0
41 fi
42
43 if echo 2>/dev/null >/.test.$$ ; then
44 einfo "root filesystem is mounted read-write - skipping"
45 rm -f /.test.$$
46 return 0
47 fi
48
49 if [ -e /forcefsck ] || get_bootparam "forcefsck" ; then
50 ebegin "Checking root filesystem (full fsck forced)"
51 fsck ${opts} -f -n /
52 # /forcefsck isn't deleted because checkfs needs it.
53 # it'll be deleted in that script.
54 retval=$?
55 else
56 # Obey the fs_passno setting for / (see fstab(5))
57 local pass=$(fstabinfo --passno /)
58 if [ ${pass:-0} != "0" ] ; then
59 ebegin "Checking root filesystem"
60 fsck ${opts} -p /
61 retval=$?
62 else
63 ebegin "Skipping root filesystem check" "(fstab's passno == 0)"
64 retval=0
65 fi
66 fi
67
68 if [ ${retval} -eq 0 ] ; then
69 eend 0
70 elif [ ${retval} -eq 1 ] ; then
71 ewend 1 "Filesystem repaired"
72 retval=0
73 elif [ ${retval} -eq 8 ] ; then
74 ewend 1 $"Operational error, continuing"
75 retval=0
76 elif [ ${retval} -eq 2 -o ${retval} -eq 3 ] ; then
77 ewend 1 "Filesystem repaired, but reboot needed!"
78 if [ "${RC_FORCE_AUTO}" != "yes" ] ; then
79 printf "\a"; sleep 1; printf "\a"; sleep 1
80 printf "\a"; sleep 1; printf "\a"; sleep 1
81 ewarn "Rebooting in 10 seconds ..."
82 sleep 10
83 fi
84 einfo "Rebooting"
85 reboot -f
86 else
87 if [ "${RC_FORCE_AUTO}" = "yes" ] ; then
88 eend 2 "Rerunning fsck in force mode"
89 fsck ${opts} -y /
90 retval=$?
91 else
92 eend 2 "Filesystem couldn't be fixed :("
93 exec rc-abort || exit 1
94 fi
95 if [ ${retval} != "0" ] ; then
96 einfo "Unmounting filesystems"
97 if [ "${RC_UNAME}" = "Linux" ] ; then
98 mount -a -o remount,ro /
99 else
100 mount -u -o ro /
101 fi
102 einfo "Rebooting"
103 reboot -f
104 fi
105 fi
106
107 ebegin "Remounting root filesystem read/write"
108 if [ "${RC_UNAME}" = "Linux" ] ; then
109 mount -n -o remount,rw /
110 else
111 mount -u -o rw /
112 fi
113 eend $? "Root filesystem could not be mounted read/write :("
114 }
115
116 start() {
117 do_fsck || return 1
118
119 # Only Linux has mtab
120 [ "${RC_UNAME}" = "Linux" ] && do_mtab
121
122 # If the user's /dev/null or /dev/console are missing, we
123 # should help them out and explain how to rectify the situation
124 if [ ! -c /dev/null -o ! -c /dev/console ] ; then
125 if [ -e /usr/share/baselayout/issue.devfix ] ; then
126 # Backup current /etc/issue
127 if [ -e /etc/issue -a ! -e /etc/issue.devfix ] ; then
128 mv -f /etc/issue /etc/issue.devfix
129 fi
130 cp -f /usr/share/baselayout/issue.devfix /etc/issue
131 fi
132 fi
133
134 # We got here, so return 0
135 return 0
136 }
137
138 # vim: set ts=4 :

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20