File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -ueo pipefail
3+
4+ if [ $# -ne 2 ] || [ ! -d " $1 " ]; then
5+ printf ' %s' " Usage ./$0 <modules dir> <output file>" 1>&2
6+ exit 1
7+ fi
8+
9+ if [ -e " $2 " ]; then
10+ printf ' %s' " 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=$( 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 " /* " $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" " $2 "
38+
39+ # Fix ownership since we're probably running under sudo
40+ if [ -n " $SUDO_USER " ]; then
41+ chown " $SUDO_USER :$SUDO_USER " " $2 "
42+ fi
43+
You can’t perform that action at this time.
0 commit comments