generated from Zackptg5/MMT-Extended
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup-cgroups.sh
executable file
·53 lines (47 loc) · 1.39 KB
/
setup-cgroups.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
MOUNT_CGROUP_SYSTEMD=true
ln_cg() {
local src=$1
local scg="/sys/fs/cgroup/${2}"
if [ -d "${src}" ] && [ ! -e "${scg}" ]; then
ln -s "${src}" "${scg}"
fi
}
mount_cg() {
local cg=$1
local opts=$2
local real_cg=$(realpath /sys/fs/cgroup/${cg})
if [ ! -d "/sys/fs/cgroup/${cg}" ]; then
mkdir -p "/sys/fs/cgroup/${cg}"
fi
if ! mountpoint -q ${real_cg}; then
mount -t cgroup -o "${opts}" cgroup "${real_cg}"
fi
}
setup_cg() {
# setup cgroup v1
if ! mountpoint -q /sys/fs/cgroup; then
mount -t tmpfs -o rw,mode=755,nodev,noexec,nosuid tmpfs /sys/fs/cgroup
else
mount -o remount,rw /sys/fs/cgroup
fi
# termux lxc,docker declares that they need these
ln_cg /acct cpuacct
ln_cg /dev/blkio blkio
ln_cg /dev/cg2_bpf cg2_bpf
ln_cg /dev/cpuctl cpu
ln_cg /dev/cpuset cpuset
ln_cg /dev/freezer freezer
ln_cg /dev/memcg memory
ln_cg /dev/stune schedtune
# if those cgroups are not mounted, mount them
for cg in blkio cpu cpuacct cpuset devices freezer memory pids schedtune; do
mount_cg ${cg} ${cg}
done
# mount systemd cgroup
$MOUNT_CGROUP_SYSTEMD &&
mount_cg systemd "none,nosuid,nodev,noexec,relatime,xattr,name=systemd"
# make cgroup read-only
mount -o remount,ro /sys/fs/cgroup
}
# main
[ $(stat -f -c %T /sys/fs/cgroup) != "cgroup2fs" ] && setup_cg