1
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 \
--noautoconsole
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 >
- Is there a way to import a disk image and simultaneously resize it?
- What would be a better approach to set the disk size with
virt-install
in the fewest steps? - Any other suggestions?