Created
December 8, 2016 08:55
-
-
Save ljjjustin/39cd68fc53a15bcf0a898a2d85e60506 to your computer and use it in GitHub Desktop.
modify qcow2 image using qemu-nbd
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 | |
if [ $# -ne 1 ]; then | |
echo "usage: $0 <qcow2 image>" | |
exit | |
fi | |
image=$1 | |
target=$(mktemp -d) | |
cleanup_on_exit() { | |
exit_code=$? | |
umount $target && rm -fr $target | |
qemu-nbd --disconnect /dev/nbd0 | |
exit $exit_code | |
} | |
trap "cleanup_on_exit" EXIT | |
setup() { | |
qemu-nbd --connect=/dev/nbd0 $image | |
mkdir -p $target | |
mount /dev/nbd0p1 $target | |
chroot $target | |
} | |
setup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment