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