Skip to content

Instantly share code, notes, and snippets.

@platu
Last active February 28, 2024 07:44
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 platu/80abe91df20868cc8e49e1de0f23a8ed to your computer and use it in GitHub Desktop.
Save platu/80abe91df20868cc8e49e1de0f23a8ed to your computer and use it in GitHub Desktop.
IaC Lab01 vm image file resize script
#!/bin/bash
# This script resizes $1 VM disk image adding $2 GB to the original size
vm="$1"
shift
size="$1"
if [[ -z ${vm} ]] || [[ -z ${size} ]]; then
echo "Usage: $0 <vm> <size>"
exit 1
fi
qemu-img resize "${vm}" "+${size}"
cp "${vm}" "${vm}.orig"
virt-resize --expand /dev/sda1 "${vm}.orig" "${vm}"
rm "${vm}.orig"
info=$(qemu-img info "${vm}") || true
vm_name=$(basename "${vm}")
grep "virtual size:" <<<"${info}" >"${vm_name}"_resized.txt
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment