Skip to content

Commit

Permalink
If target image is a block device, access it directly
Browse files Browse the repository at this point in the history
This will allow a user to specify a block device, like an LVM volume or
ZFS zvol, as target.
  • Loading branch information
omni committed Apr 13, 2021
1 parent 63a0342 commit e064a61
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions alpine-make-vm-image
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,21 @@ if ! command -v "$APK" >/dev/null; then
fi

#-----------------------------------------------------------------------
if [ ! -f "$IMAGE_FILE" ]; then
if [ ! -f "$IMAGE_FILE" -a ! -b "$IMAGE_FILE" ]; then
einfo "Creating $IMAGE_FORMAT image of size $IMAGE_SIZE"
qemu-img create ${IMAGE_FORMAT:+-f $IMAGE_FORMAT} "$IMAGE_FILE" "$IMAGE_SIZE"
fi

#-----------------------------------------------------------------------
einfo "Attaching image $IMAGE_FILE as a NBD device"
if [ -b "$IMAGE_FILE" ]; then
einfo "Provided image $IMAGE_FILE is a block device"

nbd_dev=$(attach_image "$IMAGE_FILE" "$IMAGE_FORMAT")
nbd_dev="$IMAGE_FILE"
else
einfo "Attaching image $IMAGE_FILE as a NBD device"

nbd_dev=$(attach_image "$IMAGE_FILE" "$IMAGE_FORMAT")
fi

#-----------------------------------------------------------------------
einfo "Formatting image to $ROOTFS"
Expand Down

0 comments on commit e064a61

Please sign in to comment.