Reputation: 17908
For migrating a Hyper-V VM to KVM, I used the qemu-img convert
utility to convert the vhdx disk to a compatible format like qcow (OS) and raw (data partition). The original Hyper-V disk use dynamic allocation. After converting, this seems to be changed to fixed allocation.
A example:
-rw-r--r-- 1 root root 300G May 6 20:30 IIS-Daten.raw
-rw-r--r-- 1 root root 3.5G May 6 18:17 IIS-Daten.vhdx
IIS-Daten.vhdx
is the original disc. Its limited to 300GB with dynamic allocation. In real, there are 3.5/300GB used yet. As you can see, the converted raw file has a fixed size of 300GB.
The same with the OS disk
-rw-r--r-- 1 root root 24G May 6 20:53 IIS.qcow2
-rw-r--r-- 1 libvirt-qemu kvm 36G May 6 19:16 IIS.vhdx
How can I change the type to dynamic? According to the docs, there seems no switch avaliable to control this behaviour.
UPDATE
Using df -h
I checked my drives and see that only 89GB/1.8TB are used. Since both virtual HDDs are on those drive, it seems that linux fool me: According to ls -lh
at least 324GB were used for the qcow2/raw disks. Plus about 40GB for the old vhdx files.
I think ls -lh
display me the maximum size of the hdd, and not the current one. I never saw this before. Why is this happening and how can I see the real used size of those files?
Upvotes: 2
Views: 8140
Reputation: 771
IIS-Daten.raw is a sparse file, not all blocks are actually allocated on disk. When you read unallocated blocks you'll get back zeros, when you write them the kernel will allocate blocks to store what you've written. This is standard unix behavior since decades. You can use "du $file" to see how much the file actually uses on disk.
If you want dynamic disks the qcow2 format usually works better, that supports dynamic file allocation without depending on sparse files.
Upvotes: 3