]> git.ipfire.org Git - thirdparty/dracut.git/blame - init
[PATCH 01/50] We have a path. Do not specify full paths to commands that are in it.
[thirdparty/dracut.git] / init
CommitLineData
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
8emergency_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
17echo "Starting initrd..."
18export PATH=/sbin:/bin:/usr/sbin:/usr/bin
19export TERM=linux
20
09f9fec0 21trap "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 24exec > /dev/console 2>&1 < /dev/console
ec9315e5
JK
25
26# mount some important things
ec9315e5 27mount -t proc /proc /proc
ec9315e5
JK
28mount -t sysfs /sys /sys
29mount -t tmpfs -omode=0755 udev /dev
30
0c70846e 31# FIXME: what device nodes does plymouth really _need_ ?
0c70846e
JK
32mknod /dev/ptmx c 5 2
33mknod /dev/fb c 29 0
34mkdir /dev/pts
35mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
0c70846e
JK
36mknod /dev/tty0 c 4 0
37mknod /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
46udevd --daemon
47udevadm trigger
ec9315e5 48
ec9315e5 49# mount the rootfs
35c5d61b 50NEWROOT="/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
55for o in `cat /proc/cmdline` ; do
56 case $o in
57 root=*)
58 root=${o#root=}
59 ;;
60 esac
61done
62echo -n "Going to mount rootfs ($root)"
63if [ -z "$root" ]; then
64 echo "Warning: no root specified"
65 root="/dev/sda1"
66elif [ "${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
71elif [ "${root#UUID=}" != $root ]; then
72 root="/dev/disk/by-uuid/${root#UUID=}"
73fi
74# should we have a timeout?
75tries=0
76while [ ! -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 83done
a019b953 84echo -e "\n\nMounting rootfs after $tries seconds"
35c5d61b 85ln -s "$root" /dev/root
09bab2aa 86mount -o ro /dev/root $NEWROOT || emergency_shell
65e66984 87
ec9315e5
JK
88# now we need to prepare to switchroot
89mount --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
94mount -t proc /proc $NEWROOT/proc
95mount -t sysfs /sys $NEWROOT/sys
96
654568b3
JK
97# FIXME: load selinux policy. this should really be done after we switchroot
98if [ -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
106fi
ec9315e5 107
35c5d61b
JK
108# kill off udev
109kill `pidof udevd`
0c70846e 110
09f9fec0 111[ -x /bin/plymouth ] && plymouth --newroot=$NEWROOT
654568b3 112
ec9315e5 113# FIXME: nash die die die
09f9fec0 114exec switch_root
ec9315e5
JK
115# davej doesn't like initrd bugs
116echo "Something went very badly wrong in the initrd. Please "
117echo "file a bug against mkinitrd."
ed16343e 118sleep 100d
ec9315e5 119exit 1