KVM Virtualization Directory-Based Storage Pool Configuration: Difference between revisions
(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. | ||
< | <syntaxhighlight lang='bash'> | ||
mkdir /iso-images | mkdir /iso-images | ||
</ | </syntaxhighlight> | ||
Set directory ownership: | Set directory ownership: | ||
< | <syntaxhighlight lang='bash'> | ||
chown root:root /iso-images | chown root:root /iso-images | ||
</ | </syntaxhighlight> | ||
Set directory permissions: | Set directory permissions: | ||
< | <syntaxhighlight lang='bash'> | ||
chmod 755 /iso-images | chmod 755 /iso-images | ||
</ | </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. | ||
< | <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 | ||
</ | </syntaxhighlight> | ||
Use [[virsh pool-define-as]] to define the new storage pool: | Use [[virsh pool-define-as]] to define the new storage pool: | ||
< | <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 | ||
</ | </syntaxhighlight> | ||
Start the storage pool: | Start the storage pool: | ||
< | <syntaxhighlight lang='bash'> | ||
virsh pool-start iso-images | virsh pool-start iso-images | ||
</ | </syntaxhighlight> | ||
Declare it "auto-start": | Declare it "auto-start": | ||
< | <syntaxhighlight lang='bash'> | ||
virsh pool-autostart iso-images | virsh pool-autostart iso-images | ||
</ | </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: | 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: