X-Git-Url: https://git.jankratochvil.net/?p=nethome.git;a=blobdiff_plain;f=bin%2Fqemu-img-recompress;h=5aa41263343f007011c7ff3871d3e5bddc663569;hp=0feb535c8df0cd73e7d993b65456346b2203b5b0;hb=c36d3924d6aa4ea711f344e215e2f5b8525fd0a0;hpb=ec43c7627b731e3b684aee00285b01122188b3a4 diff --git a/bin/qemu-img-recompress b/bin/qemu-img-recompress index 0feb535..5aa4126 100755 --- a/bin/qemu-img-recompress +++ b/bin/qemu-img-recompress @@ -1,5 +1,10 @@ #! /bin/sh renice 20 -p $$ +guestfish=true +if [ "$1" = "-n" ];then + guestfish=false + shift +fi for file in "$@";do if [ "$file" = "${file%.qcow2}" ];then echo >&2 "Invalid: <$file>" @@ -12,6 +17,10 @@ for file in "$@";do set -xe mv -i "$file" "$file"-src rm -f "$file"-dest + if $guestfish;then + test "$(guestfish -n -a "$file"-src run : list-devices : list-partitions|tr '\n' ' ')" = "/dev/vda /dev/vda1 " + guestfish -n -a "$file"-src run : zerofree /dev/vda1 + fi time qemu-img convert -c -f qcow2 "$file"-src -O qcow2 "$file"-dest mv -i "$file"-dest "$file" rm -f "$file"-src