]>
git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/99base/init
3 # Licensed under the GPLv2
5 # Copyright 2008, Red Hat, Inc.
6 # Jeremy Katz <katzj@redhat.com>
12 echo "Bug in initramfs /init detected. Dropping to a shell. Good luck!"
17 export PATH
=/sbin
:/bin
:/usr
/sbin
:/usr
/bin
21 trap "emergency_shell" 0
27 # mount some important things
28 mount
-t proc
/proc
/proc
>/dev
/null
2>&1
29 mount
-t sysfs
/sys
/sys
>/dev
/null
2>&1
30 mount
-t tmpfs
-omode=0755 udev
/dev
>/dev
/null
2>&1
32 getarg rdinitdebug
&& set -x
33 # Make some basic devices first, let udev handle the rest
36 mknod
/dev
/console c
5 1
38 mount
-t devpts
-o gid
=5,mode
=620 /dev
/pts
/dev
/pts
>/dev
/null
2>&1
40 # run scriptlets to parse the command line
41 getarg
'rdbreak=cmdline' && emergency_shell
44 if [ -z "$rootok" -a -n "${root%%error:*}" ]; then
45 root
="error: No handler for root=${root}"
48 if [ -z "${root%%error:*}" ]; then
50 '') echo "FATAL: no root= option specified, and no network support" ;;
51 error
) echo "FATAL: ${root#error:}" ;;
56 # Network root scripts may need updated root= options,
57 # so deposit them where they can see them (udev purges the env)
60 echo "rflags='$rflags'"
61 echo "fstype='$fstype'"
62 echo "NEWROOT='$NEWROOT'"
65 # pre-udev scripts run before udev starts, and are run only once.
66 getarg
'rdbreak=pre-udev' && emergency_shell
69 # start up udev and trigger cold plugs
71 getarg rdudevinfo
&& udevadm control
--log_priority=info
72 getarg rdudevdebug
&& udevadm control
--log_priority=debug
74 source_all pre-trigger
77 [ -f /tmp
/udevtriggeropts
] && udevtriggeropts
=$
(while read line
; do echo $line;done < /tmp
/udevtriggeropts
)
78 udevadm trigger
$udevtriggeropts >/dev
/null
2>&1
79 udevadm settle
--timeout=30 >/dev
/null
2>&1
81 # pre-mount happens before we try to mount the root filesystem,
83 getarg
'rdbreak=pre-mount' && emergency_shell
85 getarg
'rdbreak=mount' && emergency_shell
87 # mount scripts actually try to mount the root filesystem, and may
88 # be sourced any number of times. As soon as one suceeds, no more are sourced.
91 [ -d "$NEWROOT/proc" ] && break;
93 for f
in /mount
/*.sh
; do
94 [ -x "$f" ] && .
"$f";
95 [ "$ROOTFS_MOUNTED" ] && break;
100 { flock
-s 9 ; [ $i -gt 20 ] && emergency_shell
; } 9>/.console_lock
103 # pre pivot scripts are sourced just before we switch over to the new root.
104 getarg
'rdbreak=pre-pivot' && emergency_shell
107 # by the time we get here, the root filesystem should be mounted.
109 for i
in "$(getarg init=)" /sbin
/init
/etc
/init
/init
/bin
/sh
; do
110 [ -f "$NEWROOT$i" -a -x "$NEWROOT$i" ] && { INIT
="$i"; break; }
113 echo "Cannot find init! Please check to make sure you passed"
114 echo "a valid root filesystem! Dropping to a shell."
118 getarg rdbreak
&& emergency_shell
121 # Clean up the environment
122 for i
in $
(export -p); do
126 [ "$i" = "root" -o "$i" = "PATH" -o "$i" = "HOME" -o "$i" = "TERM" ] ||
unset $i
131 [ "${x%%=*}" = "console" ] && continue
132 [ "${x%%=*}" = "BOOT_IMAGE" ] && continue
133 [ "${x%%=*}" = "rdbreak" ] && continue
134 [ "${x%%=*}" = "rdinitdebug" ] && continue
135 [ "${x%%=*}" = "rdudevinfo" ] && continue
136 [ "${x%%=*}" = "rdudevdebug" ] && continue
137 initargs
="$initargs $x"
139 exec switch_root
"$NEWROOT" "$INIT" $initargs ||
{
140 # davej doesn't like initrd bugs
141 echo "Something went very badly wrong in the initrd. Please "
142 echo "file a bug against mkinitrd."