/[baselayout]/trunk/sbin/init.Linux.sh
Gentoo

Contents of /trunk/sbin/init.Linux.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2255 - (show annotations) (download) (as text)
Thu Sep 21 07:06:05 2006 UTC (7 years, 7 months ago) by vapier
File MIME type: text/x-sh
File size: 5744 byte(s)
Fix udev/devfs addon checks #147856.
1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # void single_user()
5 #
6 # Drop to a shell, remount / ro, and then reboot
7 #
8 single_user() {
9 if is_vps_sys ; then
10 einfo "Halting"
11 halt -f
12 return
13 fi
14
15 sulogin ${CONSOLE}
16 einfo "Unmounting filesystems"
17 if [[ -c /dev/null ]] ; then
18 mount -a -o remount,ro &>/dev/null
19 else
20 mount -a -o remount,ro
21 fi
22 einfo "Rebooting"
23 reboot -f
24 }
25
26 # This basically mounts $svcdir as a ramdisk, but preserving its content
27 # which allows us to run depscan.sh
28 # The tricky part is finding something our kernel supports
29 # tmpfs and ramfs are easy, so force one or the other
30 mount_svcdir() {
31 local filesystems=$(</proc/filesystems)$'\n'
32 local fs= devdir="none" devtmp="none" x=
33
34 if [[ ${filesystems} =~ "[[:space:]]tmpfs"$'\n' ]] ; then
35 fs="tmpfs"
36 elif [[ ${filesystems} =~ "[[:space:]]ramfs"$'\n' ]] ; then
37 fs="ramfs"
38 elif [[ -e /dev/ram0 && -e /dev/ram1 \
39 && ${filesystems} =~ "[[:space:]]ext2"$'\n' ]] ; then
40 devdir="/dev/ram0"
41 devtmp="/dev/ram1"
42 fs="ext2"
43 for x in ${devdir} ${devtmp} ; do
44 try dd if=/dev/zero of="${x}" bs=1k count="${svcsize}"
45 try mkfs -t "${fs}" -i 1024 -vm0 "${x}" "${svcsize}"
46 done
47 else
48 echo
49 eerror "Gentoo Linux requires tmpfs, ramfs or 2 ramdisks + ext2"
50 eerror "compiled into the kernel"
51 echo
52 single_user
53 fi
54
55 try mount -t "${fs}" "${devtmp}" "${svclib}"/tmp -o rw
56 try cp -apR "${svcdir}"/depcache "${svcdir}"/deptree "${svclib}"/tmp
57 try mount -t "${fs}" "${devdir}" "${svcdir}" -o rw
58 try cp -apR "${svclib}"/tmp/* "${svcdir}"
59 try umount "${svclib}"/tmp
60 }
61
62 source "${svclib}"/sh/init-functions.sh
63 source "${svclib}"/sh/init-common-pre.sh
64
65 echo
66 echo -e "${GOOD}Gentoo Linux${GENTOO_VERS}; ${BRACKET}http://www.gentoo.org/${NORMAL}"
67 echo -e " Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2"
68 echo
69 if [[ ${RC_INTERACTIVE} == "yes" ]] ; then
70 echo -e "Press ${GOOD}I${NORMAL} to enter interactive boot mode"
71 echo
72 fi
73 check_statedir /proc
74
75 ebegin "Mounting proc at /proc"
76 if [[ ${RC_USE_FSTAB} = "yes" ]] ; then
77 mntcmd=$(get_mount_fstab /proc)
78 else
79 unset mntcmd
80 fi
81 try mount -n ${mntcmd:--t proc proc /proc -o noexec,nosuid,nodev}
82 eend $?
83
84 # Start profiling init now we have /proc
85 profiling start
86
87 # Read off the kernel commandline to see if there's any special settings
88 # especially check to see if we need to set the CDBOOT environment variable
89 # Note: /proc MUST be mounted
90 [[ -f /sbin/livecd-functions.sh ]] && livecd_read_commandline
91
92 if [[ $(get_KV) -ge "$(KV_to_int '2.6.0')" ]] ; then
93 if [[ -d /sys ]] ; then
94 ebegin "Mounting sysfs at /sys"
95 if [[ ${RC_USE_FSTAB} == "yes" ]] ; then
96 mntcmd=$(get_mount_fstab /sys)
97 else
98 unset mntcmd
99 fi
100 try mount -n ${mntcmd:--t sysfs sysfs /sys -o noexec,nosuid,nodev}
101 eend $?
102 else
103 ewarn "No /sys to mount sysfs needed in 2.6 and later kernels!"
104 fi
105 fi
106
107 check_statedir /dev
108
109 devfs_automounted="no"
110 if [[ -e "/dev/.devfsd" ]] ; then
111 # make sure devfs is actually mounted and it isnt a bogus file
112 devfs_automounted=$(awk '($3 == "devfs") { print "yes"; exit 0 }' /proc/mounts)
113 fi
114
115 # Try to figure out how the user wants /dev handled
116 # - check $RC_DEVICES from /etc/conf.d/rc
117 # - check boot parameters
118 # - make sure the required binaries exist
119 # - make sure the kernel has support
120 if [[ ${RC_DEVICES} == "static" ]] ; then
121 ebegin "Using existing device nodes in /dev"
122 eend 0
123 else
124 fellback_to_devfs="no"
125 case ${RC_DEVICES} in
126 devfs) devfs="yes"
127 udev="no"
128 ;;
129 udev) devfs="yes"
130 udev="yes"
131 fellback_to_devfs="yes"
132 ;;
133 auto|*) devfs="yes"
134 udev="yes"
135 ;;
136 esac
137
138 # Check udev prerequisites and kernel params
139 if [[ ${udev} == "yes" ]] ; then
140 if get_bootparam "noudev" || ! has_addon udev-start.sh || \
141 [[ ${devfs_automounted} == "yes" || \
142 $(get_KV) -lt "$(KV_to_int '2.6.0')" ]] ; then
143 udev="no"
144 fi
145 fi
146
147 # Check devfs prerequisites and kernel params
148 if [[ ${devfs} == "yes" ]] ; then
149 if get_bootparam "nodevfs" || ! has_addon devfs-start.sh ||
150 [[ ${udev} == "yes" || ! -r /proc/filesystems ]] ; then
151 devfs="no"
152 elif [[ ! $(</proc/filesystems)$'\n' =~ '[[:space:]]devfs'$'\n' ]]; then
153 devfs="no"
154 fi
155 fi
156
157 # Actually start setting up /dev now
158 if [[ ${udev} == "yes" ]] ; then
159 start_addon udev
160
161 # With devfs, /dev can be mounted by the kernel ...
162 elif [[ ${devfs} == "yes" ]] ; then
163 start_addon devfs
164
165 # Did the user want udev in the config file but for
166 # some reason, udev support didnt work out ?
167 if [[ ${fellback_to_devfs} == "yes" ]] ; then
168 ewarn "You wanted udev but support for it was not available!"
169 ewarn "Please review your system after it's booted!"
170 fi
171 fi
172
173 # OK, if we got here, things are probably not right :)
174 if [[ ${devfs} == "no" && ${udev} == "no" ]] ; then
175 :
176 fi
177 fi
178
179 # From linux-2.5.68 we need to mount /dev/pts again ...
180 if [[ "$(get_KV)" -ge "$(KV_to_int '2.5.68')" ]] ; then
181 have_devpts=$(awk '($2 == "devpts") { print "yes"; exit 0 }' /proc/filesystems)
182
183 if [[ ${have_devpts} = "yes" ]] ; then
184 # Only try to create /dev/pts if we have /dev mounted dynamically,
185 # else it might fail as / might be still mounted readonly.
186 if [[ ! -d /dev/pts ]] && \
187 [[ ${devfs} == "yes" || ${udev} == "yes" ]] ; then
188 # Make sure we have /dev/pts
189 mkdir -p /dev/pts &>/dev/null || \
190 ewarn "Could not create /dev/pts!"
191 fi
192
193 if [[ -d /dev/pts ]] ; then
194 ebegin "Mounting devpts at /dev/pts"
195 if [[ ${RC_USE_FSTAB} == "yes" ]] ; then
196 mntcmd=$(get_mount_fstab /dev/pts)
197 else
198 unset mntcmd
199 fi
200 try mount -n ${mntcmd:--t devpts devpts /dev/pts -o gid=5,mode=0620,noexec,nosuid}
201 eend $?
202 fi
203 fi
204 fi
205
206 source "${svclib}"/sh/init-common-post.sh
207
208 # vim:ts=4

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20