Clipboard and folder sharing are usually an important feature to have when we run virtual machines. So here am I sharing the complete guide for you guys.
I found people talking about Qemu/KVM on Reddit, so I decided to try. Main reason why I wanted to try because I want to move away from VirtualBox that I can never enable folder sharing, and VMWare which is paid.
I am currently running Ubuntu 20.04 as the Host and Windows 10 as the Guests.
Problems
It is quite confusing when you first started. I started with virt-manager and had no clipboard sharing enabled. By default, virt-manager is using SPICE. The key to this tutorial is, install spice
-guest-tools
and Spice WebDAV daemon
.
Notes
I am writing this tutorial based on virt-manager. It should be working for any SPICE remote viewer too such as Cockpit (tested).
Solution – Clipboard sharing
(Updated as 26th Oct)
Step 1 – Download spice-guest-tools to Windows Guest
Open the download page (https://cutt.ly/2ROq8dK) on your Windows Guest, scroll down a bit until you found Windows binaries under Guest, click the Windows guest tools link to start the download. Or you can use this link
https://www.spice-space.org/download/windows/spice-guest-tools/spice-guest-tools-latest.exe Or easier, shortened URL: https://cutt.ly/SROqBqZ
Step 2 – Run and install spice-guest-tools
After the file is available on your Windows Guest, run and install the program.
The display might blinking a few times, so don’t worry about that.
Step 3 – Test your copy/paste
You are pretty much finished. Try copying something in your Windows Guest and paste it in your Host, it should work. But if it doesn’t, try rebooting the VM. If it still won’t work, remove the program and reinstall. It should be working.
Solution – Folder sharing
(Updated as 26th Oct)
So, you have clipboard sharing enabled and now want to share folder?
We will be using virt-manager
and Cockpit
Unfortunately, virt-manager has not implemented SPICE WebDAV in its client. So, we are going to use Cockpit, the alternative.
Step 1 – Install Cockpit and Cockpit Virtual Machines
First, install Cockpit and Cockpit Virtual Machines. For Ubuntu, run
Ubuntu: $ sudo apt install cockpit cockpit-machines Arch: $ sudo pacman -Sy cockpit cockpit-machines
If you are using another Linux distribution, refer this page. You will still need to install cockpit-machines
using your package manager to enable Virtual Machine manager.
Then enable and start cockpit
$ sudo systemctl enable cockpit.socket $ sudo systemctl start cockpit.socket
Step 2 – Open the Web-UI in your browser
Cockpit provides Web-UI which you can access to use the program. Simply open this URL in your browser
http://localhost:9090
Login using your PC user and username
Step 2 – Go to Virtual Machine and shutdown your VM
You need to shutdown your VM or your settings in the next few steps probably won’t work. Simply go to Virtual Machines and hit the Shut Down button to turn off the VM.
Notes: If your Virtual Machine is empty, go to Overview and check if there is a notification at the top asking for a permission. Allow the access and your VMs should be showing up.
Step 3 – Open virt-manager, add new hardware
Open your virt-manager
, right click on your VM and select open. You can also click on your VM, then hit the big “Open” button at the top.
Click Add Hardware and select Channel. Delete whatever in “Name” column, and insert this
org.spice-space.webdav.0
Step 4 – Return to Cockpit Web-UI, run your VM
You don’t need virt-manager for now, so you can close it. Then return to Cockpit Web-UI and hit Run button to start your VM.
Then go to Consoles tab and click “Launch remote viewer”
Notes: You probably need to install Remote Viewer if you are not on Ubuntu. On Arch, Install virt-viewer.
Click “OK” and you will see your Windows Desktop.
Step 5 – Enable Folder Sharing
Click menu File, then select Preferences. tick “Share Folder” and choose which folder you want to share with the Guest.
Notes: On Arch, Preferences is in hamburger menu on the right.
Download and install spice-webdavd in Windows Guest. Pay attention on the file extension. You will want to donwload .msi file which usually larger than the other. Or you can just use this link for the latest installer
https://www.spice-space.org/download/windows/spice-webdavd/spice-webdavd-x86-latest.msi Be aware, some browsers will open the link instead of downloading it. At least Edge displaying the file content to me instead of downloading it.
Then in the Windows, open Task Manager and go to Services tab. Find “spice-webdavd” and start the process if it doesn’t.
Step 7 – Verify the Folder Sharing is working
After running the “Spice webdav proxy” service, you should see a new storage in “This PC” or “My Computer”.
Try creating a file or folder and check shared folder on your Host to see if the changes reflected.
You are now done 🙂
Приложение или пакет virt-manager использует библиотеку libvirt для предоставления услуг управления виртуальными машинами. Оно имеет интерфейс рабочего стола, который помогает создавать, удалять и управлять несколькими виртуальными машинами.
Интерфейс рабочего стола virt-manager и его компоненты предоставляют гибкое управление виртуальными машинами для различных случаев использования. Это бесплатное приложение с открытым исходным кодом, используемое в основном для виртуальных машин KVM. Однако оно может поддерживать и другие гипервизоры, такие как Xen и LXC.
Замечание о virtiofs
Общий доступ к файлам и папкам обеспечивается общей файловой системой libvirt под названием virtiofs. Она предоставляет все возможности и параметры для доступа к дереву каталогов на хост-машине. Поскольку большинство конфигураций виртуальных машин virt-manager переведены в XML, общие файлы/папки также могут быть заданы XML-файлом.
Общая папка в virt-manager
<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 щелкните правой кнопкой мыши на виртуальной машине и нажмите Run, чтобы запустить виртуальную машину. Не забудьте нажать на «показать графическую консоль» (значок монитора на панели инструментов – если ВМ не отображается.
В гостевой машине создайте папку, в которую вы хотите смонтировать папку хоста. Для этого примера я использовал /mnt/pictures.
sudo mkdir /mnt/pictures
И, наконец, смонтируйте папку хоста с помощью метки, созданной в предыдущем шаге, в эту новую папку. Используйте следующую команду для этого. Убедитесь, что имя тега и папки в приведенной ниже команде соответствует вашей системе.
sudo mount -t virtiofs mount_tag_pictures /mnt/pictures
Теперь вы можете просматривать папки и добавлять/удалять элементы без проблем в virt-manager между хостом и гостем.
Подведение итогов
Надеюсь, это решение поможет вам получить доступ к файлам и папкам хоста с гостевой машины. Помните, что ваш идентификатор пользователя, который используется для запуска приложения virt-manager, должен иметь такой же доступ к папке хоста.
Зарубин Иван
Эксперт по Linux и Windows
Парашютист со стажем. Много читаю и слушаю подкасты. Люблю посиделки у костра, песни под гитару и приближающиеся дедлайны. Люблю путешествовать.
Похожие статьи
I’ve been using qemu and libvirt to create and manage virtual
machines under Linux. I’m using Virtual Machine
Manager to graphically manage the machines. I’ve
been really impressed with qemu + KVM performanace, and Virt-Manager provides a
very nice and easy to use interface. There is just one thing lacking, in
comparison to “traditional” desktop virtualization software (eg.
Virtualbox): there is no pre-configured way to
share files between the host and the guest. In contrast, Virtualbox provides a really easy
way to transfer files. As long as the agent is installed you can just “copy
and paste” them over, or drag them into the VM from the host (and vice
versa). In this article, I’ll try to configure an easy way to share files
between the host and the VM. My host is an ArchLinux system, and the two guests
are Fedora 35 and Windows 10. The steps in this article
should be generic enough to “just work” on most other distros, but YMMV.
NB: This is intended as an easy way to share files for classic “desktop”
virtualization settings. It’s not intended for servers, where there are
multiple users on the host or the guests.
We’ll be using the same method for both guests, because it works on Linux and
on Windows. Instead of the “traditional” way (sharing
over the network with SMB, NFS, or 9p), we’ll we using a file system
developed by libvirt called
virtiofs. Virtiofs was developed for
precisely this purpose (“Unlike existing approaches, it is designed to offer
local file system semantics and performance.”). This makes file sharing
easier to configure, since we don’t need to set up a server. It also should
offer very good performance.
Host
To set this up, we first need a folder on the host.
This can be done in several ways. I decided to just create a folder in
/mnt
, and change its ownership to my user:
sudo mkdir /mnt/vfs_share
sudo chown foo:foo /mnt/vfs_share
Then we need to add a virtiofs device.
Virtiofs needs shared memory to work.
This can be enabled
in the hardware configuration window. Navigate to Hardware -> Memory and
select Enable shared memory.
After that, open virt-manager and navigate to the hardware settings of the
virtual machine. Click on Add Hardware.
Virtual Machine Manager hardware configuration window.
A dialog box should pop up. In the pane on the left, click on Filesystem
The ‘Add Hardware’ dialog window
Enter the necessary settings.
Filesystem options
The settings are as follows:
For the Driver, we keep the default (virtiofs). The source path is the path
on our host filesystem. The target path is a bit of a misnomer. It’s not
actually a path, just an identifier that we use as a mount point in our
guest file system. This will become clear when we mount the file system in the
guest later.
If you want a more detailed overview of these options and some
alternatives, check
out the libvirt knowledge base on
virtiofs
Guest
Linux
After that, it’s time to configure the guest. First we create a folder in our
users home directory that we will mount the share into.
After that, we can mount the share with:
sudo mount -t virtiofs share /home/foo/share
If we want to make this permanent, we can just add an entry
to /etc/fstab
share /home/foo/share virtiofs defaults 0 0
After rebooting, the share should be mounted! If your user on the host and the
guest are the same, you don’t even need to worry about any other permissions.
Otherwise, change the folder with chmod
to suit your needs.
Windows 10
Windows 10 can also use virtiofs, but it needs some additional work. First, we
need to install 2 pieces of software:
- WinFSP
- Virtio drivers
This installation can be done in two ways: manually or with chocolatey.
Chocolatey
If you already have Chocolatey installed, it’s as
simple as:
choco install virtio-drivers winfsp
If you don’t have Chocolatey installed, I highly recommend that you check it
out. It’s a package manager for Windows that integrates quite well into the
system. It makes maintaining software on Windows a lot easier! Installation
instructions are here.
During the installation of the virtio-drivers it will pop up a dialog box
asking if you trust the drivers. Confirm the dialog box to install them.
Manual install
Download WinFSP here and install it. The default
options are fine if you just want to use the drivers.
After that, you need to download the latest ISO from the following
archive.
After downloading, mount the ISO. Then open Device Manager. Select the
appropriate device. It should appear under Other devices as a Mass storage
controller
Device Manager
Right-click on the device and select Update driver. From that menu, select
Browse my computer for drivers. Browse to the location of the ISO, and select
the directory of the drivers.
Configuration
After that, it’s a good idea to create a service for the drivers, so they are
automatically loaded during system startup.
sc.exe create VirtioFsSvc binpath="C:\ProgramData\Chocolatey\bin\virtiofs.exe" start=auto depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"
sc.exe start VirtioFsSvc
If you’ve installed manually, find the location of the .exe and change the
binpath.
Benchmarks
All Benchmarks were done on a Dell Latitude 5401 with the following specs:
Name | Value |
---|---|
CPU | Intel i5-9400H (8) @ 4.300GHz |
GPU | Intel CoffeeLake-H GT2 [UHD Graphics 630] |
Memory | 16 GB DDR4 |
Storage | 512 GB NVMe |
Linux
For the benchmark, I simply copied over a 10 GB file with cp
, measuring
it with time
. That gave me the following result:
real 0m12.532s
user 0m0.002s
sys 0m5.785s
I also transferred the same file with rsync
, to get a progress bar. That way
I could get a feel for the approximate speed of the transfer. The transfer
speed was around 250-300 MB/s consistently.
Windows
On Windows, I also copied the file in 2 ways. First using the windows File
transfer dialog. I got up speeds of about 550-700 MB/s. After that, I tried
the same using
robocopy
(A Microsoft tool for robust file copying).
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Friday, 11 March 2022 10:23:20
Source : C:\Users\foo\Downloads\
Dest = Z:\
Files : *.*
Options : *.* /DCOPY:DA /COPY:DAT /R:1000000 /W:30
------------------------------------------------------------------------------
1 C:\Users\foo\Downloads
100% New File 10.0 g 10gig.img
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 0
Files : 1 1 0 0 0 2
Bytes : 10.000 g 10.000 g 0 0 0 797.0 k
Times : 0:00:18 0:00:18 0:00:00 0:00:00
Speed : 566020993 Bytes/sec.
Speed : 32387.981 MegaBytes/min.
Ended : Friday, 11 March 2022 10:23:39
Here we end up with roughly the same speed as the windows file dialog.
Conclusion
I’m very pleased with these results. The process of setting it up is quite easy
(although not as “seamless” as the solutions Virtualbox and VMWare provide).
The performance seems fantastic, at first glance. For now, I’m very happy
with it.
I will be testing this further. If I hit any
snags or discover something else that’s interesting, I’ll let you know.
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 application (with libvirt) 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. However, when you are trying to create a shared folder using Windows Guest and Linux host, it’s 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.
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.
- 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>
- 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. It’s 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.
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.
- Install the package on Windows virtual machine. Make sure to select “Core” while installing the package. Finish the installation.
Create VirtIO-FS as a service
- Download the virtio-win-guest-tools.exe from the below path by going inside stable-virtio folder.
- Install the package on Windows virtual machine.
- 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 on how to download ISO file, mount it and manually detect the driver.
- 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
- 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.
Here is a side-by-side comparison of the same folder accessed in Linux Mint and Windows guest.
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
- https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/
- https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
- https://github.com/virtio-win/kvm-guest-drivers-windows/issues/473
In this article, we would focus on how to get a shared folder in QEMU Virtual Machine (Windows 10). We would first install Samba on our host Operating System (i.e. Ubuntu). Thereafter, we will configure network on our guest Operating System (i.e. Windows 10). Samba is released under GNU General Public License. It was first released in the year 1992.
Note: Following operations would require you to have superuser privileges. In case you don’t have one, then contact your System Administrator for assistance.
Install Samba on Ubuntu host Operating System
Since, the package samba in already available in standard Ubuntu repository. Therefore, we would first update the repository –
sudo apt update
This makes the latest version of package available. Now, to install samba package –
sudo apt install samba
Configure Network on Windows 10 guest Operating System
We have to provide following options to utilize QEMU’s built-in SMB server –
-net nic -net user,smb=shared_folder_path
So, if you are running a Virtual Machine through command-line then –
qemu-system-x86_64 -net nic -net user,smb=<shared_folder_path> -smp <number of cores> -cpu host -enable-kvm -m <memory_size> -drive format=qcow2,file=/path/to/disk_image.qcow2
For instance,
qemu-system-x86_64 -net nic -net user,smb=/dev/shm/ -smp 2 -cpu host -enable-kvm -m 2048 -drive format=qcow2,file=/path/to/disk_image.qcow2
for i386 architecture, we can replace qemu-system-x86_64 with qemu-system-i386.
Now, inside our Windows guest Virtual Machine, we need to open File explorer and then right-click on This PC. And, click Add a Network Location option.
It would get us a Add Location Wizard. Click Next.
If in case we get a Connect to Internet prompt, then we can close it from the taskbar itself. Otherwise, it will close our Add Location Wizard too.
Then, select – Choose a Custom Network Location and click Next.
In Internet or Network Address, enter the following –
\\10.0.2.4\qemu\
Thereafter, either we can provide a name for the network location or continue with default values. Click Next and Finish.
Afterwards, to access the shared folder – open File Explorer and click This PC. Under Network Location section, the shared folder is available.
In conclusion, we have discussed how to get a shared folder access in QEMU Virtual Machine (Windows 10 guest Operating System).