]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # Licensed under the GPLv2 | |
4 | # | |
5 | # Copyright 2008, Red Hat, Inc. | |
6 | # Jeremy Katz <katzj@redhat.com> | |
7 | ||
8 | emergency_shell() | |
9 | { | |
10 | echo ; echo | |
11 | echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!" | |
12 | echo | |
13 | sh -i | |
14 | } | |
15 | ||
16 | getarg() { | |
17 | local o line | |
18 | for o in $CMDLINE; do | |
19 | [ "${o%%=*}" = "$1" ] && { echo $o; return 0; } | |
20 | done | |
21 | return 1 | |
22 | } | |
23 | ||
24 | source_all() { | |
25 | local f | |
26 | [ "$1" ] && [ -d "/$1" ] || return | |
27 | for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done | |
28 | } | |
29 | ||
30 | echo "Starting initrd..." | |
31 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
32 | export TERM=linux | |
33 | CONSOLE=/dev/console | |
34 | [ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE | |
35 | trap "emergency_shell" 0 | |
36 | # mount some important things | |
37 | mount -t proc /proc /proc | |
38 | mount -t sysfs /sys /sys | |
39 | mount -t tmpfs -omode=0755 udev /dev | |
40 | read CMDLINE </proc/cmdline; | |
41 | ||
42 | ||
43 | # FIXME: what device nodes does plymouth really _need_ ? | |
44 | mknod /dev/ptmx c 5 2 | |
45 | mknod /dev/console c 5 0 | |
46 | mknod /dev/fb c 29 0 | |
47 | mkdir /dev/pts | |
48 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts | |
49 | mknod /dev/tty0 c 4 0 | |
50 | mknod /dev/tty1 c 4 1 | |
51 | mknod /dev/null c 1 3 | |
52 | ||
53 | source_all pre-udev | |
54 | ||
55 | # start up udev and trigger cold plugs | |
56 | udevd --daemon | |
57 | udevadm trigger >/dev/null 2>&1 | |
58 | ||
59 | # mount the rootfs | |
60 | NEWROOT="/sysroot" | |
61 | ||
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 | |
65 | root=$(getarg root); root=${root#root=} | |
66 | case $root in | |
67 | LABEL=*) root=${root#LABEL=} | |
68 | root="$(echo $root |sed 's,/,\\x2f,g')" | |
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 | ||
75 | # should we have a timeout? | |
76 | tries=0 | |
77 | echo "Waiting up to 30 seconds for $root to become available" | |
78 | udevadm settle --timeout=30 | |
79 | source_all pre-mount | |
80 | ||
81 | echo "Trying to mount rootfs $root" | |
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 | |
88 | [ -e "$root" ] || emergency_shell | |
89 | ln -s "$root" /dev/root | |
90 | fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}" | |
91 | mount $fstype -o $rflags /dev/root $NEWROOT || emergency_shell | |
92 | ||
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 | ||
105 | source_all pre-pivot | |
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 | } |