KVM thin provisioning tip.

Share this link

If you use KVM for managing your virtual machines, you can sometimes run out of space in the /var/lib/libvirt/images directory, the default location for the RHEL/CentOS distributions.
Because KVM knows the concept of thin provisioning through the qcow2 image format, the one used by the virt-install command by default, it would be crazy not to use it.
This can be done through the virt-sparsify command coming with the libguestfs-tools rpm package. So, the virt-sparsify command copies a VM image, only keeping the necessary data.

Let’s try an example.
Install the libguestfs-tools package:

# yum install libguestfs-tools

Go to the /var/lib/libvirt/images directory (or the one that you are using for storing your VM images):

# cd /var/lib/libvirt/images

Choose a VM and stop it (here vm.example.com) (use the virsh destroy command if necessary):

# virsh shutdown vm.example.com

Execute the virt-sparsify command:

# virt-sparsify -q vm.example.com.img vm.example.com.img2

Note: The -q option removes any display (quiet). Don’t ask me why this is not the default!

Get the size of the VM before and after:

# du -k vm.*
8388660 vm.example.com.img
1370168 vm.example.com.img2

Note: The ls command doesn’t display the correct information.

Replace the old image with the new one:

# mv -f vm.example.com.img2 vm.example.com.img

Restart the VM:

# virsh start vm.example.com

As you can see, it’s quite simple! I’m sure you will love it!

Posted in RHEL7

Upcoming Events (Local Time)

  1. Jan
    31
    Fri

    1. 9:00 am - View Details
      CentOS: Dojo, Brussels, Belgium.

RHCSA7: Task of the day

Allowed time: 5 minutes.
Add 100MB of swap space to the machine using a new logical volume.

RHCE7: Task of the day

Allowed time: 15 minutes.
Configure a Samba server called MYSERVER, belonging to the MYGROUP group, sharing the /shared directory with the name "shared".

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...