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

Contents of /trunk/init.d/checkroot

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20