/[baselayout]/branches/rc-scripts-1_6/init.d/checkroot
Gentoo

Contents of /branches/rc-scripts-1_6/init.d/checkroot

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20