translated

This commit is contained in:
geekpi 2023-07-10 08:42:36 +08:00
parent 883725836d
commit 04ad5ce22e
2 changed files with 174 additions and 174 deletions

View File

@ -1,174 +0,0 @@
[#]: 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: "geekpi"
[#]: 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

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: "geekpi"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
使用 virtiofs 在 KVM 中的 Windows 客户机和 Linux 主机之间共享文件夹
======
**在本指南中,你将了解如何在 Linux 主机(例如使用 KVM 的 Fedora、Ubuntu 或 Linux Mint下运行的 Windows 客户机之间共享文件夹。**
[virt-manager][1] 应用(带有 [libvirt][2])和软件包提供了一组灵活的工具来管理 Linux 中的虚拟机。它是免费且开源的,用于 KVM 虚拟机和其他虚拟机管理程序。
在上一篇文章中,我解释了[如何在 Linux 客户机和 Linux 主机之间共享文件夹][3]。然而,当你尝试使用 Windows 客户机和 Linux 主机创建共享文件夹时,这是一个有点困难和复杂的过程。因为两种操作系统的工作方式不同,需要进行大量配置。
按照下面提到的说明在 Windows 客户机和 Linux 主机之间共享文件夹。
### 关于 virtiofs 的说明
共享文件和文件夹由名为 virtiofs 的 libvirt 共享文件系统提供支持。它提供了访问主机上目录树的所有功能和参数。由于大多数 virt-manager 虚拟机配置都会转换为 XML因此共享文件/文件夹也可以由 XML 文件指定。
注意:如果你正在寻求在**两台 Linux 计算机**(客户机和主机)之间使用 KVM 进行文件共享,请[阅读本文][3]。
### 使用 KVM 在 Windows 客户机和 Linux 主机之间共享文件夹
以下说明假设你已在任何 Linux 主机的 virt-manager 中安装了 Windows。如果没有你可以阅读有关如何在 Linux 中安装 Windows 的完整指南。
#### 在 virt-manager 中设置挂载标签
- 首先,确保你的客户虚拟机已关闭。从 virt-manager GUI 中,选择虚拟机并单击“打开”以调出控制台设置。
![打开控制台设置][4]
- 单击工具栏中显示虚拟硬件详细信息的图标。然后单击左侧面板上的“**内存**”。
- 选择选项“**启用共享内存**”。单击“应用”。
- 确保 XML 在 XML 选项卡中显示 “access mode=shared”如下所示。
```
<memoryBacking>
<source type="memfd"/>
<access mode="shared"/>
</memoryBacking>
```
![启用共享内存][5]
- 单击底部的“添加硬件”。
- 从添加新硬件窗口的左侧面板中选择“**文件系统**”。
- 然后在详细信息选项卡中选择 **Driver=virtiofs**。单击`浏览 > 浏览本地`并从 Linux 系统中**选择主机路径**。
- 在目标路径中,输入你想要的任何名称。它只是一个文件标签,将在挂载过程中使用。目标路径中的此名称将作为 Windows 中的驱动器挂载,即资源管理器中的我的电脑。
- 我已添加 “linux_pictures” 作为目标挂载标签。
- 因此,如果我想访问图片文件夹(`/home/debugpoint/Pictures`),示例设置可能如下:
- 单击“完成”。
![为 Windows 添加文件系统挂载][6]
上述配置的 XML 设置如下。你可以在 XML 选项卡中找到它。
```
<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>
```
在 virt-manager 主窗口中,右键单击 Windows 虚拟机,然后单击“运行”启动虚拟机。如果未显示虚拟机,请单击“显示图形控制台”(工具栏中的监视器图标)。
#### 设置 WinFSP 适用于 Windows 的 FUSE
确保 Windows 虚拟机(客户机)正在运行。
- 首先,我们需要安装 WinFSP 或称为 Windows File System Proxy FUSE for Windows。这使你能够毫无困难地挂载任何类 UNIX 文件系统。
- 从客户** Windows 计算机**打开 WinFSP GitHub 中的以下页面。
- 下载 WinFSP .msi 安装程序。
[下载 WinFSP 安装程序][7]
- 在 Windows 虚拟机上安装软件包。安装软件包时请确保选择 “Core”。完成安装。
![WinFSP 设置][8]
#### 创建 VirtIO-FS 服务
- 进入 **stable-virtio** 文件夹,从以下地址下载 **virtio-win-guest-tools.exe**
[下载 virtio-win-guest-tools][9]
![下载客户机工具][10]
- 在 Windows 虚拟机上安装软件包。
![Virtio-Win-driver 安装][11]
- 安装完成后,**重启** Windows 虚拟机。
- 重启后,在开始菜单中搜索打开“设备管理器”。
- 进入系统设备并查找 “VirtIO FS 设备”。它应该被识别并且驱动程序应该由 Red Hat 签名。
- **注意**:(可选)如果你看到感叹号,即未检测到驱动程序,请按照[此处][12]说明如何下载 ISO 文件、安装它并手动检测驱动程序。
![Make sure the Virt IO driver is signed and installed][13]
- 打开开始菜单并搜索“服务”。
- 向下滚动找到 “VirtIO-FS Service”。右键单击并单击“开始”启动该服务。
- 或者,你可以以管理员身份从 PowerShell/命令提示符运行以下命令来启动服务。
```
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
```
![启动 Virt IO 服务][14]
- 服务启动后,打开资源管理器,你应该看到你在上面第一步中创建的挂载标签,该标签应映射为 Z 驱动器。见下图。
- 你现在可以根据需要使用修改后的权限访问整个 Linux 文件夹。
![挂载标签在 Windows 中映射为 Z 驱动器][15]
以下是在 Linux Mint 和 Windows 客户虚拟机中访问的同一文件夹的并排比较。
![访问和共享 Windows 客户机和 Linux 主机中的文件夹][16]
### 总结
我希望你现在能够在 Windows 客户机和 Linux 主机系统之间共享文件夹。本文在 Linux Mint 中测试了上述方法。它应该也适用于 Ubuntu、Fedora。
如果上述方法有效,请在下面发表评论以造福他人。
**_参考_**
- [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]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者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