qm importdisk always import 10G disk regardless of image size

Saahib

Member
May 2, 2021
84
3
13
I running following commands to create VM from CLI, however

Code:
qm create 1001 --name AlmaLinux-8.9-x86-64 --cores 2 --memory 1024 --net0 virtio,bridge=vmbr0
qm importdisk 1001 AlmaLinux-8.9-x86_64.qcow2 local

It is always creating 10G of VM although image size for qm importdisk AlmaLinux-8.9-x86_64.qcow2 image is 2.4G.
Code:
importing disk 'AlmaLinux-8.9-x86_64.qcow2' to VM 1001 ...
Formatting '/var/lib/vz/images/1001/vm-1001-disk-0.raw', fmt=raw size=10737418240 preallocation=off
transferred 0.0 B of 10.0 GiB (0.00%)
transferred 103.4 MiB of 10.0 GiB (1.01%)
transferred 205.8 MiB of 10.0 GiB (2.01%)
...
...

I confirmed this disk image size after creation, its 10GB
Code:
-r--r--r-- 1 root root  10G Dec 15 18:34 vm-1001-disk-0.raw

What I wish is it import in original size then I can resize to my desired size using qm resize .
How do I make sure that disk size is always equal to image size from which I am importing or atleast I can set disk size myself.
 
Thanks, it was helpful, so I get this :
Code:
image: AlmaLinux-8.9-x86_64.qcow2
file format: qcow2
virtual size: 10 GiB (10737418240 bytes)
disk size: 2.31 GiB
cluster_size: 65536
Format specific information:
    compat: 1.1
    compression type: zlib
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
    extended l2: false
Child node '/file':
    filename: AlmaLinux-8.9-x86_64.qcow2
    protocol type: file
    file length: 2.31 GiB (2485059584 bytes)
    disk size: 2.31 GiB

I tested from inside newly created VM, the actual usage is about ~2GiB
Code:
[root@AlmaLinux-8 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        436M     0  436M   0% /dev
tmpfs           476M     0  476M   0% /dev/shm
tmpfs           476M   13M  463M   3% /run
tmpfs           476M     0  476M   0% /sys/fs/cgroup
/dev/sda4       9.3G  2.0G  7.4G  21% /  <--- HERE
/dev/sda3       507M  353M  154M  70% /boot
/dev/sda2       200M  5.8M  194M   3% /boot/efi
tmpfs            96M     0   96M   0% /run/user/0

So, what can I do to reduce this virtual size safely and easily ?
 
Lets just say you cant do it on a pre-created image.
Very few filesystems support shrink and if they do, its under very specific conditions.

2GB is the occupied size, but the underlying disk is 10G. Thats how the creators of the image decided to build it.

You will need to build your own image.

PS you can look into virt-edit, but that has nothing to do with PVE Installation and Configuration.


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!