Merge pull request #29491 from lkxed/20230602-1-Share-Folder-Between-Windows-Guest-and-Linux-Host-in-KVM-using-virtiofs

[手动选题][tech]: 20230602.1 ️ Share Folder Between Windows Guest and Linux Host in KVM using virtiofs.md
This commit is contained in:
Xingyu.Wang 2023-06-06 15:05:55 +08:00 committed by GitHub
commit face6899c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -0,0 +1,174 @@
[#]: subject: "Share Folder Between Windows Guest and Linux Host in KVM using virtiofs"
[#]: via: "https://www.debugpoint.com/kvm-share-folder-windows-guest/"
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
[#]: collector: "lkxed"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Share Folder Between Windows Guest and Linux Host in KVM using virtiofs
======
**In this guide, you will learn how to share a folder between Windows guest, running under a Linux host such as Fedora, Ubuntu or Linux Mint using KVM.**
The [virt-manager][1] application (with [libvirt][2]) and packages provide a flexible set of tools to manage virtual machines in Linux. It is free and open-source and used for KVM virtual machines and other hypervisors.
In the prior article, I explained [how to share folders between a Linux guest and a Linux host][3]. However, when you are trying to create a shared folder using Windows Guest and Linux host, its a little difficult and complex process. Because both the operating system works differently and a lot of configuration is needed.
Follow the below instructions as mentioned to share the folder between Windows guest and Linux host.
### A note about virtiofs
The sharing files and folders are powered by the libvirt shared file system called virtiofs. It provides all the features and parameters to access the directory tree on the host machine. Since most of the virt-manager virtual machine configurations are translated to XML, the share files/folders can also be specified by the XML file.
Note: If you are looking for file sharing using KVM between **two Linux machines** (guest and host), [read this article][3].
### Share folder between Windows guest and Linux host using KVM
The following instructions assume that you have installed Windows in virt-manager in any Linux host. If not, you can read this complete guide on how to install Windows in Linux.
#### Set up a mount tag in virt-manager
- First, make sure your guest virtual machine is powered off. From the virt-manager GUI, select the virtual machine and click on Open to pull up the console settings.
![Open the console settings][4]
- Click on the icon which says show virtual hardware details in the toolbar. And then click on **Memory** on the left panel.
- Select the option “**Enable shared memory**“. Click Apply.
- Make sure the XML shows “access mode=shared” as below in the XML tab.
```
<memoryBacking>
<source type="memfd"/>
<access mode="shared"/>
</memoryBacking>
```
![Enable shared memory][5]
- Click “Add hardware” at the bottom.
- Select **File system** from the left panel in the add new hardware window.
- Then select **Driver=virtiofs** in the details tab. Click on `browse > browse local` and **select the host path** from your Linux system.
- In the target path, mention any name you want. Its just a file tag which will be used during mount. This name in the target path will be mounted as Drive in Windows My PC in Explorer.
- I have added “linux_pictures” as the target mount tag.
- So, if I want to access the Pictures folder (`/home/debugpoint/Pictures`), sample settings could be the following:
- Click Finish.
![Add a file system mount for windows][6]
The XML settings are below for the above configuration. You can find it in the XML tab.
```
<filesystem type="mount" accessmode="passthrough">
<driver type="virtiofs"/>
<source dir="/home/debugpoint/Pictures"/>
<target dir="linux_pictures"/>
<address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
</filesystem>
```
In the main virt-manager window, right-click on the Windows virtual machine and click Run to start the virtual machine. Make sure to click on the “show the graphical console” (monitor icon in the toolbar) if the VM is not showing.
#### Set up WinFSP FUSE for Windows
Make sure Windows virtual machine (guest) is running.
- First, we need to set up the WinFSP or Windows File System Proxy FUSE for Windows. This enables you to mount any UNIX-like filesystem without any difficulties.
- Open the below page in the WinFSP GitHub **from the guest** Windows machine.
- Download the WinFSP .msi installer.
[Download WinFSP installer][7]
- Install the package on Windows virtual machine. Make sure to select “Core” while installing the package. Finish the installation.
![WinFSP set up][8]
#### Create VirtIO-FS as a service
- Download the **virtio-win-guest-tools.exe** from the below path by going inside **stable-virtio** folder.
[Download virtio-win-guest-tools][9]
![Download guest tools][10]
- Install the package on Windows virtual machine.
![Virtio-Win-driver installation][11]
- After installation is complete, **reboot** Windows virtual machine.
- After reboot, open the “Device Manager” by searching in the start menu.
- Navigate to System devices and look for “VirtIO FS Device”. It should be recognized and driver should be signed by Red Hat.
- **Note**: (optional) If you see an exclamation mark i.e. driver is not detected, then follow the instructions [here][12] on how to download ISO file, mount it and manually detect the driver.
![Make sure the Virt IO driver is signed and installed][13]
- Open the start menu and search for “Services”.
- Scroll down to find out the “VirtIO-FS Service”. Right-click and hit Start to start the service.
- Alternatively, you can run the below command from PowerShell/command prompt as admin to start the service.
```
sc create VirtioFsSvc binpath="C:\Program Files\Virtio-Win\VioFS\virtiofs.exe" start=auto depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"
```
```
sc start VirtioFsSvc
```
![Start the Virt IO Service][14]
- After the service start, open Explorer, and you should see the mount tag which you have created in the first step above, which should be mapped as Z drive. See below.
- You can now access the entire Linux folder with modified permission as per your need.
![The mount tag is mapped as Z drive in windows][15]
Here is a side-by-side comparison of the same folder accessed in Linux Mint and Windows guest.
![Access and share folder in Windows guest and Linux host][16]
### Conclusion
I hope you can now able to share a folder between Windows guest and Linux host system. The above method is tested in Linux Mint for this article. It should work for Ubuntu, Fedora as well.
If the above method works, drop a comment below for the benefit of others.
**_References_**
- [https://virtio-fs.gitlab.io/howto-windows.html][12]
- [https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/][17]
- [https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md][18]
- [https://github.com/virtio-win/kvm-guest-drivers-windows/issues/473][19]
--------------------------------------------------------------------------------
via: https://www.debugpoint.com/kvm-share-folder-windows-guest/
作者:[Arindam][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.debugpoint.com/author/admin1/
[b]: https://github.com/lkxed/
[1]: https://virt-manager.org/
[2]: https://libvirt.org/manpages/libvirtd.html
[3]: https://www.debugpoint.com/share-folder-virt-manager/
[4]: https://www.debugpoint.com/wp-content/uploads/2023/06/Open-the-console-settings.jpg
[5]: https://www.debugpoint.com/wp-content/uploads/2023/06/Enable-shared-memory.jpg
[6]: https://www.debugpoint.com/wp-content/uploads/2023/06/Add-a-file-system-mount-for-windows.jpg
[7]: https://github.com/winfsp/winfsp/releases/
[8]: https://www.debugpoint.com/wp-content/uploads/2023/06/WinFSP-set-up.jpg
[9]: https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/
[10]: https://www.debugpoint.com/wp-content/uploads/2023/06/Download-guest-tools.jpg
[11]: https://www.debugpoint.com/wp-content/uploads/2023/06/Virtio-Win-driver-installation.jpg
[12]: https://virtio-fs.gitlab.io/howto-windows.html
[13]: https://www.debugpoint.com/wp-content/uploads/2023/06/Make-sure-the-Virt-IO-driver-is-signed-and-installed.jpg
[14]: https://www.debugpoint.com/wp-content/uploads/2023/06/Start-the-Virt-IO-Service.jpg
[15]: https://www.debugpoint.com/wp-content/uploads/2023/06/The-mount-tag-is-mapped-as-Z-drive-in-windows.jpg
[16]: https://www.debugpoint.com/wp-content/uploads/2023/06/Access-and-share-folder-in-Windows-guest-and-Linux-host-2048x1280.jpg
[17]: https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/
[18]: https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
[19]: https://github.com/virtio-win/kvm-guest-drivers-windows/issues/473