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

Contents of /trunk/init.d/checkroot

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20