KVM can dynamically allocate disk space for a virtual machine. This saves a lot of space on your KVM server because most VMs, especially testing ones, rarely need all of their disk space. By using dynamic space allocation with VM disk images, you can “over subscribe” server “bare metal” disk space and deploy more VMs. Unfortunately Virtual Machine Manager (VMM) cannot create this type of disk from its GUI. So before we setup our new VM, we need to login to the remote KVM server and create the disk image file ourselves beforehand.
This guide assumes you have already installed Virtual Machine Manager, connected to your KVM server, and have a user account on your KVM server with
sudo privileges. The example KVM server used here is named
ubuntu-mockup. The GUI steps presented here are performed on
mint-mockup and the shell commands given in this guide are executed on
ubuntu-mockup unless indicated otherwise
First, let us find out where the KVM server is storing VM disk image files. Right-click on the connection and choose “Details”
As you can see, the default location for VM disk storage is
Login to the remote KVM server
ubuntu-mockup and check the permissions on this directory.
ls -dl /var/lib/libvirt/images
drwx--x--x 2 root root 4096 Feb 6 14:33 /var/lib/libvirt/images
This directory is only writeable by the
root user, but it is also writeable by the
libvirtd KVM daemon. For our purposes we need
sudo to create the dynamic disk file.
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-vm.qcow2 30G
This creates a tiny placeholder disk image of basically 0 size that will grow as need during VM operation.
ls -l /var/lib/libvirt/images/ubuntu-vm.qcow2
-rw-r--r-- 1 root root 197120 Feb 6 14:50 /var/lib/libvirt/images/ubuntu-vm.qcow2
Back at the VMM, if you refresh the storage tab, there is a new disk.
Note that VMM shows a disk size of 30GB, but we know the current actual disk usage on the host is much smaller because we created the new disk as a dynamic space allocation type qcow2.
Now that you have some shiny new disk space, maybe you want to create a new virtual machine