Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 19. Sharing files between the host and its virtual machines
You might frequently require to share data between your host system and the virtual machines (VMs) it runs. To do so quickly and efficiently, you can use the virtio file system (virtiofs).
19.1. Sharing files between the host and Linux virtual machines by using the command line Copier lienLien copié sur presse-papiers!
When using RHEL 10 as your hypervisor, you can share files between your host system and its virtual machines (VM) by using the virtiofs feature.
Prerequisites
- Virtualization is installed and enabled on your RHEL 10 host.
A directory is available that you want to share with your VMs. If you do not want to share any of your existing directories, create a new one, for example named shared-files.
# mkdir /root/shared-files- The VM you want to share files with is using a Linux distribution as its guest operating system.
Procedure
For each directory on the host that you want to share with your VM, set it as a virtiofs file system in the VM’s XML configuration.
Open the XML configuration of the intended VM.
# virsh edit vm-nameAdd an entry similar to the following to the
<devices>section of the VM’s XML configuration.<filesystem type='mount' accessmode='passthrough'> <driver type='virtiofs'/> <binary path='/usr/libexec/virtiofsd' xattr='on'/> <source dir='/root/shared-files'/> <target dir='host-file-share'/> </filesystem>This example sets the
/root/shared-filesdirectory on the host to be visible ashost-file-shareto the VM.
Set up shared memory for the VM. To do so, add shared memory backing to the
<domain>section of the XML configuration:<domain> [...] <memoryBacking> <access mode='shared'/> </memoryBacking> [...] </domain>Boot up the VM.
# virsh start vm-nameMount the file system in the guest operating system. The following example mounts the previously configured
host-file-sharedirectory with a Linux guest operating system.# mount -t virtiofs host-file-share /mnt
Verification
- Ensure that the shared directory became accessible on the VM and that you can now open files stored in the directory.
Troubleshooting
-
File-system mount options related to access time, such as
noatimeandstrictatime, are not likely to work with virtiofs, and Red Hat discourages their use.
19.2. Sharing files between the host and Linux virtual machines by using the web console Copier lienLien copié sur presse-papiers!
To share files between your host system and its virtual machines (VM), you can use the virtiofs feature in the RHEL web console.
Prerequisites
- The web console VM plug-in is installed on your system.
A directory that you want to share with your VMs. If you do not want to share any of your existing directories, create a new one, for example named shared-files.
# mkdir /home/shared-files- The VM you want to share data with is using a Linux distribution as its guest operating system.
Procedure
In the interface, click the VM with which you want to share files.
A new page opens with an Overview section with basic information about the selected VM and a Console section.
Scroll to .
The Shared directories section displays information about the host files and directories shared with that VM and options to Add or Remove a shared directory.
Click .
The Share a host directory with the guest dialog is displayed.
Enter the following information:
- Source path - The path to the host directory that you want to share.
- Mount tag - The tag that the VM uses to mount the directory.
Set additional options:
-
Extended attributes - Set whether to enable extended attributes,
xattr, on the shared files and directories.
-
Extended attributes - Set whether to enable extended attributes,
Click .
The selected directory is shared with the VM.
Verification
- Ensure that the shared directory is accessible on the VM and you can now open files stored in that directory.