aboutsummaryrefslogtreecommitdiff
path: root/rc.boot
blob: 2ac4ee66707520ff57d450facfff507138134575 (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
108
109
110
111
112
113
114
115
116
117
#!/bin/sh
# shellcheck disable=1090,1091
# I would add 2154, but I don't want to accidentally misuse a variable name
# without noticing.

# Read the configuration file and the library of
# common functions.
. /usr/lib/init/rc.lib
[ -f /etc/init/rc.conf ] && . /etc/init/rc.conf

# Display a pretty welcome message
printf '\033[1;36m-> \033[39m%s \033[35m%s\033[39m!\033[m\n' "Welcome to" "Carbs $(uname -s)"

out "Mounting pseudo filesystems..."; {
    mnt nosuid,noexec,nodev    proc     proc /proc
    mnt nosuid,noexec,nodev    sysfs    sys  /sys
    mnt mode=0755,nosuid,nodev tmpfs    run  /run
    mnt mode=0755,nosuid       devtmpfs dev  /dev

    mkdir -p /run/lvs /run/user /run/lock \
             /run/log /dev/pts /dev/shm

    command -v runsvdir >/dev/null 2>&1 && mkdir -p 0755 /run/runit

    mnt mode=0620,gid=5,nosuid,noexec devpts devpts /dev/pts
    mnt mode=1777,nosuid,nodev        tmpfs  shm    /dev/shm

    {
        ln -sf /proc/self/fs /dev/fd
        ln -sf fd/0          /dev/stdin
        ln -sf fd/1          /dev/stdout
        ln -sf fd/2          /dev/stderr
    } 2>/dev/null
}

out "Parsing kernel commandline..."; {
    parse_cmdline
}

# shellcheck disable=2154
[ "$quiet" = 1 ] && exec >/dev/null 2>&1

[ "${dmesg_level:=$loglevel}" ] && {
    out "Setting dmesg level..."
    dmesg -n "$dmesg_level"
}

out "Starting device manager..."; {
    device_helper settle
}

out "Remounting rootfs as read-only..."; {
    mount -o remount,ro / || shell
}

# shellcheck disable=2154
[ "$fastboot" = 1 ] || {
    out "Checking filesystems..."
    fsck "-ATat${forcefsck:+-f}" noopts=_netdev 2>&1 | log
    [ $? -gt 1 ] && shell
}

# shellcheck disable=2154
[ "$ro" = "1" ] || {
    out "Mounting rootfs read-write..."
    mount -o remount,rw / || shell
}

out "Mounting all local filesystems..."; {
    mount -at nosysfs,nonfs,nonfs4,nosmbfs,nocifs -O no_netdev ||
        shell
}

run_hook early-boot

out "Enabling swap..."; {
    swapon -a || shell
}

# Load random seed
random load

out "Setting up loopback..."; {
    ip link set up dev lo
}

out "Setting hostname..."; {
    read -r hostname < /etc/hostname
    printf '%s\n' "${hostname:-carbslinux}" > /proc/sys/kernel/hostname
} 2>/dev/null

[ "$keymap" ] && {
    out "Loading keymap settings..."
    loadkmap < "$keymap"
}

out "Loading sysctl settings..."; {
    for conf in \
        /run/sysctl.d/*.conf \
        /usr/lib/sysctl.d/*.conf \
        /etc/sysctl.d/*.conf \
        /etc/sysctl.conf; do

        [ -f "$conf" ] || continue
        out "Appling $conf ..."
        sysctl -p "$conf"
    done
}


out "Stopping device manager..."; {
    device_helper exit
}

run_hook boot

out "Boot stage complete..."