merge of '178eac00dc5aa8338d42e8e203633bec7817bbf6'
[vuplus_openembedded] / packages / initrdscripts / files / init.sh
1 #!/bin/sh
2
3 MODULE_DIR=/initrd.d
4 BOOT_ROOT=
5 ROOT_DEVICE=
6
7 early_setup() {
8     mkdir /proc
9     mount -t proc proc /proc
10     mkdir /mnt
11     modprobe -q mtdblock
12 }
13
14 dev_setup()
15 {
16     echo -n "initramfs: Creating device nodes: "
17     grep '^ *[0-9]' /proc/partitions | while read major minor blocks dev
18     do
19         if [ ! -e /dev/$dev ]; then
20             echo -n "$dev "
21             [ -e /dev/$dev ] || mknod /dev/$dev b $major $minor
22         fi
23     done
24     echo
25 }
26
27 read_args() {
28     [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
29     for arg in $CMDLINE; do
30         optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
31         case $arg in
32             root=*)
33                 ROOT_DEVICE=$optarg ;;
34             rootfstype=*)
35                 ROOT_FSTYPE=$optarg ;;
36             rootdelay=*)
37                 rootdelay=$optarg ;;
38         esac
39     done
40 }
41
42 load_modules() {
43     for module in $MODULE_DIR/$1; do
44         # Cannot redir to $CONSOLE here easily - may not be set yet
45         echo "initramfs: Loading $module module"
46         source $module
47     done
48 }
49
50 boot_root() {
51     cd $BOOT_ROOT
52     exec switch_root -c /dev/console $BOOT_ROOT /sbin/init
53 }
54
55 fatal() {
56     echo $1 >$CONSOLE
57     echo >$CONSOLE
58     exec sh
59 }
60
61
62 echo "Starting initramfs boot..."
63 early_setup
64 load_modules '0*'
65
66 [ -z "$CONSOLE" ] && CONSOLE="/dev/console"
67
68 read_args
69
70 if [ -z "$rootdelay" ]; then
71     echo "rootdelay parameter was not passed on kernel command line - assuming 2s delay"
72     echo "If you would like to avoid this delay, pass explicit rootdelay=0"
73     rootdelay="2"
74 fi
75 if [ -n "$rootdelay" ]; then
76     echo "Waiting $rootdelay seconds for devices to settle..." >$CONSOLE
77     sleep $rootdelay
78 fi
79
80 dev_setup
81
82 load_modules '[1-9]*'
83
84 [ -n "$BOOT_ROOT" ] && boot_root
85
86 fatal "No valid root device was specified.  Please add root=/dev/something to the kernel command-line and try again."