Bug 263029 - [mkimg] qcow2 images are not compressed by default
Summary: [mkimg] qcow2 images are not compressed by default
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.1-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-03 21:38 UTC by Dave Cottlehuber
Modified: 2024-12-19 05:52 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Cottlehuber freebsd_committer freebsd_triage 2022-04-03 21:38:24 UTC
Using qemu-img with compression (from emulators/qemu) yields
significantly smaller images than the original mkimg one, which
appears not to be compressed at all, just sparse.

> qemu-img convert -S 1k -p -f raw -O qcow2 -c oci.raw oci.qcow
    (100.00/100%)

$ ls -FGHls
total 5824488
2551104 -rw-r--r--  1 dch  wheel   2.4G Apr  3 21:16 oci.mkimg.qcow2
2515616 -rw-r--r--  1 dch  wheel   6.0G Apr  3 21:17 oci.raw
 757768 -rw-r--r--  1 dch  wheel   740M Apr  3 21:22 oci.qemu.qcow2
Comment 1 Dave Cottlehuber freebsd_committer freebsd_triage 2022-04-03 21:39:33 UTC
<sigh> at least make the command match the output files:

> qemu-img convert -S 1k -p -f raw -O qcow2 -c oci.raw oci.qemu.qcow2
Comment 2 Ed Maste freebsd_committer freebsd_triage 2022-04-06 18:53:41 UTC
Can you check the # of blocks occupied by the mkimg and qemu-img files (e.g. stat -f%b)? Or paste a hexdump -Cv of the first few hundred bytes of each file here.

AFAICT only qcow v3 actually supports compression; I wonder if the qemu-img file is in fact a "sparse" image managed by qemu rather than the filesystem.

ref: https://git.qemu.org/?p=qemu.git;a=blob;f=docs/interop/qcow2.txt
Comment 3 Ed Maste freebsd_committer freebsd_triage 2022-04-06 19:39:15 UTC
Starting with a 1G file of all zeros and converting I see:

$ mkimg -f qcow2 -o mkimg.qcow2.out -s gpt -p freebsd-ufs:=sparse
-rw-r--r--  1 emaste  emaste      524288 Apr  6 15:28 mkimg.qcow2.out

$ mkimg -f raw -o mkimg.raw.out -s gpt -p freebsd-ufs:=sparse
-rw-r--r--  1 emaste  emaste  1073744384 Apr  6 15:28 mkimg.raw.out

$ qemu-img convert -S 1k -p -f raw -O qcow2 -c mkimg.raw.out qemu-img.out
-rw-r--r--  1 emaste  emaste      458752 Apr  6 15:30 qemu-img.out

$ hexdump -Cv mkimg.qcow2.out
00000000  51 46 49 fb 00 00 00 02  00 00 00 00 00 00 00 00  |QFI.............|
00000010  00 00 00 00 00 00 00 10  00 00 00 00 40 01 00 00  |............@...|
mkimg indeed produces V2

$ hexdump -Cv qemu-img.out
00000000  51 46 49 fb 00 00 00 03  00 00 00 00 00 00 00 00  |QFI.............|
00000010  00 00 00 00 00 00 00 10  00 00 00 00 40 00 0a 00  |............@...|
qemu-img produces V3

We can ask for qcow2 compat:
$ qemu-img convert -S 1k -p -f raw -O qcow2 -o compat=0.10 -c mkimg.raw.out qemu-img.compat.out
-rw-r--r--  1 emaste  emaste      458752 Apr  6 15:36 qemu-img.compat.out

$ hexdump -Cv qemu-img.compat.out
00000000  51 46 49 fb 00 00 00 02  00 00 00 00 00 00 00 00  |QFI.............|
00000010  00 00 00 00 00 00 00 10  00 00 00 00 40 00 0a 00  |............@...|

It is now V2.