KVM Virtualization Directory-Based Storage Pool Configuration: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 17: Line 17:
Create the new directory, or us an existing directory.
Create the new directory, or us an existing directory.


<pre>
<syntaxhighlight lang='bash'>
mkdir /iso-images
mkdir /iso-images
</pre>
</syntaxhighlight>


Set directory ownership:
Set directory ownership:


<pre>
<syntaxhighlight lang='bash'>
chown root:root /iso-images
chown root:root /iso-images
</pre>
</syntaxhighlight>


Set directory permissions:
Set directory permissions:


<pre>
<syntaxhighlight lang='bash'>
chmod 755 /iso-images
chmod 755 /iso-images
</pre>
</syntaxhighlight>


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.
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.


<pre>
<syntaxhighlight lang='bash'>
semanage fcontext -a -t virt_image_t '/iso-images(/.*)?'
semanage fcontext -a -t virt_image_t '/iso-images(/.*)?'
restorecon -R /iso-images
restorecon -R /iso-images
</pre>
</syntaxhighlight>


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


<pre>
<syntaxhighlight lang='bash'>
virsh pool-define-as iso-images dir --source-path /iso-images --target /iso-images
virsh pool-define-as iso-images dir --source-path /iso-images --target /iso-images
</pre>
</syntaxhighlight>


Start the storage pool:
Start the storage pool:


<pre>
<syntaxhighlight lang='bash'>
virsh pool-start iso-images
virsh pool-start iso-images
</pre>
</syntaxhighlight>


Declare it "auto-start":
Declare it "auto-start":


<pre>
<syntaxhighlight lang='bash'>
virsh pool-autostart iso-images
virsh pool-autostart iso-images
</pre>
</syntaxhighlight>


=Storage Volume=
=Storage Volume=
Line 62: Line 62:
Even if the ISO images are not declared as storage volumes,  [[virt-install]] will create the corresponding storage volume if used during the guest installation.
Even if the ISO images are not declared as storage volumes,  [[virt-install]] will create the corresponding storage volume if used during the guest installation.


Alternatively, they can be pre-staged as described in this procedure: [[KVM_Virtualization_Placing_an_ISO_Image_in_a_Directory-Based_Storage_Pool|Placing an ISO Image in a Directory-Based Storage Pool]].
Alternatively, they can be pre-staged as described in this procedure: {{Internal|KVM_Virtualization_Placing_an_ISO_Image_in_a_Directory-Based_Storage_Pool|Placing an ISO Image in a Directory-Based Storage Pool}}

Latest revision as of 23:36, 6 December 2020

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 available 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 755 /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

Start the storage pool:

virsh pool-start iso-images

Declare it "auto-start":

virsh pool-autostart iso-images

Storage Volume

Even if the ISO images are not declared as storage volumes, virt-install will create the corresponding storage volume if used during the guest installation.

Alternatively, they can be pre-staged as described in this procedure:

Placing an ISO Image in a Directory-Based Storage Pool