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

Contents of /trunk/init.d/checkroot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2604 - (show annotations) (download)
Fri Apr 13 15:20:10 2007 UTC (6 years, 2 months ago) by uberlord
File size: 3655 byte(s)
hug getopt_long some more
1 #!/sbin/runscript
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 do_mtab() {
6 # Don't create mtab if /etc is readonly
7 if ! touch /etc/mtab 2> /dev/null ; then
8 ewarn "Skipping /etc/mtab initialization" "(ro root?)"
9 return 0
10 fi
11
12 # Clear the existing mtab
13 > /etc/mtab
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 start() {
35 local retval=0
36
37 # Don't bother doing a fsck on these
38 if [ -n "${CDBOOT}" ] || is_net_fs / || is_union_fs / ; then
39 return 0
40 fi
41
42 if touch /.test.$$ 2> /dev/null ; then
43 einfo "root filesystem is mounted read-write - skipping"
44 rm -f /.test.$$
45 return 0
46 fi
47
48 if get_bootparam "forcefsck" ; then
49 ebegin "Checking root filesystem (full fsck forced)"
50 if [ "${RC_UNAME}" = "Linux" ] ; then
51 fsck -C -a -f /
52 else
53 fsck -F /
54 fi
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 # - find the / entry
61 # - make sure we have 6 fields
62 # - see if fs_passno is something other than 0
63 local pass=$(fstabinfo --passno /)
64 if [ ${pass:-0} != "0" ] ; then
65 ebegin "Checking root filesystem"
66 if [ "${RC_UNAME}" = "Linux" ] ; then
67 fsck -C -T -a /
68 else
69 fsck -p -F /
70 fi
71 retval=$?
72 else
73 ebegin "Skipping root filesystem check" "(fstab's passno == 0)"
74 retval=0
75 fi
76 fi
77
78 if [ ${retval} -eq 0 ] ; then
79 eend 0
80 elif [ ${retval} -eq 1 ] ; then
81 ewend 1 "Filesystem repaired"
82 retval=0
83 elif [ ${retval} -eq 8 ] ; then
84 ewend 1 $"Operational error, continuing"
85 retval=0
86 elif [ ${retval} -eq 2 -o ${retval} -eq 3 ] ; then
87 ewend 1 "Filesystem repaired, but reboot needed!"
88 if [ "${RC_FORCE_AUTO}" != "yes" ] ; then
89 printf "\a"; sleep 1; printf "\a"; sleep 1
90 printf "\a"; sleep 1; printf "\a"; sleep 1
91 ewarn "Rebooting in 10 seconds ..."
92 sleep 10
93 fi
94 einfo "Rebooting"
95 /sbin/reboot -f
96 else
97 if [ "${RC_FORCE_AUTO}" = "yes" ] ; then
98 eend 2 "Rerunning fsck in force mode"
99 if [ "${RC_UNAME}" = "Linux" ] ; then
100 fsck -y -C -T /
101 else
102 fsck -y /
103 fi
104 retval=$?
105 else
106 eend 2 "Filesystem couldn't be fixed :("
107 [ "${RC_UNAME}" = "Linux" ] || return 1
108 sulogin "${CONSOLE}"
109 fi
110 if [ ${retval} != "0" ] ; then
111 einfo "Unmounting filesystems"
112 if [ "${RC_UNAME}" = "Linux" ] ; then
113 mount -a -o remount,ro /
114 else
115 mount -u -o ro /
116 fi
117 einfo "Rebooting"
118 reboot -f
119 fi
120 fi
121
122 ebegin "Remounting root filesystem read/write"
123 if [ "${RC_UNAME}" = "Linux" ] ; then
124 mount -n -o remount,rw /
125 else
126 mount -u -o rw /
127 fi
128 eend $? "Root filesystem could not be mounted read/write :(" || return 1
129
130 # Only Linux has mtab
131 [ "${RC_UNAME}" = "Linux" ] && do_mtab
132
133 # If the user's /dev/null or /dev/console are missing, we
134 # should help them out and explain how to rectify the situation
135 if [ ! -c /dev/null -o ! -c /dev/console ] ; then
136 if [ -e /usr/share/baselayout/issue.devfix ] ; then
137 # Backup current /etc/issue
138 if [ -e /etc/issue -a ! -e /etc/issue.devfix ] ; then
139 mv -f /etc/issue /etc/issue.devfix
140 fi
141 cp -f /usr/share/baselayout/issue.devfix /etc/issue
142 fi
143 fi
144
145 # We got here, so return 0
146 return 0
147 }
148
149 # vim: set ts=4 :

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20