]>
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 | { | |
ca9f6259 | 10 | echo ; echo |
ec9315e5 JK |
11 | echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!" |
12 | echo | |
6b0daf2e | 13 | sh -i |
ec9315e5 | 14 | } |
ec9315e5 | 15 | |
04789195 | 16 | getarg() { |
955f8b09 | 17 | local o line |
6b0daf2e | 18 | for o in $CMDLINE; do |
d05f3c43 VL |
19 | [ "$o" = "$1" ] && return 0 |
20 | [ "${o%%=*}" = "${1%=}" ] && { echo ${o#*=}; return 0; } | |
04789195 | 21 | done |
cd20f1f6 VL |
22 | return 1 |
23 | } | |
24 | ||
25 | source_all() { | |
26 | local f | |
7f64a3fe | 27 | [ "$1" ] && [ -d "/$1" ] || return |
3f9c86ab | 28 | for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done |
04789195 VL |
29 | } |
30 | ||
ec9315e5 JK |
31 | echo "Starting initrd..." |
32 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
33 | export TERM=linux | |
6b0daf2e VL |
34 | CONSOLE=/dev/console |
35 | [ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE | |
7f64a3fe | 36 | trap "emergency_shell" 0 |
a890fe29 HH |
37 | |
38 | mknod /dev/null c 1 3 | |
39 | ||
ec9315e5 | 40 | # mount some important things |
a890fe29 HH |
41 | mount -t proc /proc /proc >/dev/null 2>&1 |
42 | mount -t sysfs /sys /sys >/dev/null 2>&1 | |
43 | mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1 | |
44 | ||
6b0daf2e VL |
45 | read CMDLINE </proc/cmdline; |
46 | ||
972673f6 | 47 | # Make some basic devices first, let udev handle the rest |
0c70846e | 48 | mknod /dev/ptmx c 5 2 |
972673f6 | 49 | mknod /dev/console c 5 1 |
0c70846e | 50 | mkdir /dev/pts |
a890fe29 | 51 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1 |
0c70846e | 52 | |
a08c1f45 | 53 | # pre-udev scripts run before udev starts, and are run only once. |
8177ca3e | 54 | getarg 'break=pre-udev' && emergency_shell |
ec1ad334 VL |
55 | source_all pre-udev |
56 | ||
ec9315e5 | 57 | # start up udev and trigger cold plugs |
1e984a27 | 58 | udevd --daemon --resolve-names=never |
bc6b0dec | 59 | udevadm trigger >/dev/null 2>&1 |
8177ca3e | 60 | udevadm settle --timeout=30 >/dev/null 2>&1 |
ec9315e5 | 61 | |
9cead591 | 62 | NEWROOT="/sysroot" |
a08c1f45 VL |
63 | # pre-mount happens before we try to mount the root filesystem, |
64 | # and happens once. | |
8177ca3e | 65 | getarg 'break=pre-mount' && emergency_shell |
ec1ad334 | 66 | source_all pre-mount |
8177ca3e | 67 | getarg 'break=mount' && emergency_shell |
a08c1f45 VL |
68 | # mount scripts actually try to mount the root filesystem, and may |
69 | # be sourced any number of times. As soon as one suceeds, no more are sourced. | |
87930555 | 70 | i=0 |
a08c1f45 VL |
71 | while :; do |
72 | for f in /mount/*.sh; do | |
73 | [ -x "$f" ] && . "$f"; | |
74 | [ "$ROOTFS_MOUNTED" ] && break; | |
75 | done | |
76 | [ "$ROOTFS_MOUNTED" ] && break; | |
77 | sleep 1 | |
87930555 HH |
78 | i=$[$i+1] |
79 | [ $i -gt 10 ] && emergency_shell | |
a08c1f45 VL |
80 | done |
81 | ||
82 | # by the time we get here, the root filesystem should be mounted. | |
d05f3c43 VL |
83 | # Try to find init. |
84 | for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do | |
85 | [ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT="$i"; break; } | |
86 | done | |
6b0daf2e | 87 | [ "$INIT" ] || { |
d05f3c43 VL |
88 | echo "Cannot find init! Please check to make sure you passed" |
89 | echo "a valid root filesystem! Dropping to a shell." | |
90 | emergency_shell | |
6b0daf2e | 91 | } |
a08c1f45 VL |
92 | |
93 | # pre pivot scripts are sourced just before we switch over to the new root. | |
8177ca3e | 94 | getarg 'break=pre-pivot' && emergency_shell |
ec1ad334 | 95 | source_all pre-pivot |
8177ca3e | 96 | getarg break && emergency_shell |
87930555 | 97 | kill $(pidof udevd) |
9cead591 | 98 | echo "Switching to real root filesystem $root" |
63efe29b | 99 | exec switch_root -n "$NEWROOT" || { |
9cead591 VL |
100 | # davej doesn't like initrd bugs |
101 | echo "Something went very badly wrong in the initrd. Please " | |
102 | echo "file a bug against mkinitrd." | |
103 | emergency_shell | |
104 | } |