]>
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 | |
2a3efd82 | 13 | exec sh -i |
ec9315e5 | 14 | } |
ec9315e5 | 15 | |
04789195 | 16 | getarg() { |
cd20f1f6 | 17 | local o; |
7f64a3fe VL |
18 | for o in $(cat /proc/cmdline); do |
19 | [ "${o%%=*}" = "$1" ] && { echo $o; break; } | |
04789195 | 20 | done |
cd20f1f6 VL |
21 | return 1 |
22 | } | |
23 | ||
24 | source_all() { | |
25 | local f | |
7f64a3fe VL |
26 | [ "$1" ] && [ -d "/$1" ] || return |
27 | for f in "/$1"/*; 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 | |
33 | ||
7f64a3fe | 34 | trap "emergency_shell" 0 |
ec9315e5 JK |
35 | # /dev/console comes from the built-in initramfs crud in the kernel |
36 | # someday, we may need to mkdir /dev first here | |
2a3efd82 | 37 | # exec > /dev/console 2>&1 < /dev/console |
ec9315e5 JK |
38 | |
39 | # mount some important things | |
ec9315e5 | 40 | mount -t proc /proc /proc |
ec9315e5 JK |
41 | mount -t sysfs /sys /sys |
42 | mount -t tmpfs -omode=0755 udev /dev | |
43 | ||
0c70846e | 44 | # FIXME: what device nodes does plymouth really _need_ ? |
0c70846e | 45 | mknod /dev/ptmx c 5 2 |
7924b212 | 46 | mknod /dev/console c 5 0 |
0c70846e JK |
47 | mknod /dev/fb c 29 0 |
48 | mkdir /dev/pts | |
49 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts | |
0c70846e JK |
50 | mknod /dev/tty0 c 4 0 |
51 | mknod /dev/tty1 c 4 1 | |
bc6b0dec | 52 | mknod /dev/null c 1 3 |
0c70846e | 53 | |
ec1ad334 VL |
54 | source_all pre-udev |
55 | ||
ec9315e5 | 56 | # start up udev and trigger cold plugs |
09f9fec0 | 57 | udevd --daemon |
bc6b0dec | 58 | udevadm trigger >/dev/null 2>&1 |
ec9315e5 | 59 | |
ec9315e5 | 60 | # mount the rootfs |
35c5d61b | 61 | NEWROOT="/sysroot" |
ec9315e5 | 62 | |
35c5d61b JK |
63 | # FIXME: there's got to be a better way ... |
64 | # it'd be nice if we had a udev rule that just did all of the bits for | |
65 | # figuring out what the specified root is and linking it /dev/root | |
7f64a3fe | 66 | root=$(getarg root); root=${root#root=} |
f9a0b9f8 VL |
67 | case $root in |
68 | LABEL=*) root=${root#LABEL=} | |
2a3efd82 | 69 | root="$(echo $root |sed 's,/,\\x2f,g')" |
f9a0b9f8 VL |
70 | root="/dev/disk/by-label/${root}" ;; |
71 | UUID=*) root="/dev/disk/by-uuid/${root#UUID=}" ;; | |
72 | '') echo "Warning: no root specified" | |
73 | root="/dev/sda1" ;; | |
74 | esac | |
75 | ||
35c5d61b JK |
76 | # should we have a timeout? |
77 | tries=0 | |
7924b212 VL |
78 | echo "Waiting up to 30 seconds for $root to become available" |
79 | udevadm settle --timeout=30 | |
ec1ad334 | 80 | source_all pre-mount |
cd20f1f6 | 81 | |
7924b212 | 82 | echo "Trying to mount rootfs $root" |
7f64a3fe | 83 | [ -e "$root" ] || emergency_shell |
35c5d61b | 84 | ln -s "$root" /dev/root |
09bab2aa | 85 | mount -o ro /dev/root $NEWROOT || emergency_shell |
65e66984 | 86 | |
ec9315e5 JK |
87 | # now we need to prepare to switchroot |
88 | mount --bind /dev $NEWROOT/dev | |
89 | ||
90 | # FIXME: now for a bunch of boiler-plate mounts. really, we should have | |
91 | # some like /etc/fstab.sys that's provided by filesystem/initscripts | |
92 | # and then do mount -f /etc/fstab.sys -a | |
93 | mount -t proc /proc $NEWROOT/proc | |
94 | mount -t sysfs /sys $NEWROOT/sys | |
95 | ||
ec1ad334 | 96 | source_all pre-pivot |
ec9315e5 | 97 | |
35c5d61b | 98 | # kill off udev |
8b691309 | 99 | kill $(pidof udevd) |
0c70846e | 100 | |
ec9315e5 | 101 | # FIXME: nash die die die |
09f9fec0 | 102 | exec switch_root |
ec9315e5 JK |
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." | |
ed16343e | 106 | sleep 100d |
ec9315e5 | 107 | exit 1 |