QEMU Windows host Linux guest shared folder
This article explains how to set up a shared folder between a Windows host and a Debian guest in QEMU.
Check this if you don't know how to run a Linux on the Windows with QEMU yet.
1. Configure Folder Sharing
Follow this link to set up the folder sharing. If it's set up correctly, you'll see the Network Path in Properties -> Sharing
.
2. Mount the Shared Folder
To mount the shared folder, you need to provide the following information:
- Windows username and password
Linux user uid and gid
- Run
id -[u|g] username
on Linux guest to check ids.
- Run
Shared folder path on Windows
- The path must be in Linux format. For example, if the network path is
\\[ComputerName]\Users\abc\qemu\shared
, in Linux it should be written as//10.0.2.2/Users/abc/qemu/shared
where10.0.2.2
represents the IP address that QEMU uses to connect to the Windows host.
- The path must be in Linux format. For example, if the network path is
- Mount location on Linux
For example, assuming:
- Windows username:
abc
- Shared folder path:
//10.0.2.2/Users/abc/qemu/shared
- Uid and gid:
1000
- Mount location:
/mnt/shared
Then the mounting commands would be:
$ mkdir -p /mnt/shared
# You will be prompted for the Windows user's password.
$ apt install cifs-utils
$ mount.cifs -o user=abc,uid=1000,gid=1000 //10.0.2.2/Users/abc/qemu/shared /mnt/shared
Password for abc@//10.0.2.2/Users/abc/qemu/shared:
3. Automatic Mount at Boot
The mount will no longer persist after restarting. Add an entry to /etc/fstab
to enable automatic mounting at boot.
Fill in the path, username, and password in the script below, then execute it:
# Fill in the information
SHARE_PATH="//10.0.2.2/Users/abc/qemu/shared"
MOUNT_POINT="/mnt/shared"
USERNAME="abc"
PASSWORD="xyz"
USER_UID="1000"
USER_GID="1000"
# Add entry to /etc/fstab
echo "$SHARE_PATH $MOUNT_POINT cifs username=$USERNAME,password=$PASSWORD,uid=$USER_UID,gid=$USER_GID 0 0" | tee -a /etc/fstab
# Reload systemd
systemctl daemon-reload
Then restart and check that the shared folder is mounted.
4. Demo
References
https://gist.github.com/neelabhg/8c6bfcdb44c0aa3f86bed00fe1f6da49