]>
Commit | Line | Data |
---|---|---|
7f64a3fe | 1 | #!/bin/sh |
a5e56335 JK |
2 | # |
3 | # Licensed under the GPLv2 | |
4 | # | |
5 | # Copyright 2008, Red Hat, Inc. | |
6 | # Jeremy Katz <katzj@redhat.com> | |
ec9315e5 JK |
7 | |
8 | emergency_shell() | |
9 | { | |
83701d66 | 10 | exec >/dev/console 2>&1 </dev/console |
a3a3448d HH |
11 | echo ; echo |
12 | echo $@ | |
0fd1ab9d | 13 | source_all emergency |
dacba778 | 14 | if getarg rdshell || getarg rdbreak; then |
a3a3448d | 15 | echo ; echo |
c3cd4c76 | 16 | echo "Boot has failed, dropping to debug shell." |
a3a3448d HH |
17 | echo |
18 | sh -i | |
19 | else | |
c3cd4c76 | 20 | echo "Boot has failed, sleeping forever." |
a3a3448d HH |
21 | while :; do sleep 1;done |
22 | fi | |
ec9315e5 | 23 | } |
ec9315e5 | 24 | |
ec9315e5 JK |
25 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin |
26 | export TERM=linux | |
bb040f93 HH |
27 | NEWROOT="/sysroot" |
28 | ||
a75c29be | 29 | trap "emergency_shell Signal caught!" 0 |
a890fe29 | 30 | |
b8f39ef1 | 31 | . /lib/dracut-lib.sh |
df44688f | 32 | |
a890fe29 HH |
33 | mknod /dev/null c 1 3 |
34 | ||
ec9315e5 | 35 | # mount some important things |
a890fe29 HH |
36 | mount -t proc /proc /proc >/dev/null 2>&1 |
37 | mount -t sysfs /sys /sys >/dev/null 2>&1 | |
a890fe29 | 38 | |
3473f5d9 | 39 | if [ ! -c /dev/ptmx ]; then |
e0364f95 HH |
40 | # try to mount devtmpfs |
41 | if ! mount -t devtmpfs -omode=0755 udev /dev >/dev/null 2>&1; then | |
42 | # if it failed fall back to normal tmpfs | |
3473f5d9 HH |
43 | mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1 |
44 | # Make some basic devices first, let udev handle the rest | |
45 | mknod /dev/null c 1 3 | |
46 | mknod /dev/ptmx c 5 2 | |
47 | mknod /dev/console c 5 1 | |
48 | mknod /dev/kmsg c 1 11 | |
49 | fi | |
50 | fi | |
d0e2110a | 51 | |
83701d66 HH |
52 | if getarg rdinitdebug; then |
53 | set -x | |
83701d66 HH |
54 | fi |
55 | ||
d0e2110a | 56 | mkdir /dev/shm |
0c70846e | 57 | mkdir /dev/pts |
a890fe29 | 58 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1 |
0c70846e | 59 | |
eab677a2 HH |
60 | UDEVVERSION=$(udevadm --version) |
61 | ||
e4502814 | 62 | # run scriptlets to parse the command line |
a3a3448d | 63 | getarg 'rdbreak=cmdline' && emergency_shell "Break before cmdline" |
e4502814 DD |
64 | source_all cmdline |
65 | ||
0fd1ab9d PS |
66 | [ -z "$root" ] && die "No or empty root= argument" |
67 | [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'" | |
d15c7a1a | 68 | |
7d7efa4a DD |
69 | # Network root scripts may need updated root= options, |
70 | # so deposit them where they can see them (udev purges the env) | |
71 | { | |
72 | echo "root='$root'" | |
73 | echo "rflags='$rflags'" | |
74 | echo "fstype='$fstype'" | |
2734a875 | 75 | echo "netroot='$netroot'" |
7d7efa4a DD |
76 | echo "NEWROOT='$NEWROOT'" |
77 | } > /tmp/root.info | |
78 | ||
a08c1f45 | 79 | # pre-udev scripts run before udev starts, and are run only once. |
a3a3448d | 80 | getarg 'rdbreak=pre-udev' && emergency_shell "Break before pre-udev" |
ec1ad334 VL |
81 | source_all pre-udev |
82 | ||
ec9315e5 | 83 | # start up udev and trigger cold plugs |
4eba843d | 84 | udevd --daemon |
2a652c0b HH |
85 | |
86 | UDEV_LOG_PRIO_ARG=--log-priority | |
87 | UDEV_QUEUE_EMPTY="udevadm settle --timeout=0" | |
88 | ||
89 | if [ $UDEVVERSION -lt 140 ]; then | |
90 | UDEV_LOG_PRIO_ARG=--log_priority | |
91 | UDEV_QUEUE_EMPTY="udevadm settle --timeout=1" | |
92 | fi | |
93 | ||
94 | getarg rdudevinfo && udevadm control $UDEV_LOG_PRIO_ARG=info | |
95 | getarg rdudevdebug && udevadm control $UDEV_LOG_PRIO_ARG=debug | |
1eeddd31 HH |
96 | |
97 | source_all pre-trigger | |
98 | ||
99 | # then the rest | |
53759538 | 100 | udevadm trigger $udevtriggeropts >/dev/null 2>&1 |
eab677a2 | 101 | |
58dbb43e HH |
102 | i=0 |
103 | while :; do | |
104 | # bail out, if we have mounted the root filesystem | |
105 | [ -d "$NEWROOT/proc" ] && break; | |
106 | ||
107 | # check if root can be mounted | |
108 | [ -e /dev/root ] && break; | |
109 | ||
110 | if [ $UDEVVERSION -ge 143 ]; then | |
111 | udevadm settle --exit-if-exists=/initqueue/work --exit-if-exists=/dev/root | |
112 | else | |
113 | udevadm settle --timeout=30 | |
114 | fi | |
89056045 HH |
115 | |
116 | # bail out, if we have mounted the root filesystem | |
117 | [ -d "$NEWROOT/proc" ] && break; | |
118 | # check if root can be mounted | |
119 | [ -e /dev/root ] && break; | |
120 | ||
58dbb43e HH |
121 | unset queuetriggered |
122 | if [ -f /initqueue/work ]; then | |
123 | rm /initqueue/work | |
124 | queuetriggered="1" | |
125 | fi | |
126 | ||
127 | for job in /initqueue/*.sh; do | |
128 | [ -e "$job" ] || break | |
129 | job=$job . $job | |
130 | ||
131 | # bail out, if we have mounted the root filesystem | |
132 | [ -d "$NEWROOT/proc" ] && break; | |
133 | # check if root can be mounted | |
134 | [ -e /dev/root ] && break; | |
135 | done | |
136 | ||
137 | [ -n "$queuetriggered" ] && continue | |
138 | ||
2a652c0b | 139 | if $UDEV_QUEUE_EMPTY >/dev/null 2>&1; then |
58dbb43e HH |
140 | # no more udev jobs |
141 | sleep 0.5 | |
142 | i=$(($i+1)) | |
a3a3448d HH |
143 | [ $i -gt 20 ] \ |
144 | && { flock -s 9 ; emergency_shell "No root device found"; } 9>/.console_lock | |
58dbb43e HH |
145 | fi |
146 | done | |
147 | unset job | |
148 | unset queuetriggered | |
ec9315e5 | 149 | |
a08c1f45 VL |
150 | # pre-mount happens before we try to mount the root filesystem, |
151 | # and happens once. | |
a3a3448d | 152 | getarg 'rdbreak=pre-mount' && emergency_shell "Break pre-mount" |
ec1ad334 | 153 | source_all pre-mount |
bb040f93 | 154 | |
a3a3448d HH |
155 | |
156 | getarg 'rdbreak=mount' && emergency_shell "Break mount" | |
a08c1f45 VL |
157 | # mount scripts actually try to mount the root filesystem, and may |
158 | # be sourced any number of times. As soon as one suceeds, no more are sourced. | |
87930555 | 159 | i=0 |
a08c1f45 | 160 | while :; do |
37dcb400 | 161 | [ -d "$NEWROOT/proc" ] && break; |
a08c1f45 | 162 | for f in /mount/*.sh; do |
eab677a2 | 163 | [ -f "$f" ] && . "$f" |
58dbb43e | 164 | [ -d "$NEWROOT/proc" ] && break; |
a08c1f45 | 165 | done |
bb040f93 | 166 | |
7cd15fe7 | 167 | i=$(($i+1)) |
a3a3448d HH |
168 | [ $i -gt 20 ] \ |
169 | && { flock -s 9 ; emergency_shell "Can't mount root filesystem"; } 9>/.console_lock | |
a08c1f45 VL |
170 | done |
171 | ||
b5c7c7e8 | 172 | # pre pivot scripts are sourced just before we switch over to the new root. |
41271304 | 173 | getarg 'rdbreak=pre-pivot' && emergency_shell |
88ffd2df VL |
174 | source_all pre-pivot |
175 | ||
a08c1f45 | 176 | # by the time we get here, the root filesystem should be mounted. |
d05f3c43 VL |
177 | # Try to find init. |
178 | for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do | |
179 | [ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT="$i"; break; } | |
180 | done | |
6b0daf2e | 181 | [ "$INIT" ] || { |
a3a3448d HH |
182 | echo "Cannot find init!" |
183 | echo "Please check to make sure you passed a valid root filesystem!" | |
d05f3c43 | 184 | emergency_shell |
6b0daf2e | 185 | } |
a08c1f45 | 186 | |
41271304 | 187 | getarg rdbreak && emergency_shell |
7e87a0bf HH |
188 | |
189 | HARD="" | |
190 | while pidof udevd >/dev/null 2>&1; do | |
191 | for pid in $(pidof udevd); do | |
192 | kill $HARD $pid >/dev/null 2>&1 | |
193 | done | |
194 | HARD="-9" | |
195 | done | |
5fa49940 AT |
196 | |
197 | # Clean up the environment | |
198 | for i in $(export -p); do | |
199 | i=${i#declare -x} | |
200 | i=${i#export} | |
201 | i=${i%%=*} | |
202 | [ "$i" = "root" -o "$i" = "PATH" -o "$i" = "HOME" -o "$i" = "TERM" ] || unset $i | |
203 | done | |
204 | ||
faf88239 | 205 | initargs="" |
52c3715f HH |
206 | initrdargs="$initrdargs console BOOT_IMAGE rdbreak rdinitdebug rdudevinfo rdudevdebug rdnetdebug rdcopystate rdshell" |
207 | ||
80c9d068 | 208 | for x in "$@"; do |
52c3715f HH |
209 | for s in $initrdargs; do |
210 | [ "${x%%=*}" = $s ] && continue 1 | |
211 | done | |
faf88239 VL |
212 | initargs="$initargs $x" |
213 | done | |
e1ee9353 WT |
214 | |
215 | # Copy state | |
216 | mkdir /dev/.initramfs/ | |
217 | if getarg rdcopystate; then | |
218 | cp /tmp/* /dev/.initramfs/ >/dev/null 2>&1 | |
219 | else | |
220 | cp /tmp/net.* /dev/.initramfs/ >/dev/null 2>&1 | |
221 | fi | |
222 | ||
faf88239 | 223 | exec switch_root "$NEWROOT" "$INIT" $initargs || { |
9cead591 VL |
224 | # davej doesn't like initrd bugs |
225 | echo "Something went very badly wrong in the initrd. Please " | |
226 | echo "file a bug against mkinitrd." | |
227 | emergency_shell | |
228 | } |