diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-12-07 12:13:53 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-12-07 12:13:53 +0200 |
commit | 75063303533f106db8ceec7f9a25ed746a4ae103 (patch) | |
tree | 70d6428f4f66a6f7e50a4e3e9ee8d1dddf4f3bd8 /create-vm | |
parent | 3607b16668245cd9f7ee1746c3979f51ed8994c0 (diff) | |
download | ansibleness-75063303533f106db8ceec7f9a25ed746a4ae103.tar.gz |
Change: allow create-vm handle uncomprssed image input files
Diffstat (limited to 'create-vm')
-rwxr-xr-x | create-vm | 33 |
1 files changed, 28 insertions, 5 deletions
@@ -36,6 +36,11 @@ xz_uncompressed_size() xz --robot --verbose --list "$1" | awk '/^file/ { print $5 }' } +raw_uncompressed_size() +{ + stat -c %s "$1" +} + # Check parameters. @@ -66,8 +71,20 @@ then fi verbose "$basepath exists" +# Is base image compressed? +case "$basepath" in + *.xz) xz=true ;; + *) xz=false ;; +esac + + # How large is the (uncompressed) image? In bytes. -size="$(xz_uncompressed_size "$basepath")" +if $xz +then + size="$(xz_uncompressed_size "$basepath")" +else + size="$(raw_uncompressed_size "$basepath")" +fi verbose "Image is $size bytes" # Create new LV. @@ -79,10 +96,16 @@ verbose "lvpath=$lvpath" #sudo lvchange -ay "$lvpath" # Copy uncompressed image to LV. -verbose "Uncompressing and copying image to LV" -unxz < "$basepath" | - pv --size "$size" | - sudo ionice -c3 tee "$lvpath" > /dev/null +if $xz +then + verbose "Uncompressing and copying image to LV" + unxz < "$basepath" | + pv --size "$size" | + sudo ionice -c3 tee "$lvpath" > /dev/null +else + pv "$basepath" | + sudo ionice -c3 tee "$lvpath" > /dev/null +fi # Edit /etc/hostname verbose "Set hostname on new system to $name" |