]> git.ipfire.org Git - thirdparty/dracut.git/blame_incremental - init
cryptsetup does not like running in a while read loop.
[thirdparty/dracut.git] / init
... / ...
CommitLineData
1#!/bin/sh
2#
3# Licensed under the GPLv2
4#
5# Copyright 2008, Red Hat, Inc.
6# Jeremy Katz <katzj@redhat.com>
7
8emergency_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
16getarg() {
17 local o line
18 for o in $CMDLINE; do
19 [ "${o%%=*}" = "$1" ] && { echo $o; return 0; }
20 done
21 return 1
22}
23
24source_all() {
25 local f
26 [ "$1" ] && [ -d "/$1" ] || return
27 for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
28}
29
30echo "Starting initrd..."
31export PATH=/sbin:/bin:/usr/sbin:/usr/bin
32export TERM=linux
33CONSOLE=/dev/console
34[ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE
35trap "emergency_shell" 0
36# mount some important things
37mount -t proc /proc /proc
38mount -t sysfs /sys /sys
39mount -t tmpfs -omode=0755 udev /dev
40read CMDLINE </proc/cmdline;
41
42
43# FIXME: what device nodes does plymouth really _need_ ?
44mknod /dev/ptmx c 5 2
45mknod /dev/console c 5 0
46mknod /dev/fb c 29 0
47mkdir /dev/pts
48mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
49mknod /dev/tty0 c 4 0
50mknod /dev/tty1 c 4 1
51mknod /dev/null c 1 3
52
53source_all pre-udev
54
55# start up udev and trigger cold plugs
56udevd --daemon
57udevadm trigger >/dev/null 2>&1
58
59# mount the rootfs
60NEWROOT="/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
65root=$(getarg root); root=${root#root=}
66case $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" ;;
73esac
74
75# should we have a timeout?
76tries=0
77echo "Waiting up to 30 seconds for $root to become available"
78udevadm settle --timeout=30
79source_all pre-mount
80
81echo "Trying to mount rootfs $root"
82if rflags="$(getarg rootflags)"; then
83 rflags="${rflags#rootflags=}"
84 getarg rw >/dev/null && rflags="${rflags},rw" || rflags="${rflags},ro"
85else
86 getarg rw >/dev/null && rflags=rw || rflags=ro
87fi
88[ -e "$root" ] || emergency_shell
89ln -s "$root" /dev/root
90fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}"
91mount $fstype -o $rflags /dev/root $NEWROOT || emergency_shell
92
93INIT=$(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
105source_all pre-pivot
106echo "Switching to real root filesystem $root"
107exec 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}