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