Skip to content

Commit b8d707d

Browse files
committed
First pass at a script
1 parent 61945f2 commit b8d707d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -ueo pipefail
3+
4+
if [ $# -ne 2 ] || [ ! -d $1 ]; then
5+
printf "Usage ./$0 <modules dir> <output file>" 1>&2
6+
exit 1
7+
fi
8+
9+
if [ -e $2 ]; then
10+
printf "Refusing to overwrite existing file $2" 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=$(sudo losetup --find --show "$tmp_dir/modules.img")
27+
sudo mkfs -t ext4 "$lo_dev"
28+
mkdir "$tmp_dir/modules_img"
29+
sudo mount "$lo_dev" "$tmp_dir/modules_img"
30+
sudo chmod a+rw "$tmp_dir/modules_img"
31+
32+
# Copy over the contents of $1
33+
cp -r "$1"/* "$tmp_dir/modules_img"
34+
sudo umount "$tmp_dir/modules_img"
35+
36+
# Do the final conversion
37+
qemu-img convert -O vhdx "$tmp_dir/modules.img" "$2"
38+

0 commit comments

Comments
 (0)