Share Files Between Host and Linux Virtual Machine over Hyper-V

Last updated on June 16, 2023 pm

Share Files Between Host and Linux Virtual Machine over Hyper-V

Generally speaking, just follow this post and things will be all set.

Shared Folders over Hyper-V Ubuntu Guest

Also, attach a USB drive to the VM is a feasible way, but on Windows 10, it is not support to make a removable device offline, so it is not applicable for SD / TF card. Unreasonable…

Some Notices

1.

On Advanced sharing settings on host Windows machine, make sure all entries under All Networks item are selected as turned on. Otherwise, there might be a permission deny on mounting.

2.

For accessing host directory as root user, no -o flag needed when running mount.cifs command. Also, password for host root can be put as pressing Enter.

3.

Read and write to the shared directory will need root permission at this case.

4.

Simply running umount (unmount) the directory like unmount other device can disable the sharing.

Next Time

Every time start the linux vm, simply run mount.cifs again can enable the directory sharing.

Or it can be automated by a bash script as follow:

1
2
3
4
5
6
7
#!/bin/bash

MOUNTED=$(df -h /path/to/vm/shared/dir/ | grep dev)

if ! [ -z "$MOUNTED" ] ; then
sudo mount.cifs //WIN-DESKTOP/shared_folder_name /path/to/vm/shared/dir/
fi

If the CIFS is not mounted, the path is mounted from device tree /dev by default. But after mounting, it will be changed to the host shared folder name, this can be verified by df -h.

References

  1. Shared Folders over Hyper-V Ubuntu Guest
  2. Share Files, Folders or Drives Between Host and Hyper-V Virtual Machine
  3. All About CIFS
  4. Attach USB device to Hyper-V guest machine - Microsoft Q&A
  5. File Permissions and Sharing Files | Computing

Share Files Between Host and Linux Virtual Machine over Hyper-V
https://lingkang.dev/2023/06/16/share-file-host-and-vm-hyper-v/
Author
Lingkang
Posted on
June 16, 2023
Licensed under