Add scripts to generate raw images

See: https://github.com/kairos-io/kairos/issues/377
This commit is contained in:
Ettore Di Giacinto
2022-11-03 21:37:32 +00:00
parent 1f932a7644
commit dc55928694
4 changed files with 117 additions and 1 deletions

16
tools-image/gce.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/bin/bash
# Transform a raw image disk to gce compatible
RAWIMAGE="$1"
GB=$((1024*1024*1024))
size=$(qemu-img info -f raw --output json "$RAWIMAGE" | gawk 'match($0, /"virtual-size": ([0-9]+),/, val) {print val[1]}')
# shellcheck disable=SC2004
ROUNDED_SIZE=$(echo "$size/$GB+1"|bc)
echo "Resizing raw image from \"$size\"MB to \"$ROUNDED_SIZE\"GB"
qemu-img resize -f raw "$RAWIMAGE" "$ROUNDED_SIZE"G
echo "Compressing raw image $RAWIMAGE to $RAWIMAGE.tar.gz"
tar -c -z --format=oldgnu -f "$RAWIMAGE".tar.gz $RAWIMAGE
echo "Restoring size to original raw image"
qemu-img resize -f raw "$RAWIMAGE" --shrink "$size"
echo "Done"