aboutsummaryrefslogtreecommitdiff
path: root/skel/init
blob: e3b295eb5a6ec02dd797312c62e02cdb6a43f054 (plain) (blame)
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
#!/bin/sh

touch /proc/mounts
mount -t proc proc /proc
mount -t devtmpfs devtmpfs /dev
mount -t sysfs sysfs /sys

args=$(tr ' ' '\n' < /proc/cmdline)
var() {
    echo "$args" | grep "^$1=" | cut -d= -f2
}
arg() {
    echo "$args" | grep -q "^$1$"
}
rescue() {
    sh
}

root=$(var root)
init=$(var init)
[ -z "$init" ] && init="/sbin/init"

fsck -p "$root" || rescue

mount -o ro $(findfs "$root") /mnt/root || rescue

umount /proc /sys /dev

exec switch_root /mnt/root "$init"