Skip to content

Commit c1cff5a

Browse files
committed
mi-bug-report: Allow to use kernel modules from the host system
Signed-off-by: Alexey Gladkov <[email protected]>
1 parent c2fb472 commit c1cff5a

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

utils/mi-bug-report

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ show_help() {
2727
Usage: $PROG [<option>] <report-archive> [<command> [<args>]]
2828
2929
Options:
30-
-v, --verbose print a message for each action;
31-
-V, --version output version information and exit;
32-
-h, --help display this help and exit.
30+
-k, --set-version=VERSION use kernel VERSION.
31+
-v, --verbose print a message for each action;
32+
-V, --version output version information and exit;
33+
-h, --help display this help and exit.
3334
3435
Report bugs to authors.
3536
@@ -38,12 +39,17 @@ show_help() {
3839
}
3940

4041
if [ -z "${__BUG_REPORT-}" ]; then
41-
TEMP=`getopt -n "$PROG" -o 'h,v,V' -l 'help,verbose,version' -- "$@"` ||
42+
TEMP=`getopt -n "$PROG" -o 'k:,h,v,V' -l 'set-version:,help,verbose,version' -- "$@"` ||
4243
show_usage
4344
eval set -- "$TEMP"
4445

46+
kver=
47+
4548
while :; do
4649
case "$1" in
50+
-k|--set-version) shift
51+
kver="$1"
52+
;;
4753
-h|--help)
4854
show_help
4955
;;
@@ -84,7 +90,7 @@ if [ -z "${__BUG_REPORT-}" ]; then
8490

8591
verbose "making new namespace ..."
8692

87-
export verbose
93+
export verbose kver
8894
export __BUG_REPORT=1
8995
export __BUG_REPORT_ARCHIVE="$archive"
9096
export __BUG_REPORT_PWD="$PWD"
@@ -161,6 +167,11 @@ else
161167
[ -f etc/initrd.mk ] || printf > etc/initrd.mk 'AUTODETECT = all\n'
162168
}
163169

170+
if [ -n "$kver" ]; then
171+
mkdir -p -- "/tmp/_$kver"
172+
mount --bind "/lib/modules/$kver" "/tmp/_$kver"
173+
fi
174+
164175
# We overlap the system directories with prepared directories from the
165176
# bug report.
166177
find . -mindepth 1 -maxdepth 1 -type d -printf './%f /%f\n' |
@@ -183,6 +194,11 @@ else
183194
mount $verbose --rbind "$src" "$dst"
184195
done
185196

197+
if [ -n "$kver" ]; then
198+
mkdir -p -- "/lib/modules/$kver"
199+
mount --move "/tmp/_$kver" "/lib/modules/$kver"
200+
fi
201+
186202
mkdir -p -- "$workdir"/bin
187203
cat > "$workdir"/bin/procfs <<-'EOF'
188204
#!/bin/bash -efu
@@ -209,9 +225,11 @@ else
209225
alias l='ls -la'
210226
EOF
211227

212-
[ -d lib/modules ] &&
213-
kver=$(find lib/modules/ -mindepth 1 -maxdepth 1 -printf '%f' -quit ||:) ||
214-
kver=$(uname -r)
228+
if [ -z "$kver" ]; then
229+
[ -d lib/modules ] &&
230+
kver=$(find lib/modules/ -mindepth 1 -maxdepth 1 -printf '%f' -quit ||:) ||
231+
kver=$(uname -r)
232+
fi
215233

216234
kmodules="$(find "/lib/modules/$kver/kernel" -name '*.ko*' -print -quit 2>/dev/null ||:)"
217235
[ -n "$kmodules" ] ||

0 commit comments

Comments
 (0)