mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
translated
This commit is contained in:
parent
a320ab8bcb
commit
732ba00ca3
@ -1,110 +0,0 @@
|
||||
[#]: subject: "Share Folder Between Guest and Host in virt-manager (KVM/Qemu/libvirt)"
|
||||
[#]: via: "https://www.debugpoint.com/share-folder-virt-manager/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Share Folder Between Guest and Host in virt-manager (KVM/Qemu/libvirt)
|
||||
======
|
||||
|
||||
**In this guide, you will learn how to share a folder between host and guest in virt-manager using KVM, QEMU and libvirt.**
|
||||
|
||||
The [virt-manager][1] application or package uses the [libvirt][2] library to provide virtual machine management services. It has a desktop interface that helps to create, delete, and manage multiple virtual machines.
|
||||
|
||||
The virt-manager desktop interface and its components provide flexible virtual machine management services for various personal and business use cases. it is a free and open-source application primarily used for KVM virtual machines. However, it can also support other hypervisors such as Xen and LXC.
|
||||
|
||||
In the earlier article, I explained [how to create a virtual machine using virt-manager][3]. This article covers how you can seamlessly access files and folders between guest and host virtual machines.
|
||||
|
||||
### 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.
|
||||
|
||||
### Share folder 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 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.
|
||||
|
||||
![Enable the shared memory option][5]
|
||||
|
||||
- And then click “Add hardware” at the bottom.
|
||||
|
||||
![Click on add hardware][6]
|
||||
|
||||
- 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** you want to access inside the guest VM.
|
||||
- In the target path, mention any name you want. It’s just a file tag which will be used during mount.
|
||||
- So, if I want to access the Pictures/Screenshots folder (`/home/debugpoint/Pictures/Screenshots`), sample settings could be the following:
|
||||
|
||||
![Add a new file system hardware][7]
|
||||
|
||||
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"/>
|
||||
<binary path="/usr/libexec/virtiofsd"/>
|
||||
<source dir="/home/debugpoint/Pictures/Screenshots"/>
|
||||
<target dir="mount_tag_pictures"/>
|
||||
<alias name="fs1"/>
|
||||
<address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
|
||||
</filesystem>
|
||||
```
|
||||
|
||||
Click on Finish. In the main virt-manager window, right-click on the VM 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.
|
||||
|
||||
In the guest machine, create a folder where you want to mount the host folder. For this example, I have used /mnt/pictures.
|
||||
|
||||
```
|
||||
sudo mkdir /mnt/pictures
|
||||
```
|
||||
|
||||
And finally, mount the host folder using the tag you created in the above step to this new folder. Use the following command to do that from the terminal. Ensure to change the tag and folder name in the below command as your system.
|
||||
|
||||
```
|
||||
sudo mount -t virtiofs mount_tag_pictures /mnt/pictures
|
||||
```
|
||||
|
||||
Now you can browse the folders and add/delete items seamlessly in virt-manager between host and guest.
|
||||
|
||||
![Access host files from virt-manager guest][8]
|
||||
|
||||
### Wrapping Up
|
||||
|
||||
I hope this solution helps you to access host files and folders from the guest machine. Remember, your user Id, which is used to launch the virt-manager app, should have the same access to the host folder.
|
||||
|
||||
If you run into any errors, the above guide helped you drop a note below.
|
||||
|
||||
_[Reference][9]_
|
||||
|
||||
[_Using Mastodon? Follow us at floss.social/@debugpoint_][10]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/share-folder-virt-manager/
|
||||
|
||||
作者:[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/virt-manager/
|
||||
[4]: https://www.debugpoint.com/wp-content/uploads/2023/01/Open-the-settings.jpg
|
||||
[5]: https://www.debugpoint.com/wp-content/uploads/2023/01/Enable-the-shared-memory-option.jpg
|
||||
[6]: https://www.debugpoint.com/wp-content/uploads/2023/01/Click-on-add-hardware.jpg
|
||||
[7]: https://www.debugpoint.com/wp-content/uploads/2023/01/Add-a-new-file-system-hardware.jpg
|
||||
[8]: https://www.debugpoint.com/wp-content/uploads/2023/01/Access-host-files-from-virt-manager-guest.jpg
|
||||
[9]: https://libvirt.org/kbase/virtiofs.html
|
||||
[10]: https://floss.social/@debugpoint
|
@ -0,0 +1,109 @@
|
||||
[#]: subject: "Share Folder Between Guest and Host in virt-manager (KVM/Qemu/libvirt)"
|
||||
[#]: via: "https://www.debugpoint.com/share-folder-virt-manager/"
|
||||
[#]: author: "Arindam https://www.debugpoint.com/author/admin1/"
|
||||
[#]: collector: "lkxed"
|
||||
[#]: translator: "geekpi"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
在 virt-manager 中,在客户机和主机之间共享文件夹(KVM/Qemu/libvirt)
|
||||
======
|
||||
|
||||
**在本指南中,你将学习如何使用 KVM、QEMU 和 libvirt 在 virt-manager 中的主机和客户机之间共享文件夹。**
|
||||
|
||||
|
||||
[virt-manager][1] 应用或软件包使用 [libvirt][2] 库来提供虚拟机管理服务。它有一个桌面界面,有助于创建、删除和管理多个虚拟机。
|
||||
|
||||
virt-manager 桌面界面及其组件为各种个人和商业场景提供了灵活的虚拟机管理服务。它是一个免费和开源的应用,主要用于 KVM 虚拟机。然而,它也可以支持其他管理程序,如 Xen 和 LXC。
|
||||
|
||||
在之前的文章中,我解释了[如何使用 virt-manager 创建虚拟机][3]。这篇文章介绍了如何在客户机和主机之间无缝访问文件和文件夹。
|
||||
|
||||
### 关于 virtiofs 的说明
|
||||
|
||||
共享文件和文件夹是由名为 virtiofs 的 libvirt 共享文件系统提供的。它提供了所有的功能和参数来访问主机上的目录树。由于大多数 virt-manager 虚拟机的配置都被翻译成 XML,所以共享文件/文件夹也可以通过 XML 文件来指定。
|
||||
|
||||
### 在 virt-manager中共享文件夹
|
||||
|
||||
- 首先,确保你的客户机关闭了电源。在 virt-manager GUI 中,选择虚拟机,点击打开,弹出控制台设置。
|
||||
|
||||
![打开设置][4]
|
||||
|
||||
- 点击工具条上显示虚拟硬件细节的图标。然后点击左边面板上的**内存**。
|
||||
- 选择选项“**启用共享内存**”。点击应用。
|
||||
|
||||
![启用共享内存选项][5]
|
||||
|
||||
- 然后点击底部的“添加硬件”。
|
||||
|
||||
![点击添加硬件][6]
|
||||
|
||||
- 在添加新硬件的窗口中,从左边的面板上选择**文件系统**。
|
||||
- 然后在细节标签中选择 **Driver=virtiofs**。点击“浏览>浏览本地”,**选择你想在客户机内访问的主机路径**。
|
||||
- 在目标路径中,输入你想要的任何名字。这只是一个文件标签,将在挂载时使用。
|
||||
- 所以,如果我想访问 Pictures/Screenshots 文件夹(`/home/debugpoint/Pictures/Screenshots`),示例设置可以是这样:
|
||||
|
||||
![添加一个新的文件系统硬件][7]
|
||||
|
||||
下面是上述配置的 XML 设置。你可以在 XML 标签中找到它。
|
||||
|
||||
```
|
||||
<filesystem type="mount" accessmode="passthrough">
|
||||
<driver type="virtiofs"/>
|
||||
<binary path="/usr/libexec/virtiofsd"/>
|
||||
<source dir="/home/debugpoint/Pictures/Screenshots"/>
|
||||
<target dir="mount_tag_pictures"/>
|
||||
<alias name="fs1"/>
|
||||
<address type="pci" domain="0x0000" bus="0x08" slot="0x00" function="0x0"/>
|
||||
</filesystem>
|
||||
```
|
||||
|
||||
点击“完成”。在 virt-manager 主窗口中,右键点击虚拟机,点击运行,启动虚拟机。确保点击“显示图形控制台”(如果虚拟机没有显示,点击工具条上的监视器图标)。
|
||||
|
||||
在客户机中,创建一个你想挂载主机文件夹的文件夹。在这个例子中,我使用了 /mnt/pictures。
|
||||
|
||||
```
|
||||
sudo mkdir /mnt/pictures
|
||||
```
|
||||
|
||||
最后,使用你在上述步骤中创建的标签将主机文件夹挂载到这个新文件夹。使用下面的命令在终端做这件事。确保根据你的系统改变下面命令中的标签和文件夹名称。
|
||||
|
||||
```
|
||||
sudo mount -t virtiofs mount_tag_pictures /mnt/pictures
|
||||
```
|
||||
|
||||
现在你可以在主机和客户机之间的 virt-manager 中无缝地浏览文件夹和添加/删除项目。
|
||||
|
||||
![从 virt-manager 客户机访问主机文件][8]
|
||||
|
||||
### 总结
|
||||
|
||||
我希望这个方案能帮助你从客户机上访问主机文件和文件夹。记住,你的用户 ID,也就是用来启动 virt-manager 应用的用户,应该有同样的权限来访问主机文件夹。
|
||||
|
||||
如果你遇到任何错误,上述指南帮助了你,请在下面留言。
|
||||
|
||||
_[参考][9]_
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://www.debugpoint.com/share-folder-virt-manager/
|
||||
|
||||
作者:[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/virt-manager/
|
||||
[4]: https://www.debugpoint.com/wp-content/uploads/2023/01/Open-the-settings.jpg
|
||||
[5]: https://www.debugpoint.com/wp-content/uploads/2023/01/Enable-the-shared-memory-option.jpg
|
||||
[6]: https://www.debugpoint.com/wp-content/uploads/2023/01/Click-on-add-hardware.jpg
|
||||
[7]: https://www.debugpoint.com/wp-content/uploads/2023/01/Add-a-new-file-system-hardware.jpg
|
||||
[8]: https://www.debugpoint.com/wp-content/uploads/2023/01/Access-host-files-from-virt-manager-guest.jpg
|
||||
[9]: https://libvirt.org/kbase/virtiofs.html
|
Loading…
Reference in New Issue
Block a user