-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent-modules-overlay.sh
More file actions
executable file
·48 lines (40 loc) · 1.91 KB
/
current-modules-overlay.sh
File metadata and controls
executable file
·48 lines (40 loc) · 1.91 KB
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
#!/bin/bash
function die {
msg="$1"
shift
printf "$msg\n" "$@" 1>&2
exit 1
}
module_base_dir="$(pkg-config --variable module_directory kmod 2>/dev/null)"
: ${module_base_dir:=/lib/modules}
if ! [[ "$module_base_dir" =~ ^/ ]]; then
die 'Module directory "%s" was not an absolute path' "$module_base_dir"
fi
if mountpoint -q "$module_base_dir"; then
# if the overlay already exists, assume it's set up properly and succeed without doing any work
exit 0
fi
if [[ "$module_base_dir" =~ [=,:] ]]; then
die 'Module directory "%s" contains a special character, and cannot be overlay mounted' "$module_base_dir"
fi
tmpfs_dir="$module_base_dir/../current-modules"
if ! mountpoint -q "$tmpfs_dir"; then
die 'The current modules tmpfs is not mounted at "%s"' "$tmpfs_dir"
fi
kernel_version="$(uname -r 2>/dev/null)"
if [[ -n "$kernel_version" ]]; then
current_modules_dir="$module_base_dir/$kernel_version"
# Remove any whiteout file so the current modules will show up
if [[ -c "$current_modules_dir" ]] && [[ "$(stat -c '%r' "$current_modules_dir")" = "0" ]]; then
rm "$current_modules_dir"
fi
fi
overlay_workdir="$module_base_dir/../current-modules-workdir"
mkdir -p "$overlay_workdir" || exit $?
# Concatenation is safe because we know module_base_dir starts with a slash
tmpfs_module_base_dir="$tmpfs_dir$module_base_dir"
# The overlayfs module may not be loaded, so attempt to load it from the current module tmpfs. Failure is not fatal; the real test is if mount works.
modprobe -d "$tmpfs_dir" overlay
# The overlayfs documentation says "Offline changes to the lower tree are only allowed if the “metacopy”, “index”, “xino” and “redirect_dir” features have not been used", so disable all of those features
mount -t overlay -o "metacopy=off,index=off,xino=off,redirect_dir=off,lowerdir=$tmpfs_module_base_dir,upperdir=$module_base_dir,workdir=$overlay_workdir" current-modules-overlay "$module_base_dir" || exit $?
exit 0