-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit
executable file
·117 lines (99 loc) · 2.35 KB
/
init
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
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
shell() {
setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'
}
problem() {
msg "Encountered a problem, dropping you to a shell."
shell
}
msg() {
[ "$quiet" = y ] && return
echo ":: $*"
}
mount_root() {
mkdir $newroot
if [ ! "$device" ]; then
msg "device not scpecified!"
problem
fi
while [ ! -b "$device" ] ; do
no_device $device
problem
done
if ! mount -n ${rootfstype:+-t $rootfstype} -o ${rwopt:-ro}${rootflags:+,$rootflags} "$device" "$newroot" ; then
msg "failed mount root device: $device"
shell
fi
}
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" ;;
PARTUUID=*) eval $root; device="/dev/disk/by-partuuid/$PARTUUID" ;;
LABEL=* ) eval $root; device="/dev/disk/by-label/$LABEL" ;;
esac
}
init=/sbin/init
root=
newroot=/.root
rootdelay=
rootfstype=auto
ro="ro"
rootflags=
device=
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
parse_cmdline
if [ "$break" = y ] || [ "$break" = pre-mount ]; then
msg "break pre-mount requested."
shell
fi
# run hook
if [ -f /runhook.order ]; then
for hook in $(cat /runhook.order); do
if [ -f /etc/mkinitrd.d/$hook.run ]; then
msg "running run hook: $hook"
. /etc/mkinitrd.d/$hook.run
fi
done
fi
# mount root device is root is set
if [ "$root" ]; then
msg "mounting root: $root"
mount_root
fi
# run cleanup hook
if [ -f /cleanuphook.order ]; then
for hook in $(tac /cleanuphook.order); do
if [ -f /etc/mkinitrd.d/$hook.cleanup ]; then
msg "running cleanup hook: $hook"
. /etc/mkinitrd.d/$hook.cleanup
fi
done
fi
if [ ! -d "$newroot" ] || [ ! "$(mountpoint $newroot)" ]; then
msg "seems no root device mounted on newroot."
problem
fi
mount --move /proc $newroot/proc
mount --move /sys $newroot/sys
mount --move /dev $newroot/dev
mount --move /run $newroot/run
exec switch_root $newroot "$init" "$@"