forked from esrlabs/northstar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_conf.sh
executable file
·289 lines (252 loc) · 6.6 KB
/
check_conf.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#!/system/bin/sh
#
# Script to check for required kernel config options
#
# The default environment is Android. To run on linux
# change the shebang above. Note that this script uses shell
# arrays and will not run on busybox sh/ash
#
# Android/Linux deltas
if [[ -d /data/local/tmp ]] ; then
loopdev_dir=/dev/block
tmpdir=/data/local/tmp
else
loopdev_dir=/dev
tmpdir=/tmp
fi
# this appears as 'device_mapper' in northstar.toml
#
# Note that the /dev/mapper/control entry can exist without
# BLK_DEV_DM being configured. This is the case with stock
# ubuntu 20.04 server
mapper_check() {
local status
find /dev | grep -q mapper
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not find device mapper in /dev"
echo "Check for CONFIG_BLK_DEV_DM and CONFIG_DM_UEVENT"
exit 1
fi
}
# this appears as 'loop_control' in northstar.toml
#
# Check for loop devices. The number is dependent on how many containers
# will be created. For testing the initial config, we check for 8
#
loop_check() {
local status
local -i i
if [[ ! -c /dev/loop-control ]] ; then
echo "Can not find /dev/loop-control"
echo "Check for CONFIG_BLK_DEV_LOOP"
exit 1
fi
i=0
while [[ $i -lt 8 ]] ; do
if [[ ! -b ${loopdev_dir}/loop${i} ]] ; then
echo "There does not appear to be at least $i loop devices"
echo -n "Verify the number of devices for the container count, "
echo "CONFIG_BLK_DEV_LOOP_MIN_COUNT"
echo
echo "Also check the location; should it be /dev/block/loop ?"
exit 1
fi
((i++))
done
}
verity_check() {
if [[ ! -e /sys/module/dm_verity ]] ; then
echo "dm verity module appears to be missing"
echo "Check CONFIG_DM_VERITY. Also enable CONFIG_DM_VERITY_FEC"
echo "The following are also required:"
echo " CONFIG_DM_CRYPT"
echo " CONFIG_DM_THIN_PROVISIONING"
echo " CONFIG_CRYPTO_SHA256"
exit 1
fi
}
fs_check() {
local status
grep -q tmpfs /proc/filesystems
status=$?
if [[ $status -ne 0 ]] ; then
echo "tmpfs does not seem to be configured"
echo "Check CONFIG_TMPFS"
exit 1
fi
grep -q squashfs /proc/filesystems
status=$?
if [[ $status -ne 0 ]] ; then
echo "squashfs does not seem to be configured"
echo "Check CONFIG_SQUASHFS"
echo "The following are also required:"
echo " CONFIG_SQUASHFS_FILE_DIRECT"
echo " CONFIG_SQUASHFS_DECOMP_MULTI"
echo " CONFIG_SQUASHFS_4K_DEVBLK_SIZE"
echo " CONFIG_SQUASHFS_XATTR"
echo " CONFIG_SQUASHFS_ZLIB"
echo " CONFIG_SQUASHFS_ZSTD"
echo " CONFIG_SQUASHFS_EMBEDDED"
echo " CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3"
exit 1
fi
}
cgroup_check() {
local status mntpoint type
local cgtypes
cgtypes=( memory pids cpuset blkio )
grep -q cgroup /proc/filesystems
status=$?
if [[ $status -ne 0 ]] ; then
echo "cgroups do not seem to be configured"
echo "Check CONFIG_CGROUPS"
exit 1
fi
mntpoint=${tmpdir}/mntpoint_$$
if [[ ! -d $mntpoint ]] ; then
mkdir $mntpoint
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not mkdir $mntpoint"
exit 1
fi
fi
for type in ${cgtypes[@]} ; do
mount -t cgroup none $mntpoint -o $type > /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not mount $type cgroup"
echo "failed: mount -t cgroup none $mntpoint -o $type "
echo "Check configuration of the following:"
echo " CONFIG_MEMCG "
echo " CONFIG_CGROUP_PIDS "
echo " CONFIG_CPUSETS "
echo " CONFIG_BLK_CGROUP "
echo " CONFIG_CGROUP_CPUACCT"
exit 1
fi
umount $mntpoint
done
/bin/rmdir $mntpoint
# explicit check for cpu cgroup because if it is already
# mounted, another mount can fail
mount | grep cgroup | grep -v cpuset | grep -q cpu
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not find cpu cgroup"
echo "Check configuration of the following:"
echo " CONFIG_CGROUP_CPUACCT"
exit 1
fi
}
namespace_check() {
local status type
local nstypes
nstypes=( net uts ipc pid user )
if [[ ! -d /proc/self/ns ]] ; then
echo "Can not query namespaces"
echo "Check configuration of CONFIG_NAMESPACES"
exit 1
fi
for type in ${nstypes[@]} ; do
if [[ ! -e /proc/self/ns/${type} ]] ; then
echo "Can not query namespace type $type"
echo "Check configuration of the following:"
echo " CONFIG_UTS_NS"
echo " CONFIG_USER_NS"
echo " CONFIG_PID_NS"
echo " CONFIG_NET_NS"
echo " CONFIG_IPC_NS"
exit 1
fi
done
}
iputil_check() {
local status
which ip > /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not find 'ip' utility. This utility is required for network setup."
echo "On Ubuntu: apt install iproute2"
exit 1
fi
which iptables > /dev/null 2>&1
status=$?
if [[ status -ne 0 ]] ; then
echo "Can not 'iptables' utility. This utility is required for network setup."
echo "On Ubuntu: apt install iptables"
exit 1
fi
}
bridge_check() {
local status
ip link add name test_bridge type bridge > /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not create network bridge"
echo "Check the configuration of the following"
echo " CONFIG_BRIDGE"
echo " CONFIG_BRIDGE_VLAN_FILTERING"
exit 1
fi
ip link del test_bridge > /dev/null 2>&1
}
veth_check() {
local status
ip netns add test_ns > /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not create network namespace"
echo "Check the configration of the following:"
echo " CONFIG_NET_NS"
exit 1
fi
ip link add test_veth type veth peer test_brveth > /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
ip netns del test_ns > /dev/null 2>&1
echo "Can not create network veth pair"
echo "Check the configuration of the following"
echo " CONFIG_MACVLAN"
echo " CONFIG_MACVTAP"
echo " CONFIG_VXLAN"
echo " CONFIG_VETH"
exit 1
fi
# This deletes both veths
ip link del test_veth > /dev/null 2>&1
ip netns del test_ns > /dev/null 2>&1
}
iptables_check() {
local status
iptables -w 30 -t nat -A POSTROUTING -s 169.254.10.0/24 -j MASQUERADE \
> /dev/null 2>&1
status=$?
if [[ $status -ne 0 ]] ; then
echo "Can not setup up masquerading in iptables"
echo "Check the configuration of the following:"
echo " CONFIG_IP_NF_IPTABLES"
echo " CONFIG_IP_NF_NAT"
echo " CONFIG_IP_NF_TARGET_MASQUERADE"
echo " CONFIG_IP_NF_MANGLE"
echo " CONFIG_IP_NF_FILTER"
echo " CONFIG_IP_NF_SECURITY"
exit 1
fi
iptables -w 30 -t nat -D POSTROUTING -s 169.254.10.0/24 -j MASQUERADE \
> /dev/null 2>&1
}
mapper_check
loop_check
verity_check
fs_check
cgroup_check
namespace_check
# The following are only required if setting up network namespaces
iputil_check
bridge_check
veth_check
iptables_check
echo "kernel is correctly configured for northstar"
exit 0