How to refer via API to a downloaded image file stored in the images folder?

eltydari

New Member
Jan 22, 2024
5
0
1
I am trying to automate creation of my Ubuntu VM in Proxmox using Ansible, proxmoxer, and cloudinit.

I've seen (old) tutorial videos download the Ubuntu cloudinit IMG file to the /var/lib/vz/images path and then successfully use the image file by using the volume name import-from=local:images/noble-server-cloudimg-amd64.img to initialize the attached hard drive. However when I try this myself I get 500 Internal Server Error: unable to parse directory volume name 'images/noble-server-cloudimg-amd64.img'

What am I doing wrong? I know it has something to do with the right way of referring to the /var/lib/vz/images path, but documentation on this is pretty sparse and I've tried multiple ways of reaching this folder without any success.
 
import-from=local:images/noble-server-cloudimg-amd64.img
This does not look right & should probably be:
Code:
import-from=local:noble-server-cloudimg-amd64.img

# or

import-from=/var/lib/vz/images/noble-server-cloudimg-amd64.img

Disclaimer: I don't do anything like this, I'm just using intuition.
 
This does not look right & should probably be:
Code:
import-from=local:noble-server-cloudimg-amd64.img

# or

import-from=/var/lib/vz/images/noble-server-cloudimg-amd64.img

Disclaimer: I don't do anything like this, I'm just using intuition.
Thanks for the response! Unfortunately this (first one) did not work either (first screenshot attached)

For the second one, the background is that I am trying to use proxmoxer i.e. the Proxmox REST API to create the VM, and it seems you need to be root inside the Proxmox node in order to use absolute paths (see second screenshot)
 

Attachments

  • Screenshot 2025-01-30 154704.png
    Screenshot 2025-01-30 154704.png
    30.2 KB · Views: 5
  • Screenshot 2025-01-30 155206.png
    Screenshot 2025-01-30 155206.png
    27.8 KB · Views: 5
Last edited:
Proxmox REST API to create the VM, and it seems you need to be root inside
I see what you are trying to do. That seems correct like this.

However, I will just point out, that that location you used on local in /var/lib/vz/images/ is in fact the local storage location for VM disk images (assuming you have the local backend storage setup for disk images type) & then following the directory format of /var/lib/vz/images/{VMID}/

What ought to (should have!) work in your case - save that image file in /var/lib/vz/template/iso/ & then in your API config setup use:
import-from=local:iso/noble-server-cloudimg-amd64.img

BUT - this will also probably fail, as it will complain that the file has wrong ISO type.

As far as I can see, the API backend (that does not have root permissions) has not (as of yet) a working implementation for what you want. Read this thread.


A possible workaround:

1. On your node, create a "bogus" VM, lets call it VMID 999. Create it without any disks.

2. Use qm importdisk 999 {path}/noble-server-cloudimg-amd64.img

3. Check the file name of that VM 999's disk that is created. So maybe ls /var/lib/vz/images/999 (if you are using the local storage backend for VMs) will output: vm-999-disk-0.qcow2or something like that.

4. Then in your API backend config you can use:
import-from=local:vm-999-disk-0.qcow2

This workaround should work, & you could even add all your images that you use to that "bogus" VM & then use them accordingly.

The above is nothing but a workaround, & I must agree; I would have expected PVE themselves to have incorporated an image import facility within the API backend itself.
 
Thanks! I'll try your suggestion.
& I must agree; I would have expected PVE themselves to have incorporated an image import facility within the API backend itself.
Yeah. I looked through that thread link you posted and it seems someone asked about this very thing in August and it's still in progress.
 
Keep us posted if you are successful & maybe change the thread title to:

How to refer via API to a downloaded image file stored in the images folder?​

 
  • Like
Reactions: Johannes S
Keep us posted if you are successful & maybe change the thread title to:

How to refer via API to a downloaded image file stored in the images folder?​

Thanks! Changed. Should I mark this thread as resolved (edit: after i test your workaround) or leave as is until a real solution is found?
 
or leave as is until a real solution is found?
That is a good question. The Oxford dictionary (Google) defines solved by 3 options: "find an answer to, explanation for, or means of effectively dealing with (a problem or mystery)". I guess it depends on which one of these options you choose!

I would consider this is as of yet unsolved. But the choice is yours - not mine.
 
  • Like
Reactions: Johannes S
Ok now I'm running up against a different problem. Seems that this new disk (it's a RAW file) I imported into this bogus VM has a weird file state. When I try to use it to create my new VM, I get hit with this (this is coming from my Proxmox web UI):

Code:
Formatting '/var/lib/vz/images/103/vm-103-cloudinit.qcow2', fmt=qcow2 cluster_size=65536 extended_l2=off preallocation=metadata compression_type=zlib size=4194304 lazy_refcounts=off refcount_bits=16
ide2: successfully created disk 'local:103/vm-103-cloudinit.qcow2,media=cdrom'
failed to stat '/var/lib/vz/images/1000/base-1000-disk-0.raw'
TASK ERROR: unable to create VM 103 - cannot import from 'local:1000/base-1000-disk-0.raw' - could not get size of local:1000/base-1000-disk-0.raw

I've made sure that the file exists in the proper location.
 
First up based on this listing, it would appear that noble-server-cloudimg-amd64.img should be a "QCow2 UEFI/GPT Bootable disk image".

I am going to assume VM 103 is the VM you are trying to create via API & VM 1000 is the "bogus" VM we discussed above.

For my understanding:
'local:103/vm-103-cloudinit.qcow2,media=cdrom'
You are attaching a cloudinit cdrom to the VM 103 in addition to the requested disk you wish to attach via import-from VM 1000.
Is this your intention & why?

I'm not sure why you are showing that filename base-1000-disk-0.raw , AFAIK "base" is normally associated with clones & templates.
This possibly may have been caused, because you have not correctly "attached" this disk to the VM 1000.

Could you show the following:

1. Exact command you used to qm importdisk that noble-server-cloudimg-amd64.img to the bogus VM 1000.
2. Output for: qm config 1000 .
3. Output for: ls /var/lib/vz/images/1000/ .
4. Output for: cat /etc/pve/storage.cfg .

Thanks.