Skip to content

Commit a55b23f

Browse files
committed
Merge feature/wsl-module-script/6.6 into v6.6.87
* commit 'c313d7377ddbf534848625cce7f175389e553e48': Fix the structure of the generated VHDX Fix shellcheck issues Expect script to be running as root/under sudo First pass at a script
2 parents ddda429 + c313d73 commit a55b23f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -ueo pipefail
3+
4+
if [ $# -ne 3 ] || [ ! -d "$1" ]; then
5+
printf '%s' "Usage ./$0 <modules dir> <kernelversion> <output file>" 1>&2
6+
exit 1
7+
fi
8+
9+
if [ -e "$3" ]; then
10+
printf '%s' "Refusing to overwrite existing file $3" 1>&2
11+
exit 2
12+
fi
13+
14+
15+
# Calculate modules size (+ 256MiB for slack)
16+
modules_size=$(du -bs "$1" | awk '{print $1;}')
17+
modules_size=$((modules_size + (256*(1<<20))))
18+
19+
# Create our scratch directory
20+
tmp_dir=$(mktemp -d)
21+
22+
# Create a blank image file of the right size
23+
dd if=/dev/zero of="$tmp_dir/modules.img" bs=1024 count=$((modules_size / 1024))
24+
25+
# Set up fs and mount
26+
lo_dev=$(losetup --find --show "$tmp_dir/modules.img")
27+
mkfs -t ext4 "$lo_dev"
28+
mkdir "$tmp_dir/modules_img"
29+
mount "$lo_dev" "$tmp_dir/modules_img"
30+
chmod a+rw "$tmp_dir/modules_img"
31+
32+
# Copy over the contents of $1
33+
cp -r "$1/lib/modules/$2"/* "$tmp_dir/modules_img"
34+
umount "$tmp_dir/modules_img"
35+
36+
# Do the final conversion
37+
qemu-img convert -O vhdx "$tmp_dir/modules.img" "$3"
38+
39+
# Fix ownership since we're probably running under sudo
40+
if [ -n "$SUDO_USER" ]; then
41+
chown "$SUDO_USER:$SUDO_USER" "$3"
42+
fi
43+

0 commit comments

Comments
 (0)