]>
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 |
27994f9e | 19 | [ "${o%%=*}" = "$1" ] && { echo $o; return 0; } |
04789195 | 20 | done |
cd20f1f6 VL |
21 | return 1 |
22 | } | |
23 | ||
24 | source_all() { | |
25 | local f | |
7f64a3fe | 26 | [ "$1" ] && [ -d "/$1" ] || return |
3f9c86ab | 27 | for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done |
04789195 VL |
28 | } |
29 | ||
ec9315e5 JK |
30 | echo "Starting initrd..." |
31 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
32 | export TERM=linux | |
6b0daf2e VL |
33 | CONSOLE=/dev/console |
34 | [ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE | |
7f64a3fe | 35 | trap "emergency_shell" 0 |
ec9315e5 | 36 | # mount some important things |
ec9315e5 | 37 | mount -t proc /proc /proc |
ec9315e5 JK |
38 | mount -t sysfs /sys /sys |
39 | mount -t tmpfs -omode=0755 udev /dev | |
6b0daf2e VL |
40 | read CMDLINE </proc/cmdline; |
41 | ||
ec9315e5 | 42 | |
0c70846e | 43 | # FIXME: what device nodes does plymouth really _need_ ? |
0c70846e | 44 | mknod /dev/ptmx c 5 2 |
7924b212 | 45 | mknod /dev/console c 5 0 |
0c70846e JK |
46 | mknod /dev/fb c 29 0 |
47 | mkdir /dev/pts | |
48 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts | |
0c70846e JK |
49 | mknod /dev/tty0 c 4 0 |
50 | mknod /dev/tty1 c 4 1 | |
bc6b0dec | 51 | mknod /dev/null c 1 3 |
0c70846e | 52 | |
ec1ad334 VL |
53 | source_all pre-udev |
54 | ||
ec9315e5 | 55 | # start up udev and trigger cold plugs |
09f9fec0 | 56 | udevd --daemon |
bc6b0dec | 57 | udevadm trigger >/dev/null 2>&1 |
ec9315e5 | 58 | |
ec9315e5 | 59 | # mount the rootfs |
9cead591 | 60 | NEWROOT="/sysroot" |
ec9315e5 | 61 | |
35c5d61b JK |
62 | # FIXME: there's got to be a better way ... |
63 | # it'd be nice if we had a udev rule that just did all of the bits for | |
64 | # figuring out what the specified root is and linking it /dev/root | |
7f64a3fe | 65 | root=$(getarg root); root=${root#root=} |
f9a0b9f8 VL |
66 | case $root in |
67 | LABEL=*) root=${root#LABEL=} | |
2a3efd82 | 68 | root="$(echo $root |sed 's,/,\\x2f,g')" |
f9a0b9f8 VL |
69 | root="/dev/disk/by-label/${root}" ;; |
70 | UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;; | |
71 | '') echo "Warning: no root specified" | |
72 | root="/dev/sda1" ;; | |
73 | esac | |
74 | ||
35c5d61b JK |
75 | # should we have a timeout? |
76 | tries=0 | |
7924b212 VL |
77 | echo "Waiting up to 30 seconds for $root to become available" |
78 | udevadm settle --timeout=30 | |
ec1ad334 | 79 | source_all pre-mount |
cd20f1f6 | 80 | |
7924b212 | 81 | echo "Trying to mount rootfs $root" |
9689f4c8 VL |
82 | if rflags="$(getarg rootflags)"; then |
83 | rflags="${rflags#rootflags=}" | |
84 | getarg rw >/dev/null && rflags="${rflags},rw" || rflags="${rflags},ro" | |
85 | else | |
86 | getarg rw >/dev/null && rflags=rw || rflags=ro | |
87 | fi | |
7f64a3fe | 88 | [ -e "$root" ] || emergency_shell |
9689f4c8 VL |
89 | ln -s "$root" /dev/root |
90 | fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}" | |
91 | mount $fstype -o $rflags /dev/root $NEWROOT || emergency_shell | |
65e66984 | 92 | |
6b0daf2e VL |
93 | INIT=$(getarg init) |
94 | [ "$INIT" ] || { | |
95 | for i in /sbin/init /etc/init /init /bin/sh; do | |
96 | [ -x "$NEWROOT$i" ] && { INIT="$i"; break; } | |
97 | done | |
98 | [ "$INIT" ] || { | |
99 | echo "Cannot find init! Please check to make sure you passed" | |
100 | echo "a valid root filesystem! Dropping to a shell." | |
101 | emergency_shell | |
102 | } | |
103 | } | |
104 | ||
ec1ad334 | 105 | source_all pre-pivot |
9cead591 VL |
106 | echo "Switching to real root filesystem $root" |
107 | exec switch_root "$NEWROOT" "$INIT" $CMDLINE || { | |
108 | # davej doesn't like initrd bugs | |
109 | echo "Something went very badly wrong in the initrd. Please " | |
110 | echo "file a bug against mkinitrd." | |
111 | emergency_shell | |
112 | } |