Tutorial: Share a Directory via QEMU Between Debian Host and Windows Guest

user1272047user1272047
3 min read

Tutorial: Share a Directory via QEMU Between Debian Host and Windows Guest

This guide explains how to share a directory between a Debian host and a Windows guest using QEMU with virtiofs.


Prerequisites

  1. Debian Host: Running QEMU/KVM and virt-manager.

  2. Windows Guest: Installed and operational within QEMU.

  3. Virtiofsd Package: Installed on the host.

  4. WinFSP: Installed on the Windows guest.


Steps to Share a Directory

Step 1: Install Required Tools on Host

Ensure virtiofsd is installed on your Debian host. Run:

sudo apt update
sudo apt install virtiofsd qemu-system qemu-utils virt-manager

Step 2: Configure the Virtual Machine

  1. Shut down the Windows Guest: Open virt-manager, select your VM, and power it off.

  2. Edit Virtual Machine Settings:

    • Open virt-manager, right-click your Windows VM, and select "Open".

    • Click the "Show virtual hardware details" icon.

    • Scroll down and select Add Hardware > Filesystem.

  3. Configure Filesystem Sharing:

    • Set the Driver to virtiofs.

    • Set the Source Path to the directory you want to share (e.g., /media/backup_005_3/qemu.shared).

    • Set the Target Path to a tag name (e.g., shared_folder).

    • Click "Finish" and "Apply".


Step 3: Verify XML Configuration

Check and edit the VM's XML configuration to ensure virtiofs is properly configured.

  1. In virt-manager, go to the "XML" tab for your VM.

  2. Ensure the following snippet exists:

<filesystem type="mount" accessmode="passthrough">
  <driver type="virtiofs"/>
  <source dir="/media/backup_005_3/qemu.shared"/>
  <target dir="shared_folder"/>
</filesystem>
  1. Save and close.

Step 4: Install Virtio Drivers on Windows Guest

  1. Download Virtio Drivers:

  2. Mount ISO in Windows Guest:

    • Attach the ISO as a CD drive in virt-manager.

    • Boot the Windows VM and run the installer from the mounted ISO.

  3. Install WinFSP:

    • Download the WinFSP installer in the Windows guest.

    • Install it with the "Core" feature enabled.


Step 5: Start Virtio-FS Service

  1. Enable Virtio-FS in Device Manager:

    • Open "Device Manager" in Windows.

    • Verify the "VirtIO FS Device" is listed under "System Devices".

    • If not, reinstall the VirtIO drivers.

  2. Start the Virtio-FS Service:

    • Open "Services" in Windows.

    • Locate "VirtIO-FS Service".

    • Start the service and set its startup type to "Automatic".

    •   PS C:\WINDOWS\system32> Start-Process -FilePath sc.exe -ArgumentList 'config VirtioFsSvc start= auto' -NoNewWindow -Wait
        [SC] ChangeServiceConfig SUCCESS
        PS C:\WINDOWS\system32>
      

Step 6: Mount the Shared Directory in Windows

  1. Open a Command Prompt or PowerShell in Windows.

  2. Use the following command to map the shared folder to a drive letter (e.g., Z:):

net use Z: \\127.0.0.1\shared_folder
  • Replace shared_folder with the Target Path you set earlier.
  1. Verify the shared folder appears in "This PC" as drive Z:.

Troubleshooting

  • Driver Not Found: Ensure virtiofsd is installed on the Debian host and the VirtIO drivers are correctly installed in the guest.

  • Directory Not Mounted: Recheck the XML configuration and the shared folder path.

  • Permissions Issues: Verify permissions on the shared directory using chmod or chown on the host.


Conclusion

By following these steps, you can seamlessly share a directory between your Debian host and a Windows guest using QEMU. This method leverages the high-performance virtiofs technology for efficient file sharing.

0
Subscribe to my newsletter

Read articles from user1272047 directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

user1272047
user1272047