Last active
February 28, 2024 07:44
-
-
Save platu/80abe91df20868cc8e49e1de0f23a8ed to your computer and use it in GitHub Desktop.
IaC Lab01 vm image file resize script
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 | |
# 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