]>
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 | { | |
09f9fec0 | 10 | [ -x /bin/plymouth ] && plymouth --hide-splash |
ca9f6259 | 11 | echo ; echo |
ec9315e5 JK |
12 | echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!" |
13 | echo | |
0c70846e | 14 | bash < /dev/console |
ec9315e5 | 15 | } |
ec9315e5 JK |
16 | |
17 | echo "Starting initrd..." | |
18 | export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
19 | export TERM=linux | |
20 | ||
09f9fec0 | 21 | trap "emergency_shell" 0 2 |
ec9315e5 JK |
22 | # /dev/console comes from the built-in initramfs crud in the kernel |
23 | # someday, we may need to mkdir /dev first here | |
eb25ff7a | 24 | exec > /dev/console 2>&1 < /dev/console |
ec9315e5 JK |
25 | |
26 | # mount some important things | |
ec9315e5 | 27 | mount -t proc /proc /proc |
ec9315e5 JK |
28 | mount -t sysfs /sys /sys |
29 | mount -t tmpfs -omode=0755 udev /dev | |
30 | ||
0c70846e | 31 | # FIXME: what device nodes does plymouth really _need_ ? |
0c70846e JK |
32 | mknod /dev/ptmx c 5 2 |
33 | mknod /dev/fb c 29 0 | |
34 | mkdir /dev/pts | |
35 | mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts | |
0c70846e JK |
36 | mknod /dev/tty0 c 4 0 |
37 | mknod /dev/tty1 c 4 1 | |
0c70846e JK |
38 | |
39 | # start plymouth if it's available | |
40 | # arguably we need some of udev run first for fbmods and above devnodes :/ | |
09f9fec0 VL |
41 | [ -x /bin/plymouthd ] && plymouthd --attach-to-session |
42 | [ -x /bin/plymouth ] && plymouth --show-splash | |
0c70846e JK |
43 | |
44 | ||
ec9315e5 | 45 | # start up udev and trigger cold plugs |
09f9fec0 VL |
46 | udevd --daemon |
47 | udevadm trigger | |
ec9315e5 | 48 | |
ec9315e5 | 49 | # mount the rootfs |
35c5d61b | 50 | NEWROOT="/sysroot" |
ec9315e5 | 51 | |
35c5d61b JK |
52 | # FIXME: there's got to be a better way ... |
53 | # it'd be nice if we had a udev rule that just did all of the bits for | |
54 | # figuring out what the specified root is and linking it /dev/root | |
55 | for o in `cat /proc/cmdline` ; do | |
56 | case $o in | |
57 | root=*) | |
58 | root=${o#root=} | |
59 | ;; | |
60 | esac | |
61 | done | |
62 | echo -n "Going to mount rootfs ($root)" | |
63 | if [ -z "$root" ]; then | |
64 | echo "Warning: no root specified" | |
65 | root="/dev/sda1" | |
66 | elif [ "${root#LABEL=}" != $root ]; then | |
2064166d BN |
67 | # FIXME: may need to do more escaping here |
68 | l=${root#LABEL=} | |
69 | label=${l//\//\\x2f} | |
70 | root="/dev/disk/by-label/${label}" | |
35c5d61b JK |
71 | elif [ "${root#UUID=}" != $root ]; then |
72 | root="/dev/disk/by-uuid/${root#UUID=}" | |
73 | fi | |
74 | # should we have a timeout? | |
75 | tries=0 | |
76 | while [ ! -e $root ]; do | |
77 | echo -n "." | |
78 | sleep 1 | |
79 | tries=$(($tries + 1)) | |
dd1ae3a1 | 80 | if [ $tries -gt 30 ]; then |
ca9f6259 JK |
81 | emergency_shell |
82 | fi | |
35c5d61b | 83 | done |
a019b953 | 84 | echo -e "\n\nMounting rootfs after $tries seconds" |
35c5d61b | 85 | ln -s "$root" /dev/root |
09bab2aa | 86 | mount -o ro /dev/root $NEWROOT || emergency_shell |
65e66984 | 87 | |
ec9315e5 JK |
88 | # now we need to prepare to switchroot |
89 | mount --bind /dev $NEWROOT/dev | |
90 | ||
91 | # FIXME: now for a bunch of boiler-plate mounts. really, we should have | |
92 | # some like /etc/fstab.sys that's provided by filesystem/initscripts | |
93 | # and then do mount -f /etc/fstab.sys -a | |
94 | mount -t proc /proc $NEWROOT/proc | |
95 | mount -t sysfs /sys $NEWROOT/sys | |
96 | ||
654568b3 JK |
97 | # FIXME: load selinux policy. this should really be done after we switchroot |
98 | if [ -x $NEWROOT/usr/sbin/load_policy ]; then | |
99 | chroot $NEWROOT /usr/sbin/load_policy -i | |
100 | if [ $? -eq 3 ]; then | |
101 | echo "Initial SELinux policy load failed and enforcing mode requested." | |
102 | echo "Not continuing" | |
103 | sleep 100d | |
104 | exit 1 | |
105 | fi | |
106 | fi | |
ec9315e5 | 107 | |
35c5d61b JK |
108 | # kill off udev |
109 | kill `pidof udevd` | |
0c70846e | 110 | |
09f9fec0 | 111 | [ -x /bin/plymouth ] && plymouth --newroot=$NEWROOT |
654568b3 | 112 | |
ec9315e5 | 113 | # FIXME: nash die die die |
09f9fec0 | 114 | exec switch_root |
ec9315e5 JK |
115 | # davej doesn't like initrd bugs |
116 | echo "Something went very badly wrong in the initrd. Please " | |
117 | echo "file a bug against mkinitrd." | |
ed16343e | 118 | sleep 100d |
ec9315e5 | 119 | exit 1 |