3

I have created a virtual disk with QEMU / KVM in format .qcow2 enter image description here

I already know they are virtual sparce disks, however, the problem is that when I try to copy & paste virtual disk (vol.qcow2) in another path (removable drive), it is still 20GB (not 3.32 MiB), something that does not happen with dynamic disks in Virtualbox.

I have tried editing the .xml file to put

sparce = true # supposedly this option is the one that defines if the disk is dynamic or fixed

But I have not been successful.

What should I do to create a virtual disk with QEMU / KVM / virt-manager in .qcow2 or RAW format and keep it similar size of virtualbox dynamic virtual disks (VDI nd other formats like a VHD, etc)?

PD: Please with QEMU/KVM virt-manager" in linux

thanks in advanced

3
  • You didn't mention "how" you back up. The following question outlines various options that retain the sparse-ness serverfault.com/questions/665335/… Dec 8, 2020 at 7:53
  • just copy&paste virtual disk (vol.qcow2) in another path (removable drive)
    – acgbox
    Dec 8, 2020 at 18:33
  • I just created a 100M sparse image in ~/ (193k on disk) and copied it over to /tmp - still 193k. Sparse support depends on the copy tools AND (more important) the target file systems. Since you said "removable drive" that isn't (by any chance) for matted vfs or such? Please try to copy in a console and use a different path on the same disk (to ensure your copy retains spares) and only then to the removable drive (if failing there mentioned the FS this is formatted). Dec 14, 2020 at 9:21

1 Answer 1

6

You can convert the existing disk in a new disk (that uses preallocation=off) with the following command:

qemu-img convert -f qcow2 -O qcow2 -o preallocation=off vol.qcow2 newdisk.qcow2

where:

  • the -f format flag specifies the format of the input disk
  • the -O format flag specifies the format of the output disk
  • the -o flag is used to specify some options for the output file, such as the way data is allocated (in this case, no data preallocation)

Then use the new disk in place of the original disk:

  • rename vol.qcow2 as vol.qcow2.bak just to backup it. Delete it only when you are sure that newdisk.qcow2 works as expected.
  • rename newdisk.qcow2 as vol.qcow2

If you want to create a dynamic virtual disk from scratch, you can run this command:

qemu-img create -f qcow2 -o preallocation=off <disk-name> <disk-size>

where:

  • disk-name is the name of the dynamic virtual disk
  • disk-size is the maximum disk size (you can use k, M, G, T, P or E as suffixes)
3
  • 1
    Your answer is correct. I already tried it and it works (and I am grateful), but it only explains how to do it by command line and not by GUI with the "QEMU / KVM virtual machine manager" in linux
    – acgbox
    Dec 9, 2020 at 13:50
  • 1
    I don't know if it's possible to do it via GUI. That's the reason why I typically create the virtual disk by command line, and then, when creating a VM using virt-manager, I use the option to use an existing virtual disk. Dec 9, 2020 at 13:54
  • ok. I will investigate this topic further to see if this is possible, although we agree, as in virtualbox, creating or resizing disks by command line is safer and better. thanks
    – acgbox
    Dec 9, 2020 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.