]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/99base/init
Standardize boot failed language.
[thirdparty/dracut.git] / modules.d / 99base / init
CommitLineData
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
8emergency_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
25export PATH=/sbin:/bin:/usr/sbin:/usr/bin
26export TERM=linux
bb040f93
HH
27NEWROOT="/sysroot"
28
a75c29be 29trap "emergency_shell Signal caught!" 0
a890fe29 30
b8f39ef1 31. /lib/dracut-lib.sh
df44688f 32
a890fe29
HH
33mknod /dev/null c 1 3
34
ec9315e5 35# mount some important things
a890fe29
HH
36mount -t proc /proc /proc >/dev/null 2>&1
37mount -t sysfs /sys /sys >/dev/null 2>&1
a890fe29 38
3473f5d9 39if [ ! -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
50fi
d0e2110a 51
83701d66
HH
52if getarg rdinitdebug; then
53 set -x
83701d66
HH
54fi
55
d0e2110a 56mkdir /dev/shm
0c70846e 57mkdir /dev/pts
a890fe29 58mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1
0c70846e 59
eab677a2
HH
60UDEVVERSION=$(udevadm --version)
61
e4502814 62# run scriptlets to parse the command line
a3a3448d 63getarg 'rdbreak=cmdline' && emergency_shell "Break before cmdline"
e4502814
DD
64source_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 80getarg 'rdbreak=pre-udev' && emergency_shell "Break before pre-udev"
ec1ad334
VL
81source_all pre-udev
82
ec9315e5 83# start up udev and trigger cold plugs
4eba843d 84udevd --daemon
2a652c0b
HH
85
86UDEV_LOG_PRIO_ARG=--log-priority
87UDEV_QUEUE_EMPTY="udevadm settle --timeout=0"
88
89if [ $UDEVVERSION -lt 140 ]; then
90 UDEV_LOG_PRIO_ARG=--log_priority
91 UDEV_QUEUE_EMPTY="udevadm settle --timeout=1"
92fi
93
94getarg rdudevinfo && udevadm control $UDEV_LOG_PRIO_ARG=info
95getarg rdudevdebug && udevadm control $UDEV_LOG_PRIO_ARG=debug
1eeddd31
HH
96
97source_all pre-trigger
98
99# then the rest
53759538 100udevadm trigger $udevtriggeropts >/dev/null 2>&1
eab677a2 101
58dbb43e
HH
102i=0
103while :; 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
146done
147unset job
148unset queuetriggered
ec9315e5 149
a08c1f45
VL
150# pre-mount happens before we try to mount the root filesystem,
151# and happens once.
a3a3448d 152getarg 'rdbreak=pre-mount' && emergency_shell "Break pre-mount"
ec1ad334 153source_all pre-mount
bb040f93 154
a3a3448d
HH
155
156getarg '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 159i=0
a08c1f45 160while :; 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
170done
171
b5c7c7e8 172# pre pivot scripts are sourced just before we switch over to the new root.
41271304 173getarg 'rdbreak=pre-pivot' && emergency_shell
88ffd2df
VL
174source_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.
178for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
179 [ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT="$i"; break; }
180done
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 187getarg rdbreak && emergency_shell
7e87a0bf
HH
188
189HARD=""
190while 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"
195done
5fa49940
AT
196
197# Clean up the environment
198for 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
203done
204
faf88239 205initargs=""
52c3715f
HH
206initrdargs="$initrdargs console BOOT_IMAGE rdbreak rdinitdebug rdudevinfo rdudevdebug rdnetdebug rdcopystate rdshell"
207
80c9d068 208for x in "$@"; do
52c3715f
HH
209 for s in $initrdargs; do
210 [ "${x%%=*}" = $s ] && continue 1
211 done
faf88239
VL
212 initargs="$initargs $x"
213done
e1ee9353
WT
214
215# Copy state
216mkdir /dev/.initramfs/
217if getarg rdcopystate; then
218 cp /tmp/* /dev/.initramfs/ >/dev/null 2>&1
219else
220 cp /tmp/net.* /dev/.initramfs/ >/dev/null 2>&1
221fi
222
faf88239 223exec 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}