-
Notifications
You must be signed in to change notification settings - Fork 48
/
S01mountall
executable file
·98 lines (83 loc) · 2.8 KB
/
S01mountall
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
#!/bin/bash
test -n "${OS_VERSION}" || source /etc/init.d/base
function mount_fs() {
msg_begin "Mounting filesystems"
/bin/mount -T /tmp/fstab.disk -a &&
/bin/mount -T /tmp/fstab.extra -a &&
if [[ -r /data/etc/fstab.user ]]; then /bin/mount -T /data/etc/fstab.user -a; fi
test $? == 0 && msg_done || msg_fail
}
function mount_overlay() {
modprobe overlay &>/dev/null
grep -qw overlay /proc/filesystems || return
msg_begin "Mounting overlay filesystems"
grep -oE 'lowerdir=[^,]+' /tmp/fstab.overlay | cut -d '=' -f 2 | xargs -r mkdir -p
grep -oE 'upperdir=[^,]+' /tmp/fstab.overlay | cut -d '=' -f 2 | xargs -r mkdir -p
grep -oE 'workdir=[^ ]+' /tmp/fstab.overlay | cut -d '=' -f 2 | xargs -r mkdir -p
cat /tmp/fstab.overlay | grep -vE '^#' | while read line; do
parts=(${line})
test ${#parts[@]} -ge 4 || continue
fs=${parts[0]}
mp=${parts[1]}
type=${parts[2]}
opts=${parts[3]}
# Add index/metacopy options are only available after kernel 4.19
if echo -e "$(uname -r)\n4.19.0" | semver-sort | head -n 1 | grep -q 4.19.0; then
opts+=",index=off,metacopy=off"
fi
/bin/mount -t ${type} -o ${opts} ${fs} ${mp}
done
test $? == 0 && msg_done || msg_fail
}
function mount_cgroupfs() {
kernel_maj_ver=$(uname -r | cut -d . -f 1)
if [[ ${kernel_maj_ver} -ge 5 ]]; then
/bin/mount -t cgroup2 cgroup2 /sys/fs/cgroup
else
/usr/bin/cgroupfs-mount
fi
}
function install_factory_defaults() {
if [[ -s /boot/factory-defaults.tar.xz ]]; then
msg_begin "Installing factory defaults"
xzcat /boot/factory-defaults.tar.xz | tar --no-same-owner -mx -C /data
sync
msg_done
fi
}
function remount_rw() {
msg_begin "Remounting boot partition read-write"
mount -o remount,rw /boot
test $? == 0 && msg_done || msg_fail
msg_begin "Remounting root partition read-write"
mount -o remount,rw /
test $? == 0 && msg_done || msg_fail
}
function mk_tty_login() {
console=$(grep -oE 'console=[a-zA-Z0-9_/-]+' /proc/cmdline | cut -d = -f 2)
if [[ -z "${console}" ]]; then console=/dev/console; fi
if ! [[ ${console} == /* ]]; then console=/dev/${console}; fi
ln -sf ${console} /dev/ttylogin
}
case "$1" in
start)
mount_fs
mount_overlay
if [[ -f /data/.install_factory_defaults ]]; then
rm /data/.install_factory_defaults
install_factory_defaults
fi
mount_cgroupfs 2>/dev/null
# we need to source conf again, now that /data is available
source /etc/init.d/os_conf
test "${OS_DEBUG}" == "true" && remount_rw
mk_tty_login
;;
stop)
true
;;
*)
echo "Usage: $0 {start}"
exit 1
esac
exit $?