KVM Virtualization Directory-Based Storage Pool Configuration

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

This procedure declares a local directory as a storage pool.

One case when this is useful is when we want to share DVD ISO images with the guest for installation as -disk=.../some-image.iso,device=cdrom argument for virt-install. If the image is not declared as storage volume in a storage pool, libvirt will automatically build a storage pool for it, and sometimes build multiple storage pools for the same image, which is something we want to avoid.

Procedure

Create the new directory, or us an existing directory.

mkdir /iso-images

Set directory ownership:

chown root:root /iso-images

Set directory permissions:

chmod 700 /iso-images

Configure SELinux file contexts. Note that the name of the pool and the directory do not have to match. However, a guest virtual machine is being shut down, libvirt has to set the context back to a default value. The context of the directory determines what this default value is. It is worth explicitly labeling the directory virt_image_t, so that when the guest virtual machine is shutdown, the images get labeled 'virt_image_t' and are thus isolated from other processes running on the host physical machine.

semanage fcontext -a -t virt_image_t '/iso-images(/.*)?'
restorecon -R /iso-images

Use virsh pool-define-as to define the new storage pool:

virsh pool-define-as iso-images dir --source-path /iso-images --target /iso-images