summaryrefslogtreecommitdiff
path: root/recipes/initrdscripts/files/init.sh
blob: 221b8f56b909c40ccb9e1fdee4cb593f8e277fa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh

MODULE_DIR=/initrd.d
BOOT_ROOT=
ROOT_DEVICE=

early_setup() {
    mkdir /proc
    mount -t proc proc /proc
    mkdir /mnt
    modprobe -q mtdblock
}

dev_setup()
{
    echo -n "initramfs: Creating device nodes: "
    grep '^ *[0-9]' /proc/partitions | while read major minor blocks dev
    do
        if [ ! -e /dev/$dev ]; then
            echo -n "$dev "
            [ -e /dev/$dev ] || mknod /dev/$dev b $major $minor
        fi
    done
    echo
}

read_args() {
    [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
    for arg in $CMDLINE; do
        optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
        case $arg in
            root=*)
                ROOT_DEVICE=$optarg ;;
            rootfstype=*)
                ROOT_FSTYPE=$optarg ;;
            rootdelay=*)
                rootdelay=$optarg ;;
            debug) set -x ;;
            shell) sh ;;
        esac
    done
}

do_depmod() {
	[ -e "/lib/modules/$(uname -r)/modules.dep" ] || depmod
}

load_module() {
    # Cannot redir to $CONSOLE here easily - may not be set yet
    echo "initramfs: Loading $module module"
    source $1
}

load_modules() {
    for module in $MODULE_DIR/$1; do
        [ -e "$module"  ] && load_module $module
    done
}

boot_root() {
    cd $BOOT_ROOT
    exec switch_root -c /dev/console $BOOT_ROOT /sbin/init
}

fatal() {
    echo $1 >$CONSOLE
    echo >$CONSOLE
    exec sh
}


echo "Starting initramfs boot..."
early_setup
load_modules '0*'
do_depmod

[ -z "$CONSOLE" ] && CONSOLE="/dev/console"

read_args

if [ -z "$rootdelay" ]; then
    echo "rootdelay parameter was not passed on kernel command line - assuming 2s delay"
    echo "If you would like to avoid this delay, pass explicit rootdelay=0"
    rootdelay="2"
fi
if [ -n "$rootdelay" ]; then
    echo "Waiting $rootdelay seconds for devices to settle..." >$CONSOLE
    sleep $rootdelay
fi

dev_setup

load_modules '[1-9]*'

[ -n "$BOOT_ROOT" ] && boot_root

fatal "No valid root device was specified.  Please add root=/dev/something to the kernel command-line and try again."