2

I'd like to convert a KVM virtual machine disk image in raw file from a thin privisioning format to preallocated.

In the first place I've got a preallocated 20Gb raw image file:

image: /var/lib/libvirt/images/ArchLinux.img
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 20G

I used the following command to make the backup disk file:

sudo qemu-img -O qcow2 -cp ArchLinux.img BackupArchlinux.qcow2

After that I tried to get the first image file back using:

sudo qemu-img -O raw -p BackupArchlinux.qcow2 Archlinux.img

but I get a thin privisioned raw format as you can see here:

image: .../ArchLinux.img
file format: raw
virtual size: 20G (21474836480 bytes)
disk size: 1.6G

How can I convert this raw file to preallocated format back?

Note: qemu-img version 2.11.0

  • Thank you Thomas for your edition, I learned something 'bout markdown ;-) – Damon Hill Jan 20 '18 at 23:49
3

To fully preallocate a RAW image, rather than copying/converting the whole image with qemu-img, you can simply issue fallocate <image_file> -l <size_to_preallocate>

In your case, you can issue fallocate ArchLinux.img -l 20G.

Of course, do a backup before messing with the disk's image file.

  • Perfect! I did: fallocate NewArchLinux.img -l 20G and now qemu-img info NewArchLinux.img image: NewArchLinux.img file format: raw virtual size: 20G (21474836480 bytes) disk size: 20G – Damon Hill Jan 20 '18 at 23:50

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.