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

Thomas
  • 4,225
  • 5
  • 23
  • 28
Damon Hill
  • 77
  • 2
  • 13

1 Answers1

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.

shodanshok
  • 47,711
  • 7
  • 111
  • 180
  • 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