12.5. Sharing virtual machine disk images with other hosts
To perform a live migration of a virtual machine (VM) between supported KVM hosts, shared VM storage is required. The following procedure provides instructions for sharing a locally stored VM image with the source host and the destination host using the NFS protocol.
Conditions préalables
- The VM intended for migration is shut down.
- Optional: A host system is available for hosting the storage that is not the source or destination host, but both the source and the destination host can reach it through the network. This is the optimal solution for shared storage and is recommended by Red Hat.
- Make sure that NFS file locking is not used as it is not supported in KVM.
The NFS is installed and enabled on the source and destination hosts. If it is not:
Install the NFS packages:
# dnf install nfs-utils
Make sure that the ports for NFS, such as 2049, are open in the firewall.
# firewall-cmd --permanent --add-service=nfs # firewall-cmd --permanent --add-service=mountd # firewall-cmd --permanent --add-service=rpc-bind # firewall-cmd --permanent --add-port=2049/tcp # firewall-cmd --permanent --add-port=2049/udp # firewall-cmd --reload
Start the NFS service.
# systemctl start nfs-server
Procédure
Connect to the host that will provide shared storage. In this example, it is the
cargo-bay
host:# ssh root@cargo-bay root@cargo-bay's password: Last login: Mon Sep 24 12:05:36 2019 root~#
Create a directory that will hold the disk image and will be shared with the migration hosts.
# mkdir /var/lib/libvirt/shared-images
Copy the disk image of the VM from the source host to the newly created directory. For example, the following copies the disk image of the
wanderer1
VM to the/var/lib/libvirt/shared-images/
directory on the`cargo-bay` host:# scp /var/lib/libvirt/images/wanderer1.qcow2 root@cargo-bay:/var/lib/libvirt/shared-images/wanderer1.qcow2
On the host that you want to use for sharing the storage, add the sharing directory to the
/etc/exports
file. The following example shares the/var/lib/libvirt/shared-images
directory with thesource-example
anddest-example
hosts:/var/lib/libvirt/shared-images source-example(rw,no_root_squash) dest-example(rw,no_root_squash)
On both the source and destination host, mount the shared directory in the
/var/lib/libvirt/images
directory:# mount cargo-bay:/var/lib/libvirt/shared-images /var/lib/libvirt/images
Vérification
- To verify the process was successful, start the VM on the source host and observe if it boots correctly.