Skip to content

Instantly share code, notes, and snippets.

@ikemo3
Created April 21, 2018 08:14
Show Gist options
  • Save ikemo3/afe577adc928a76a55151e90c15fae70 to your computer and use it in GitHub Desktop.
Save ikemo3/afe577adc928a76a55151e90c15fae70 to your computer and use it in GitHub Desktop.
virtual machine image to tarball.
#!/bin/bash
if [ $# -ne 3 ]
then
echo "vmimg-to-tar.sh vm-image-path path-to-write tar-out-file"
exit 1
fi
IMG=$1
PATH_TO_WRITE=$2
TAR=$3
IMG_FILE=$(basename "$IMG")
TAR_FILE=$(basename "$TAR")
IMG_DIR=$(cd "$(dirname "$IMG")" || exit; pwd)
TAR_DIR=$(cd "$(dirname "$TAR")" || exit; pwd)
docker run -it --rm \
-v "$IMG_DIR":/root/in \
-v "$TAR_DIR":/root/out \
--entrypoint /usr/bin/virt-tar-out \
curator/guestfish \
-a "/root/in/$IMG_FILE" ${PATH_TO_WRITE} "/root/out/$TAR_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment