summaryrefslogtreecommitdiff
path: root/packages/initrdscripts/files/init.sh
blob: 8c9803f21b014f52528ac58818b6b98b7ff40c4f (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
#!/bin/sh

MODULE_DIR=/initrd.d
BOOT_ROOT=
ROOT_DEVICE=/dev/null

early_setup() {
    mkdir /proc
    mount -t proc proc /proc
    mkdir /mnt

    echo -n "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() {
    CMDLINE=`cat /proc/cmdline`
    for arg in $CMDLINE; do
        optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
        case $arg in
            root=*)
                ROOT_DEVICE=$optarg ;;
            rootdelay=*)
                rootdelay=$optarg ;;
        esac
    done
}

load_modules() {
    for module in $MODULE_DIR/*; do
        source $module
    done
}

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

boot_failed() {
    echo "No valid root device was specified.  Please add root=/dev/something to"
    echo "the kernel command-line and try again."
    echo
    exec sh
}

echo "Starting initramfs boot..."
early_setup
read_args

if [ -n "$rootdelay" ]; then
    echo "Waiting $rootdelay seconds for devices to settle..."
    sleep $rootdelay
fi

load_modules
[ -n "$BOOT_ROOT" ] && boot_root
boot_failed