]> git.ipfire.org Git - thirdparty/dracut.git/blame - modules.d/99base/init
use udev rules to autoassemble a md raid and added mdmon pre-pivot
[thirdparty/dracut.git] / modules.d / 99base / 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
d05f3c43
VL
19 [ "$o" = "$1" ] && return 0
20 [ "${o%%=*}" = "${1%=}" ] && { echo ${o#*=}; return 0; }
04789195 21 done
cd20f1f6
VL
22 return 1
23}
24
25source_all() {
26 local f
7f64a3fe 27 [ "$1" ] && [ -d "/$1" ] || return
3f9c86ab 28 for f in "/$1"/*.sh; do [ -f "$f" ] && . "$f"; done
04789195
VL
29}
30
ec9315e5
JK
31echo "Starting initrd..."
32export PATH=/sbin:/bin:/usr/sbin:/usr/bin
33export TERM=linux
6b0daf2e
VL
34CONSOLE=/dev/console
35[ -c $CONSOLE ] && exec >$CONSOLE 2>&1 <$CONSOLE
7f64a3fe 36trap "emergency_shell" 0
a890fe29
HH
37
38mknod /dev/null c 1 3
39
ec9315e5 40# mount some important things
a890fe29
HH
41mount -t proc /proc /proc >/dev/null 2>&1
42mount -t sysfs /sys /sys >/dev/null 2>&1
43mount -t tmpfs -omode=0755 udev /dev >/dev/null 2>&1
44
6b0daf2e
VL
45read CMDLINE </proc/cmdline;
46
972673f6 47# Make some basic devices first, let udev handle the rest
0c70846e 48mknod /dev/ptmx c 5 2
972673f6 49mknod /dev/console c 5 1
0c70846e 50mkdir /dev/pts
a890fe29 51mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts >/dev/null 2>&1
0c70846e 52
a08c1f45 53# pre-udev scripts run before udev starts, and are run only once.
8177ca3e 54getarg 'break=pre-udev' && emergency_shell
ec1ad334
VL
55source_all pre-udev
56
ec9315e5 57# start up udev and trigger cold plugs
1e984a27 58udevd --daemon --resolve-names=never
bc6b0dec 59udevadm trigger >/dev/null 2>&1
8177ca3e 60udevadm settle --timeout=30 >/dev/null 2>&1
ec9315e5 61
9cead591 62NEWROOT="/sysroot"
a08c1f45
VL
63# pre-mount happens before we try to mount the root filesystem,
64# and happens once.
8177ca3e 65getarg 'break=pre-mount' && emergency_shell
ec1ad334 66source_all pre-mount
8177ca3e 67getarg 'break=mount' && emergency_shell
a08c1f45
VL
68# mount scripts actually try to mount the root filesystem, and may
69# be sourced any number of times. As soon as one suceeds, no more are sourced.
87930555 70i=0
a08c1f45
VL
71while :; do
72 for f in /mount/*.sh; do
73 [ -x "$f" ] && . "$f";
74 [ "$ROOTFS_MOUNTED" ] && break;
75 done
76 [ "$ROOTFS_MOUNTED" ] && break;
77 sleep 1
87930555
HH
78 i=$[$i+1]
79 [ $i -gt 10 ] && emergency_shell
a08c1f45
VL
80done
81
82# by the time we get here, the root filesystem should be mounted.
d05f3c43
VL
83# Try to find init.
84for i in "$(getarg init=)" /sbin/init /etc/init /init /bin/sh; do
85 [ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT="$i"; break; }
86done
6b0daf2e 87[ "$INIT" ] || {
d05f3c43
VL
88 echo "Cannot find init! Please check to make sure you passed"
89 echo "a valid root filesystem! Dropping to a shell."
90 emergency_shell
6b0daf2e 91}
a08c1f45
VL
92
93# pre pivot scripts are sourced just before we switch over to the new root.
8177ca3e 94getarg 'break=pre-pivot' && emergency_shell
ec1ad334 95source_all pre-pivot
8177ca3e 96getarg break && emergency_shell
87930555 97kill $(pidof udevd)
9cead591 98echo "Switching to real root filesystem $root"
63efe29b 99exec switch_root -n "$NEWROOT" || {
9cead591
VL
100 # davej doesn't like initrd bugs
101 echo "Something went very badly wrong in the initrd. Please "
102 echo "file a bug against mkinitrd."
103 emergency_shell
104}