]>
Commit | Line | Data |
---|---|---|
ec9315e5 | 1 | #!/bin/bash |
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 | { | |
10 | echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!" | |
11 | echo | |
12 | bash | |
13 | } | |
14 | trap "emergency_shell" 0 2 | |
15 | ||
16 | echo "Starting initrd..." | |
17 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
18 | export TERM=linux | |
19 | ||
20 | # /dev/console comes from the built-in initramfs crud in the kernel | |
21 | # someday, we may need to mkdir /dev first here | |
22 | exec > /dev/console 2>&1 | |
23 | ||
24 | # mount some important things | |
ec9315e5 | 25 | mount -t proc /proc /proc |
ec9315e5 JK |
26 | mount -t sysfs /sys /sys |
27 | mount -t tmpfs -omode=0755 udev /dev | |
28 | ||
29 | # start up udev and trigger cold plugs | |
30 | /sbin/udevd --daemon | |
31 | /sbin/udevadm trigger | |
32 | # FIXME: should we really wait for the queue to settle or just try to | |
33 | # find the rootfs? | |
35c5d61b | 34 | #/sbin/udevadm settle --timeout=30 || : |
ec9315e5 | 35 | |
ec9315e5 | 36 | # mount the rootfs |
35c5d61b | 37 | NEWROOT="/sysroot" |
ec9315e5 | 38 | |
35c5d61b JK |
39 | # FIXME: there's got to be a better way ... |
40 | # it'd be nice if we had a udev rule that just did all of the bits for | |
41 | # figuring out what the specified root is and linking it /dev/root | |
42 | for o in `cat /proc/cmdline` ; do | |
43 | case $o in | |
44 | root=*) | |
45 | root=${o#root=} | |
46 | ;; | |
47 | esac | |
48 | done | |
49 | echo -n "Going to mount rootfs ($root)" | |
50 | if [ -z "$root" ]; then | |
51 | echo "Warning: no root specified" | |
52 | root="/dev/sda1" | |
53 | elif [ "${root#LABEL=}" != $root ]; then | |
54 | root="/dev/disk/by-label/${root#LABEL=}" | |
55 | elif [ "${root#UUID=}" != $root ]; then | |
56 | root="/dev/disk/by-uuid/${root#UUID=}" | |
57 | fi | |
58 | # should we have a timeout? | |
59 | tries=0 | |
60 | while [ ! -e $root ]; do | |
61 | echo -n "." | |
62 | sleep 1 | |
63 | tries=$(($tries + 1)) | |
64 | done | |
65 | echo -e "\n\nMounted rootfs after $tries seconds" | |
66 | ln -s "$root" /dev/root | |
67 | mount -o ro -t ext3 /dev/root $NEWROOT | |
65e66984 | 68 | |
ec9315e5 JK |
69 | # now we need to prepare to switchroot |
70 | mount --bind /dev $NEWROOT/dev | |
71 | ||
72 | # FIXME: now for a bunch of boiler-plate mounts. really, we should have | |
73 | # some like /etc/fstab.sys that's provided by filesystem/initscripts | |
74 | # and then do mount -f /etc/fstab.sys -a | |
75 | mount -t proc /proc $NEWROOT/proc | |
76 | mount -t sysfs /sys $NEWROOT/sys | |
77 | ||
78 | # FIXME: load selinux policy | |
79 | ||
35c5d61b JK |
80 | # kill off udev |
81 | kill `pidof udevd` | |
ec9315e5 JK |
82 | # FIXME: nash die die die |
83 | exec /sbin/switch_root | |
84 | # davej doesn't like initrd bugs | |
85 | echo "Something went very badly wrong in the initrd. Please " | |
86 | echo "file a bug against mkinitrd." | |
87 | exit 1 |