forked from Magisk-Modules-Alt-Repo/magisk_overlayfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost-fs-data.sh
125 lines (101 loc) · 3.22 KB
/
post-fs-data.sh
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
118
119
120
121
122
123
124
MODDIR="${0%/*}"
set -o standalone
export MAGISKTMP="$(magisk --path)"
chmod 777 "$MODDIR/overlayfs_system"
OVERLAYDIR="/data/adb/overlay"
OVERLAYMNT="/dev/mount_overlayfs"
MODULEMNT="/dev/mount_loop"
mv -fT /cache/overlayfs.log /cache/overlayfs.log.bak
rm -rf /cache/overlayfs.log
echo "--- Start debugging log ---" >/cache/overlayfs.log
echo "init mount namespace: $(readlink /proc/1/ns/mnt)" >>/cache/overlayfs.log
echo "current mount namespace: $(readlink /proc/self/ns/mnt)" >>/cache/overlayfs.log
mkdir -p "$OVERLAYMNT"
mkdir -p "$OVERLAYDIR"
mkdir -p "$MODULEMNT"
mount -t tmpfs tmpfs "$MODULEMNT"
loop_setup() {
unset LOOPDEV
local LOOP
local MINORX=1
[ -e /dev/block/loop1 ] && MINORX=$(stat -Lc '%T' /dev/block/loop1)
local NUM=0
while [ $NUM -lt 2048 ]; do
LOOP=/dev/block/loop$NUM
[ -e $LOOP ] || mknod $LOOP b 7 $((NUM * MINORX))
if losetup $LOOP "$1" 2>/dev/null; then
LOOPDEV=$LOOP
break
fi
NUM=$((NUM + 1))
done
}
if [ -f "$OVERLAYDIR" ]; then
loop_setup /data/adb/overlay
if [ ! -z "$LOOPDEV" ]; then
mount -o rw -t ext4 "$LOOPDEV" "$OVERLAYMNT"
ln "$LOOPDEV" /dev/block/overlayfs_loop
fi
fi
if ! "$MODDIR/overlayfs_system" --test --check-ext4 "$OVERLAYMNT"; then
echo "unable to mount writeable dir" >>/cache/overlayfs.log
exit
fi
num=0
for i in /data/adb/modules/*; do
[ ! -e "$i" ] && break;
module_name="$(basename "$i")"
if [ ! -e "$i/disable" ] && [ ! -e "$i/remove" ]; then
if [ -f "$i/overlay.img" ]; then
loop_setup "$i/overlay.img"
if [ ! -z "$LOOPDEV" ]; then
echo "mount overlayfs for module: $module_name" >>/cache/overlayfs.log
mkdir -p "$MODULEMNT/$num"
mount -o rw -t ext4 "$LOOPDEV" "$MODULEMNT/$num"
fi
num="$((num+1))"
fi
if [ "$KSU" == "true" ]; then
mkdir -p "$MODULEMNT/$num"
mount --bind "$i" "$MODULEMNT/$num"
num="$((num+1))"
fi
fi
done
OVERLAYLIST=""
for i in "$MODULEMNT"/*; do
[ ! -e "$i" ] && break;
if [ -d "$i" ] && [ ! -L "$i" ] && "$MODDIR/overlayfs_system" --test --check-ext4 "$i"; then
OVERLAYLIST="$i:$OVERLAYLIST"
fi
done
mkdir -p "$OVERLAYMNT/upper"
rm -rf "$OVERLAYMNT/worker"
mkdir -p "$OVERLAYMNT/worker"
if [ ! -z "$OVERLAYLIST" ]; then
export OVERLAYLIST="${OVERLAYLIST::-1}"
echo "mount overlayfs list: [$OVERLAYLIST]" >>/cache/overlayfs.log
fi
# overlay_system <writeable-dir>
. "$MODDIR/mode.sh"
"$MODDIR/overlayfs_system" "$OVERLAYMNT" | tee -a /cache/overlayfs.log
if [ ! -z "$MAGISKTMP" ]; then
mkdir -p "$MAGISKTMP/overlayfs_mnt"
mount --bind "$OVERLAYMNT" "$MAGISKTMP/overlayfs_mnt"
fi
umount -l "$OVERLAYMNT"
rmdir "$OVERLAYMNT"
umount -l "$MODULEMNT"
rmdir "$MODULEMNT"
rm -rf /dev/.overlayfs_service_unblock
echo "--- Mountinfo (post-fs-data) ---" >>/cache/overlayfs.log
cat /proc/mounts >>/cache/overlayfs.log
(
# block until /dev/.overlayfs_service_unblock
while [ ! -e "/dev/.overlayfs_service_unblock" ]; do
sleep 1
done
rm -rf /dev/.overlayfs_service_unblock
echo "--- Mountinfo (late_start) ---" >>/cache/overlayfs.log
cat /proc/mounts >>/cache/overlayfs.log
) &