aboutsummaryrefslogtreecommitdiff
path: root/skel/init
blob: db8ef66676c59cd86c6c8ed0b10f80b4757cda77 (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
30
31
32
33
34
35
#!/bin/sh

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- | tail -1
}
arg() {
    echo "$args" | grep -q "^$1$"
}
rescue() {
    echo "Entering rescue shell."
    setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'
}

root=$(var root)
if ! echo "$root" | grep -q '^/dev/';then
    root=$(findfs "$root")
fi
init=$(var init)
[ -z "$init" ] && init="/sbin/init"

fsck -p "$root" || rescue

mkdir /mnt/root
mount -o ro "$root" /mnt/root || rescue

arg rescue && rescue

umount /proc /sys /dev

exec switch_root /mnt/root "$init"