vm-bhyve icon indicating copy to clipboard operation
vm-bhyve copied to clipboard

Unable to provision compressed VM images

Open elasmo opened this issue 3 years ago • 1 comments

Description

When an image is created using vm image create decompression fails while using vm image provision. This happens because xz ignores files missing a .xz filename suffix.

Versions used

  • vm-bhyve 1.5-devel
  • FreeBSD 12.2-RELEASE-p4

How to reproduce

# grep ^disk0 /vm/FreeBSD-12.2-RELEASE/FreeBSD-12.2-RELEASE.conf 
disk0_type="virtio-blk"
disk0_name="disk0"
disk0_dev="sparse-zvol"
# vm image create FreeBSD-12.2-RELEASE
Creating a compressed image, this may take some time...
Image of FreeBSD-12.2-RELEASE created with UUID 1921dde1-8d74-11eb-bf7a-0025907b906a
# vm image provision 1921dde1-8d74-11eb-bf7a-0025907b906a test4
Unpacking guest image, this may take some time...
cannot receive: failed to read from stream
/usr/local/sbin/vm: ERROR: errors occured while trying to unpackage the image file

Workaround

# sed -i '' 's/.zfs.z/.zfs.xz/' /vm/images/1921dde1-8d74-11eb-bf7a-0025907b906a.manifest
# mv /vm/images/1921dde1-8d74-11eb-bf7a-0025907b906a.zfs.z /vm/images/1921dde1-8d74-11eb-bf7a-0025907b906a.zfs.xz
# vm image provision 1921dde1-8d74-11eb-bf7a-0025907b906a test4
Unpacking guest image, this may take some time...
#

Discussion It could be sufficient to change the filename variable on #L374, but that would possibly break any user defined compression. It's worth noting that gzip also expects a correct filename suffix (.gz)

Possible solution could be to change #L387 to perform compression on a single line. Both gzip and xz would add a suffix this way.

zfs send -R "${VM_DS_ZFS_DATASET}/${_name}@${_snap}" > "${vm_dir}/images/${_filename}"
${_compress} "${vm_dir}/images/${_filename}"

elasmo avatar Mar 30 '21 15:03 elasmo

#394 also mentions this issue.

elasmo avatar Apr 01 '21 09:04 elasmo