Detect image format for qemu-nbd --format

qemu-nbd will error when the image format is raw unless there is an
explicit --format raw argument provided.

This change adds format detection for raw and qcow2 using qemu-img
info. Any other image type will depend on qemu-nbd auto-detection.

Blueprint: whole-disk-default
Change-Id: I628abc4cb8c46c3b2e5bfd3cd16bb6d5cc95fabe
This commit is contained in:
Steve Baker 2021-09-17 11:03:15 +12:00
parent 049f9a9659
commit db7280e653
1 changed files with 8 additions and 1 deletions

View File

@ -92,7 +92,14 @@ remove_device () {
mount_image() {
set -x
qemu-nbd --connect $NBD_DEVICE $IMAGE_FILE
if qemu-img info --output json $IMAGE_FILE |grep '"format": "raw"' ; then
image_format='--format raw'
elif qemu-img info --output json $IMAGE_FILE |grep '"format": "qcow2"' ; then
image_format='--format qcow2'
else
image_format=''
fi
qemu-nbd $image_format --connect $NBD_DEVICE $IMAGE_FILE
# search for the vg volume group, this is automatic in some environments
vgscan