[early] Changed init to not make mdadm and lvm activations fail if the module didn...
[opensde-nopast.git] / target / early / initramfs / init.sh
blob2a962a256c9e9ddd0cdd6beecf6c117609f869b3
1 #!/bin/sh
2 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # Filename: target/early/initramfs/init.sh
6 # Copyright (C) 2007 - 2008 The OpenSDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- SDE-COPYRIGHT-NOTE-END ---
16 export PATH=/usr/bin:/usr/sbin:/bin:/sbin
18 modules=
19 root=
20 mode=
21 init=/sbin/init
23 NOCOLOR=
24 initargs="$*"
26 want_mdadm=
27 want_lvm=
28 want_shell=
30 # read kernel arguments
31 [ -e /proc/cmdline ] || mount -n -t proc none /proc
32 set -- $( cat /proc/cmdline )
33 for x; do
34 v="${x#*=}"
35 case "$x" in
36 root=*) root="$v" ;;
37 init=*) init="$v" ;;
38 rw|ro) mode="$x" ;;
39 modules=*) modules=$( echo "$v" | tr ',' ' ' ) ;;
40 nocolor) export NOCOLOR=yes ;;
41 initrdopt=*) for y in $( echo "$v" | tr ',' ' ' ); do
42 case "$y" in
43 mdadm) want_mdadm=yes ;;
44 mdadm=*) want_mdadm="${y#mdadm=}" ;;
45 lvm) want_lvm=yes ;;
46 lvm=*) want_lvm="${y#lvm=}" ;;
47 shell) want_shell=yes ;;
48 shell=*) want_shell="${y#shell=}" ;;
49 esac
50 done
52 esac
53 done
55 . /etc/rc.d/functions.in
57 banner "Starting Early User Space environment"
59 title "Mounting /proc and /sys"
60 check mount -n -t usbfs none /proc/bus/usb
61 check mount -n -t sysfs none /sys
62 status
64 [ -x /bin/dmesg ] && /bin/dmesg -n 3
66 title "Preparing /dev"
67 check mount -n -t tmpfs none /dev
68 check cp -a /lib/udev/devices/* /dev
69 status
71 title "Starting udev daemon"
72 echo "" > /sys/kernel/uevent_helper
73 check udevd --daemon
74 status
76 if [ -x /sbin/modprobe -a -n "$modules" ]; then
77 title "Preloading requested kernel modules"
78 for x in $modules; do
79 echo -n " $x"
80 check modprobe -q $x
81 done
82 status
85 title "Triggering coldplug"
86 check udevtrigger
87 check udevsettle
88 status
90 sleep 2
92 [ -n "$root" ] || echo "No root device defined."
94 if [ ! -e "$root" ]; then
95 if [ "$want_mdadm" = yes ]; then
96 title "Detecting possible RAID devices"
97 check mdadm -E --scan > /etc/mdadm.conf
98 status
101 if [ "$want_mdadm" != no -a -s /etc/mdadm.conf ]; then
102 # try activating software raids
103 title "Activating RAID devices"
104 modprobe -q md-mod
105 udevsettle
106 check mdadm -As --auto=yes
107 status
111 if [ ! -e "$root" ]; then
112 if [ "$want_lvm" = yes ]; then
113 title "Detecting possible LVM devices"
114 check lvm vgscan
115 status
118 if [ "$want_lvm" != no -a -d /etc/lvm/archive ]; then
119 title "Activating LVM devices"
120 modprobe -q dm_mod
121 udevsettle
122 check lvm vgchange -ay
123 status
127 if [ -n "$root" ]; then
128 udevsettle
130 # give it a second chance to appear (delay 2s)
131 [ -e "$root" ] || sleep 2;
133 if [ -e "$root" ]; then
134 /lib/udev/vol_id "$root" > /tmp/$$.vol_id
135 . /tmp/$$.vol_id
136 rm /tmp/$$.vol_id
138 title "Mounting $root (${ID_FS_TYPE:-unknown}) "
139 check mount ${ID_FS_TYPE:+-t $ID_FS_TYPE} ${mode:+-o $mode} "$root" /rootfs
140 status
141 else
142 echo "root device ($root) not found on time."
146 # wait for /sbin/init
147 while [ ! -x "/rootfs$init" ]; do
148 # one shell is enough
149 want_shell=no
150 echo -e "\nPlease mount root device on /rootfs and exit to continue."
151 /sbin/getsh
152 done
154 if [ "$want_shell" = yes ]; then
155 echo -e "\nA last-minute shell was requested, please exit to continue."
156 /sbin/getsh
159 title "Cleaning up"
160 check killall udevd
161 check mount -t none -o move /dev /rootfs/dev
162 check mount -t none -o move /sys /rootfs/sys
163 check mount -t none -o move /proc /rootfs/proc
164 status
166 exec switch_root /rootfs "$init" $initargs
167 #FIXME: what if it fails?