Ce contenu n'est pas disponible dans la langue sélectionnée.

Chapter 20. 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).

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.

When using RHEL 10 as your hypervisor, you can efficiently share files between your host system and Windows virtual machines (VM) using the virtiofs feature along with the virtio-win package.

Note

You can run the virtiofs service in case-insensitive mode on a Windows VM using the virtiofs.exe command and the -i parameter.

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 shared-files.

    # mkdir /root/shared-files
    Copy to Clipboard Toggle word wrap
  • You have attached the virtio driver installation media to the VM.
  • You have attached the virtio driver installation media to the VM.
  • You have installed the virtio-win package on your Windows VM. For more information, see Installing virtio drivers on a Windows guest.

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 Toggle word wrap
    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 Toggle word wrap

      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 Toggle word wrap
  3. Boot up the VM.

    # virsh start vm-name
    Copy to Clipboard Toggle word wrap
  4. On your Windows VM, install WinFsp. To do so, mount the virtio-win ISO image, start the winfsp MSI installer, and follow the prompts.

    In the Custom Setup window of the installation wizard, select the features you want to install on the VM.

  5. Start the virtiofs service:

    # sc start VirtioFsSvc
    Copy to Clipboard Toggle word wrap
  6. Navigate to This PC:

    File Explorer This PC

    If configured correctly, virtiofs is available on the Windows VM as the first available drive letter starting with Z: and going backwards. For example, my_viofs (Z:).

    Important

    You must restart the virtiofs service after each VM reboot to access the shared directory.

  7. Optional: To set up additional virtiofs instances:

    1. Stop the virtiofs service:

      # sc stop VirtioFsSvc
      # sc config VirtioFsSvc start=demand
      Copy to Clipboard Toggle word wrap
    2. Configure the WinFSP.Launcher service to set up multiple virtiofs instances:

      # "C:\Program Files (x86)\WinFsp\bin\fsreg.bat" virtiofs "<path to the binary>\virtiofs.exe" "-t %1 -m %2"
      Copy to Clipboard Toggle word wrap
    3. Mount virtiofs instances to drives.

      For example, to mount virtiofs with the tag mount_tag0 to the Y: drive:

      "C:\Program Files (x86)\WinFsp\bin\launchctl-x64.exe" start virtiofs viofsY mount_tag0 Y:
      Copy to Clipboard Toggle word wrap
    4. Repeat the previous step to mount all of your virtiofs instances.
    5. To unmount the virtiofs instance:

      "C:\Program Files (x86)\WinFsp\bin\launchctl-x64.exe" stop virtiofs viofsY
      Copy to Clipboard Toggle word wrap

Verification

  1. On your Windows VM, navigate to This PC:

    File Explorer This PC

    • If you did not specify a mount point when setting up the virtiofs service, it will use the first available drive letter starting with z: and going backwards.
    • If you have multiple virtiofs instances set up, they will appear as drives with the letters you had assigned to the instances.
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat