summaryrefslogtreecommitdiff
path: root/init
blob: 80bee3cfeecc9d061862911d78cd5453d9ec4492 (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
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
trap 'exec /bin/sh' INT EXIT

# We need proc for reading the kernel command line
mount -n -t proc none /proc

set -- $(cat /proc/cmdline)

# We don't want to leave mount points around
umount /proc

for arg; do
    case "$arg" in
    root=LABEL=*)
        if [ x"$root_type" != x ]; then
            echo "Warning, multiple root= specified, using latest."
        fi
        root_type=label
        root="${arg#root=LABEL=}"
        ;;
    root=UUID=*)
        if [ x"$root_type" != x ]; then
            echo "Warning, multiple root= specified, using latest."
        fi
        root_type=uuid
        root="${arg#root=UUID=}"
        ;;
    root=*)
        if [ x"$root_type" != x ]; then
            echo "Warning, multiple root= specified, using latest."
        fi
        root_type=disk
        root="${arg#root=}"
        ;;
    rootflags=*)
        if [ x"$rootflags" != x ]; then
            echo "Warning, multiple rootflags= specified, using latest."
        fi
        rootflags=",${arg#rootflags=}"
        ;;
    rootfstype=*)
        if [ x"$rootflags" != x ]; then
            echo "Warning, multiple rootfstype= specified, using latest."
        fi
        rootfstype="${arg#rootfstype=}"
        ;;
    rootdelay=*)
        if [ x"$rootflags" != x ]; then
            echo "Warning, multiple rootdelay= specified, using latest."
        fi
        rootfstype="${arg#rootdelay=}"
        ;;
    ro)
        ro=ro
        ;;
    rw)
        ro=rw
        ;;
    init=*)
        init="${arg#init=}"
        ;;
    esac
done

if [ x"$rootdelay" != x ]; then
    sleep "$rootdelay"
fi

if [ x"$rootfstype" = x ]; then
    # Warn that busybox may not be able to auto-detect rootfs type
    cat <<\EOF
Warning, rootfs type not specified, auto-detection of type is slow and
may fail. Please add rootfstype=$type to kernel command line.
EOF
fi

mount -n -t devtmpfs devtmpfs /dev
case "$root_type" in
disk)
    mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$root" /mnt
    ;;
label)
    disk="$(findfs LABEL="$root")"
    if [ x"$disk" = x ]; then
        echo disk with label $root not found
        blkid
        exit 1
    fi
    mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$disk" /mnt
    ;;
uuid)
    disk="$(findfs UUID="$root")"
    if [ x"$disk" = x ]; then
        echo disk with UUID $root not found
        blkid
        exit 1
    fi
    mount -n -t "${rootfstype}" -o "${ro-rw}""$rootflags" "$disk" /mnt
    ;;
'')
    echo "Error, no root specified"
    exit 1
    ;;
esac
umount -n /dev

exec switch_root -c /dev/console /mnt "${init-/sbin/init}"