Get Image Fingerprint Before Full Import

Hi everyone,

I’m trying to figure out how to retrieve the fingerprint of an image before the import process is fully completed. Specifically, my workflow looks something like this:

1.	I want to create a minimal or empty image (with some placeholder data, if necessary).
2.	I need to know the image’s fingerprint at this point, even though the actual QCOW2 file or full image data hasn’t been downloaded or imported yet.
3.	Once the QCOW2 file is ready, I plan to import it fully and replace the placeholder.

Is there any way to calculate or get the image’s fingerprint (or at least reserve a fingerprint) before completing the full import process? Any guidance or workarounds for this would be much appreciated!

Thanks in advance for your help!

The image fingerprint is the SHA256 sum of its data.

stgraber@dakara:~$ cd test/
stgraber@dakara:~/test$ incus image info images:alpine/edge
Fingerprint: 373497044c7db6aceb32fdc01f3543fa471eb688b67eb6680b27ce3398bde447
Size: 3.09MiB
Architecture: x86_64
Type: container
Public: yes
Timestamps:
    Created: 2024/10/20 20:00 EDT
    Uploaded: 2024/10/20 20:00 EDT
    Expires: 1969/12/31 19:00 EST
    Last used: never
Properties:
    variant: default
    type: squashfs
    release: edge
    serial: 20241021_13:00
    description: Alpine edge amd64 (20241021_13:00)
    requirements.secureboot: false
    os: Alpine
    architecture: amd64
Aliases:
    - alpine/edge/default
    - alpine/edge/default/amd64
    - alpine/edge
    - alpine/edge/amd64
Cached: no
Auto update: disabled
Profiles: []
stgraber@dakara:~/test$ incus image export images:alpine/edge
Image exported successfully!                   
stgraber@dakara:~/test$ cat incus.tar.xz rootfs.squashfs | sha256sum
373497044c7db6aceb32fdc01f3543fa471eb688b67eb6680b27ce3398bde447  -
stgraber@dakara:~/test$ 

So given access to the data, you can compute its fingerprint, but if that data changes, so will its fingerprint.

thanks for your reply.
I need to create 1000’s of images from qcow files from different S3 buckets, Its possible to create an empty image using just metadata.tar to obtain an early fingerprint/id/alias of the image (as we do with volumes). then can start the async processs to download and import the qcow into the new image, knowing the image fingerprint/alias before hand we can monitor the image import process, register it and then define when the image is avaiable or the import process failed.
Thanks again

No, as mentioned, the image fingerprint is the hash of the entire chunk of data.
You can’t take one small file, make a hash of that, then combine it with a much larger file and still get the same hash.

k, what about using the alias instead ? can create an empty image and then complete the import of the real content. even if the fingerprint change we can use the alias to keep a record of the image in the creation process

yeah, an alias works fine, you can move it between a broken (empty) image and your final image if you want.

1 Like