Objective
The default KVM virtual storage location is /var/lib/libvirt/images
meaning, that any new virtual machines created via Virtual Machine Manager will be stored within this location. The objective of this guide is to configure another default KVM virtual storage directory location.
Operating System and Software Versions
- Operating System: – Redhat 7.3
- Software: – libvirtd (libvirt) 2.0.0
Requirements
Privileged access to your Redhat Linux installation is required.
Difficulty
EASY
Conventions
- # – requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudo
command - $ – requires given linux commands to be executed as a regular non-privileged user
Instructions
Create New Virtual Storage Directory
Let’s start by creating a new virtual storage directory. For example within a home directory of our current user /home/linuxconfig/kvm-vms/
. If you need to create a new Virtual Storage directory outside of your home directory you may need to execute the below command with administrative privileges:
$ mkdir /home/linuxconfig/kvm-vms/
Configure SELinux Context
Configure SELinux Context for a new storage directory. This step can be omitted if SELinux is disabled on your system:
# semanage fcontext -t virt_image_t -a '/home/linuxconfig/kvm-vms(/.*)?' # restorecon /home/linuxconfig/kvm-vms/
Set New Default Virtual Storage Directory
Lastly, set your new directory as default by creating a symbolic link to /var/lib/libvirt/images
directory. The below commands assume that your current /var/lib/libvirt/images
is empty:
# rmdir /var/lib/libvirt/images/ # ln -s /home/linuxconfig/kvm-vms/ /var/lib/libvirt/images