]> git.ipfire.org Git - thirdparty/dracut.git/blame - init
cryptsetup does not like running in a while read loop.
[thirdparty/dracut.git] / init
CommitLineData
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
8emergency_shell()
9{
ca9f6259 10 echo ; echo
ec9315e5
JK
11 echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
12 echo
6b0daf2e 13 sh -i
ec9315e5 14}
ec9315e5 15
04789195 16getarg() {
955f8b09 17 local o line
6b0daf2e 18 for o in $CMDLINE; do
27994f9e 19 [ "${o%%=*}" = "$1" ] && { echo $o; return 0; }
04789195 20 done
cd20f1f6
VL
21 return 1
22}
23
24source_all() {
25 local f
7f64a3fe 26 [ "$1" ] && [ -d "/$1" ] || return
3f9c86ab 27 for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
04789195
VL
28}
29
ec9315e5
JK
30echo "Starting initrd..."
31export PATH=/sbin:/bin:/usr/sbin:/usr/bin
32export TERM=linux
6b0daf2e
VL
33CONSOLE=/dev/console
34[ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE
7f64a3fe 35trap "emergency_shell" 0
ec9315e5 36# mount some important things
ec9315e5 37mount -t proc /proc /proc
ec9315e5
JK
38mount -t sysfs /sys /sys
39mount -t tmpfs -omode=0755 udev /dev
6b0daf2e
VL
40read CMDLINE </proc/cmdline;
41
ec9315e5 42
0c70846e 43# FIXME: what device nodes does plymouth really _need_ ?
0c70846e 44mknod /dev/ptmx c 5 2
7924b212 45mknod /dev/console c 5 0
0c70846e
JK
46mknod /dev/fb c 29 0
47mkdir /dev/pts
48mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
0c70846e
JK
49mknod /dev/tty0 c 4 0
50mknod /dev/tty1 c 4 1
bc6b0dec 51mknod /dev/null c 1 3
0c70846e 52
ec1ad334
VL
53source_all pre-udev
54
ec9315e5 55# start up udev and trigger cold plugs
09f9fec0 56udevd --daemon
bc6b0dec 57udevadm trigger >/dev/null 2>&1
ec9315e5 58
ec9315e5 59# mount the rootfs
9cead591 60NEWROOT="/sysroot"
ec9315e5 61
35c5d61b
JK
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
7f64a3fe 65root=$(getarg root); root=${root#root=}
f9a0b9f8
VL
66case $root in
67 LABEL=*) root=${root#LABEL=}
2a3efd82 68 root="$(echo $root |sed 's,/,\\x2f,g')"
f9a0b9f8
VL
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
35c5d61b
JK
75# should we have a timeout?
76tries=0
7924b212
VL
77echo "Waiting up to 30 seconds for $root to become available"
78udevadm settle --timeout=30
ec1ad334 79source_all pre-mount
cd20f1f6 80
7924b212 81echo "Trying to mount rootfs $root"
9689f4c8
VL
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
7f64a3fe 88[ -e "$root" ] || emergency_shell
9689f4c8
VL
89ln -s "$root" /dev/root
90fstype="$(getarg rootfstype)" && fstype="-t ${fstype#rootfstype=}"
91mount $fstype -o $rflags /dev/root $NEWROOT || emergency_shell
65e66984 92
6b0daf2e
VL
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
ec1ad334 105source_all pre-pivot
9cead591
VL
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}