KVM Questions

Home » CentOS » KVM Questions
CentOS 7 Comments

I have a system with two CentOS 7.1 guests. When I created the VMs I did not have enough storage space in the default location
/var/lib/libvirt/images so I moved the default location to a directory
/home/vmimages. While this configuration is functional I regret creating a new storage pool in /home. I would like to create a separate partition to place the VM images removing them from their present /home/images location. The /home partition is presently empty other than the VM
images directory so I can easily steal space from it (using only ~4% of
500GB). However, I have a problem. Namely /home is an XFS file system so I cannot shrink the partition in order to make space for the desired new VM images partition. I was wondering if this procedure might work to do what I desire:

1.) Shutdown the VMs
2.) Archive the VM image directory /home/vmimages to a network drive
(don’t have space locally other than on /home)
3.) Use parted or fdisk to delete present /home partition
4.) Use parted or fdisk to re-create smaller/home partition and new
/vm-images partition
5.) Create XFS file system on /home and /vm-images
6.) Extact VM image directory archive into /vm-images
7.) Use virt-manager to change default location of images to /vm-images

Is there any chance that after all this the VMs would actually start up again especially after a re-boot?

Thanks.

7 thoughts on - KVM Questions

  • not have enough storage space in the default location
    /var/lib/libvirt/images so I moved the default location to a directory
    /home/vmimages. While this configuration is functional I regret creating a new storage pool in /home. I would like to create a separate partition to place the VM images removing them from their present /home/images location. The /home partition is presently empty other than the VM images directory so I can easily steal space from it (using only ~4% of 500GB). However, I
    have a problem. Namely /home is an XFS file system so I cannot shrink the partition in order to make space for the desired new VM images partition. I
    was wondering if this procedure might work to do what I desire:
    (don’t have space locally other than on /home)
    /vm-images partition again especially after a re-boot?

    They are just disk images so as long as you don’t mind deleting home then this will work.

    Don’t forget to virsh edit each domain and update the paths in that.

    In addition don’t forget to fix your selinux contexts:

    semanage fcontext -a -e /var/lib/libvirt/images /vm-images

  • Thank you for the reminder. My monitor would have taken some verbal abuse but I would have figured it out eventually. :)

  • So it turns out this was even easier than I expected. The home partition was actually built upon LVM so some relatively simple use of LVM allowed me to do exactly what I wanted. However I have some very subtle issue that I don’t understand. virt-manager, df and du incorrectly think this:

    Filesystem 1K-blocks Used Available Use% Mounted on
    /dev/mapper/CentOS_mric–srv2-root 52403200 5717192 46686008 11% /
    devtmpfs 16378220 0 16378220 0% /dev tmpfs 16388924 88 16388836 1% /dev/shm tmpfs 16388924 9224 16379700 1% /run tmpfs 16388924 0 16388924 0% /sys/fs/cgroup
    /dev/mapper/CentOS_mric–srv2-home 433378560 32928 433345632 1% /home
    /dev/sda1 508588 219764 288824 44% /boot
    /dev/mapper/CentOS_mric–srv2-vm–images 67858700 16294864 51563836 25% /vm-images

    16261904 /vm-images

    But ls has it correct:

    total 16261908
    -rw——-. 1 qemu qemu 51547734016 May 9 15:15 CentOS7.0-1.qcow2
    -rw——-. 1 qemu qemu 12887130112 May 9 15:15 CentOS7.0.qcow2
    drwxr-xr-x. 21 root root 4096 May 9 15:13 .. drwxr-xr-x. 2 root root 52 May 9 13:39 .

    Any idea how I make this correct?

    There are no side effects that I see but it is extremely puzzling to me as to why the new partition does not have the correct size. It appears the larger of the two VM images is not getting counted.

  • Am 09.05.2015 um 23:19 schrieb Paul R. Ganci :

    modern filesystems and image formats do not allocate the whole space if not neccessary (qcow2 feature).

  • Not specifically. Every disk image type would be sparse if it were copied off a disk and back by a tool that wrote them correctly.

    qcow2 does support small files on filesystems that don’t support sparse files, but in that case du and ls will show the same size.

  • In part because this directory was getting in the way of synchronizing user directories between two servers. You could imagine the mess if I
    clobbered the /home/vmimages directories. I worked around the issue but felt that this pool just didn’t belong in /home. I suppose that is mostly a personal choice but I am much happier now that the VM images are in their own space. Much less likely to make a nasty mistake.