-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathinit.in
executable file
·116 lines (97 loc) · 2.3 KB
/
init.in
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
#!/bin/sh
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
shell() {
setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'
}
problem() {
echo "problem occurs, here's a shell."
shell
}
msg() {
[ "$verbose" = y ] || return
echo ":: $*"
}
mount_setup() {
mount -t proc proc /proc -o nosuid,noexec,nodev
mount -t sysfs sys /sys -o nosuid,noexec,nodev
mount -t devtmpfs dev /dev -o mode=0755,nosuid
mount -t tmpfs run /run -o nosuid,nodev,mode=0755
}
move_mount_setup() {
mount --move /proc /newroot/proc
mount --move /sys /newroot/sys
mount --move /dev /newroot/dev
mount --move /run /newroot/run
}
parse_cmdline() {
read -r cmdline < /proc/cmdline
for param in $cmdline ; do
case $param in
*=*) key=${param%%=*}; value=${param#*=} ;;
'#'*) break ;;
*) key=$param
esac
case $key in
ro|rw) rwopt=$key ;;
[![:alpha:]_]*|[[:alpha:]_]*[![:alnum:]_]*) ;;
*) eval "$key"=${value:-y} ;;
esac
unset key value
done
case "$root" in
/dev/* ) device=$root ;;
UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID" ;;
LABEL=*) eval $root; device="/dev/disk/by-label/$LABEL" ;;
esac
}
mount_root() {
newroot=$1
if [ ! "$device" ]; then
echo "device not scpecified!"
shell
fi
if ! mount -n ${rootfstype:+-t $rootfstype} -o ${rwopt:-ro}${rootflags:+,$rootflags} "$device" "$newroot" ; then
echo "cant mount: $device"
shell
fi
}
run_hook() {
stage=$1
if [ -f /hook/hook.order ]; then
case $stage in
cleanup) sed '1!G;h;$!d' /hook/hook.order > /hook/hook.orderreverse
mv /hook/hook.orderreverse /hook/hook.order ;;
esac
while read -r line; do
. /hook/$line
if [ "$(command -v run_${stage}hook)" ]; then
msg "running ${stage}hook: $line"
run_${stage}hook
fi
unset -f run_earlyhook run_latehook run_cleanuphook build_hook
done < /hook/hook.order
fi
unset stage line
}
mount_handler=mount_root
init=/sbin/init
rootfstype=auto
mount_setup
parse_cmdline
run_hook early
if [ "$break" = "premount" ] || [ "$break" = "y" ]; then
echo "break on pre-mount requested"
echo "exit this shell to continue booting"
shell
fi
$mount_handler /newroot
run_hook late
run_hook cleanup
if [ "$break" = "postmount" ]; then
echo "break on post-mount requested"
echo "exit this shell to continue booting"
shell
fi
move_mount_setup
exec switch_root /newroot "$init" "$@"
problem