Skip to content

Instantly share code, notes, and snippets.

@lpenz
Last active April 22, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpenz/4db6f92d8c22935b139d1854648089b7 to your computer and use it in GitHub Desktop.
Save lpenz/4db6f92d8c22935b139d1854648089b7 to your computer and use it in GitHub Desktop.
Script that creates a bootable qcow2 img with a directory's contents - installs mbr and extlinux
#!/bin/bash
DIR=${1?usage: $0 <dir> <img>}
OUT=${2?usage: $0 <dir> <img>}
set -e -x
rm -f "$OUT"
trap 'rm -f $OUT' EXIT INT
virt-make-fs --partition=mbr --type=ext3 --format=raw --size=+300M "$DIR" "$OUT"
guestfish -a "$OUT" <<END
launch
mount /dev/sda1 /
part-set-bootable /dev/sda 1 true
extlinux /boot
copy-file-to-device /usr/lib/extlinux/mbr.bin /dev/sda
END
trap '' EXIT INT
if [ -n "$SUDO_USER" ]; then
chown "$SUDO_USER:$SUDO_USER" "$OUT"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment