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 its virtual machines by using virtiofs

By using the virtio file system (virtiofs), you can share files between your host and your virtual machines (VM) as a directory tree that works the same as the local file system structure.

19.1.1. Sharing files between the host and Linux virtual machines by using the command line

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
    Copy to Clipboard
  • The VM you want to share files with is using a Linux distribution as its guest operating system.

Procedure

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

    1. Open the XML configuration of the intended VM.

      # virsh edit vm-name
      Copy to Clipboard
    2. Add 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>
      Copy to Clipboard

      This example sets the /root/shared-files directory on the host to be visible as host-file-share to the VM.

  2. 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>
    Copy to Clipboard
  3. Boot up the VM.

    # virsh start vm-name
    Copy to Clipboard
  4. Mount the file system in the guest operating system. The following example mounts the previously configured host-file-share directory with a Linux guest operating system.

    # mount -t virtiofs host-file-share /mnt
    Copy to Clipboard

Verification

  • Ensure that the shared directory became accessible on the VM and that you can now open files stored in the directory.

Known issues and limitations

  • File-system mount options related to access time, such as noatime and strictatime, are not likely to work with virtiofs, and Red Hat discourages their use.

19.1.2. Sharing files between the host and Linux virtual machines by using the web console

You can use the RHEL web console to efficiently share files between your host system and its virtual machines (VM) by using the virtiofs feature.

Prerequisites

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

    # mkdir /home/centurion
    Copy to Clipboard
  • The VM you want to share data with is using a Linux distribution as its guest operating system.

Procedure

  1. In the Virtual Machines 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.

  2. Scroll to Shared directories.

    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.

  3. Click Add shared directory.

    The Share a host directory with the guest dialog is displayed.

  4. 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.
  5. Set additional options:

    • Extended attributes - Set whether to enable extended attributes, xattr, on the shared files and directories.
  6. Click Share.

    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.

19.1.3. Removing files shared between the host and Linux virtual machines by using the web console

You can use the RHEL web console to remove files shared between your host system and its virtual machines (VM) by using the virtiofs feature.

Prerequisites

  • The web console VM plugin is installed on your system.
  • The shared directory that you want to remove is no longer being used by the VM.

Procedure

  1. In the Virtual Machines interface, click the VM from which you want to remove the shared files.

    A new page opens with an Overview section with basic information about the selected VM and a Console section.

  2. Scroll to Shared directories.

    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.

  3. Click Remove next to the directory that you want to unshare with the VM.

    The Remove filesystem dialog is diplayed.

  4. Click Remove.

    The selected directory is unshared with the VM.

Verification

  • Ensure that the shared directory is no longer available and accessible on the VM.
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat