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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#!/bin/sh
# /etc/runit/1 - krypt/sh system boot
PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH
msg() {
printf '\033[1m%s\033[0m\n' "$1"
}
err() {
printf '\033[1;31m%s\033[0m\n' "$1" >&2
}
emergency_shell() {
err "Dropping to emergency shell. Type 'exit' to reboot."
sulogin -p
printf '%s\n' "Rebooting..."
umount -a -r
mount -o remount,ro /
reboot -f
exit 0
}
printf '%s\n' "rawnix is starting..."
msg "Mounting /proc..."
mountpoint -q /proc || mount -t proc proc /proc
msg "Mounting /sys..."
mountpoint -q /sys || mount -t sysfs sysfs /sys
msg "Mounting /run..."
mountpoint -q /run || mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run
msg "Mounting /dev..."
if ! mountpoint -q /dev; then
mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev
else
mount -o remount,mode=0755,nosuid devtmpfs /dev
fi
msg "Mounting /dev/pts..."
mkdir -m 755 -p /dev/pts
mountpoint -q /dev/pts || mount -t devpts -o gid=tty,mode=0620,noexec,nosuid devpts /dev/pts
msg "Mounting /dev/shm..."
mkdir -m 1777 -p /dev/shm
mountpoint -q /dev/shm || mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /dev/shm
msg "Mounting cgroups v2..."
if ! mountpoint -q /sys/fs/cgroup; then
mount -t cgroup2 none /sys/fs/cgroup 2>/dev/null ||
err "cgroup2 mount failed - containers will not work"
fi
# Bootstrap udevd for coldplug; sv/udevd takes over in stage 2
msg "Starting udevd..."
if udevd --daemon 2>/dev/null; then
msg "Triggering udev coldplug..."
udevadm trigger --type=subsystems --action=add
udevadm trigger --type=devices --action=add
msg "Waiting for udev to settle..."
udevadm settle --timeout=30 || err "Timeout waiting for udev events"
else
err "udevd not available - continuing without hotplug"
fi
msg "Bringing up loopback..."
ip addr add 127.0.0.1/8 dev lo 2>/dev/null
ip link set lo up 2>/dev/null
# LUKS volumes
if [ -x /sbin/cryptsetup ] && [ -f /etc/crypttab ]; then
msg "Opening LUKS volumes..."
while IFS= read -r line; do
case "$line" in ''|\#*) continue ;; esac
name="${line%% *}"
rest="${line#* }"
device="${rest%% *}"
cryptsetup open "$device" "$name" || err "Failed to open LUKS volume: $name"
done < /etc/crypttab
fi
msg "Remounting / read-only..."
mount -o remount,ro /
if [ -f /forcefsck ]; then
msg "Forced filesystem check..."
FORCEFSCK="-f"
fi
msg "Checking filesystems..."
fsck $FORCEFSCK -A -T -C -a 2>/dev/null
if [ $? -gt 1 ]; then
err "Filesystem check failed!"
err "Please repair manually. Root is mounted read-only."
err "To remount read-write: mount -n -o remount,rw /"
emergency_shell
fi
msg "Remounting / read-write..."
mount -o remount,rw /
msg "Seeding urandom..."
if [ -f /var/lib/random/seed ]; then
cat /var/lib/random/seed >/dev/urandom
rm -f /var/lib/random/seed
fi
msg "Setting shared mount propagation..."
mount --make-rshared /
msg "Activating swap..."
swapon -a 2>/dev/null
msg "Mounting local filesystems..."
mount -a -O no_netdev 2>/dev/null || emergency_shell
mkdir -m 0755 -p /run/user
mkdir -m 1777 -p /run/lock
: >/run/utmp
rm -rf /forcefsck /fastboot /etc/nologin /etc/shutdownpid 2>/dev/null
rm -rf /tmp/* /tmp/.* 2>/dev/null
if [ -x /etc/rc.modules ]; then
msg "Loading kernel modules..."
/etc/rc.modules
fi
if [ -f /etc/sysctl.conf ]; then
msg "Setting kernel parameters..."
sysctl -p >/dev/null 2>&1
fi
if [ -f /etc/hostname ]; then
msg "Setting hostname: $(cat /etc/hostname)"
hostname "$(cat /etc/hostname)"
fi
hwclock --hctosys 2>/dev/null
[ -x /etc/rc.local ] && /etc/rc.local
touch /etc/runit/stopit
chmod 100 /etc/runit/stopit
touch /etc/runit/reboot
chmod 100 /etc/runit/reboot
dmesg > /var/log/boot.log 2>/dev/null
msg "Boot complete."
exit 0
|