Last active
April 22, 2019 16:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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