Context > I am a bit confused about disk images and their installation. I am using qemu/kvm with libvirt and have used VirtualBox in the past. Back then, the UI would guide me to choosing a "template" ISO image for the OS, and creating a separate VDI storage file without modifying the "template" image.

Confusion > However, using libvirt and qemu with qcow2 images such as one of debian cloud, the process I have found does not separate the working disk image from the downloaded or template one, using "import from existing image". It's ok for me, but I find it troublesome that I can't set the maximum size of the image, that one the guest OS perceives from inside.

Explored way > I learnt how to resize a qemu image with qemu-img and the gparted live cd, but I'm sure there's an easier way. Actually, from the virt-install manpages it looks like one could do something like --import --disk path=/home/user/my_os.img,size=10 and it would make sure available storage for guest OS is 10 GB.

The command that I tried to do what I want, using Ubuntu cloud images:

virt-install \
 --name ubuntu-bionic \
 --memory 4000 \
 --vcpus 2 \
 --import \
 --disk path=/path/to/bionic-server-cloudimg-amd64.img,format=qcow2,bus=virtio,size=10 \
 --disk path=/path/to/cloud-init.img,device=cdrom \
 --network bridge=virbr0,model=virtio \
 --os-type=linux \
 --os-variant=ubuntubionic \
 --connect qemu:///system \

Problem > However, this doesn't work as expected. It creates a "domain" and starts the vm with the disk, but instead of 10 GB, it shows it as 2.2 GB. This is the size perceived from the guest OS and the one reported by virt-manager (the GUI). I did an screenshot of virt-manager and terminal oposed opinions on "size" of the disk image. The actual used space is 380 MB as du reports.

Questions >

  1. Is there a way to import a disk image and simultaneously resize it?
  2. What would be a better approach to set the disk size with virt-install in the fewest steps?
  3. Any other suggestions?

1 Answer 1


I think that you can solve your issue running a qemu-img resize command before creating the virtual machine with the virt-install command.

I use the next process to generate a vm with a 10G of disk space and with a qcow2 image:

  1. Download the cloud qcow2 iso.
  2. Run the resize image command:
$ qemu-img resize /var/lib/libvirt/images/bionic-server-cloudimg-amd64.img 10G
  1. And then run the virt-install command.

If you want, we create detailed documentation about How to create a development virtualized environment in our handbook: https://github.com/coopdevs/handbook/wiki/Virtualization-with-libvirt%2C-qemu-and-kvm :P

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .