quervernetzt
quervernetzt

Reputation: 11621

Hyper-V: Create shared folder between host and guest with internal network

Set up:

Aim:

How can I achieve this?

Upvotes: 135

Views: 374201

Answers (5)

Spangen
Spangen

Reputation: 4720

In addition to the excellent answers above that gives me access to resources on my host drive (Windows 11 host, Win 2022 VM) as "Redirected drives and folders" I wanted to use the drive from the command line in the VM (powershell) and got

PS C:\Users\Administrator> e:
Set-Location : Cannot find drive. A drive with the name 'E' does not exist.
At line:1 char:1
+ Set-Location $MyInvocation.MyCommand.Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (E:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

The solution for me was to run net use to display the resources being accessed by the VM and then map the drive:

Show the resources:

PS C:\Users\Administrator> net use
New connections will be remembered.


Status       Local     Remote                    Network

-------------------------------------------------------------------------------
                       \\TSCLIENT\E              Microsoft Terminal Services
The command completed successfully.

Map the drive:

PS C:\Users\Administrator> net use e: \\TSCLIENT\E
The command completed successfully.

Drive now available on commandline and in explorer.

PS C:\Users\Administrator> e:
PS E:\> ls


    Directory: E:\


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        16/09/2024     10:52                jenkins

Windows explorer showing mapped drives

Naturally this will suffer the same limitations as other mapped drives that are not available in background services etc, but it suited my purpose.

Upvotes: 1

Dave Lydick
Dave Lydick

Reputation: 117

For those who are having trouble getting the "Edit Session Settings..." dialog, I found that I could get to the dialog box by having the guest machine running in windowed mode so that the top menu ("File Action Media Clipboard View Help") was visible, then selecting "File > Exit" (or clicking on the "X" at the top right of the guest machine window).

After that, the dialog would launch from the Hyper-V Manager Actions "Edit Session Settings..." link.

Upvotes: 10

laggingreflex
laggingreflex

Reputation: 34627

Share Files, Folders or Drives Between Host and Hyper-V Virtual Machine

Prerequisites

  1. Make sure you have a Pro or Enterprise version of the Windows OS. The Home version does not provide you with this functionality! From the official documentation:

The virtual machine must have Remote Desktop Services enabled, and run Windows 10, Windows 8.1, Windows Server 2016, or Windows Server 2012 R2 as the guest operating system.

  1. Ensure that Enhanced session mode settings are enabled on the Hyper-V host.

    Start Hyper-V Manager, and in the Actions section, select "Hyper-V Settings".

    hyper-v-settings

    Make sure that enhanced session mode is allowed in the Server section. Then, make sure that the enhanced session mode is available in the User section.

    use-enhanced-session-mode

  2. Enable Hyper-V Guest Services for your virtual machine

    Right-click on Virtual Machine > Settings. Select the Integration Services in the left-lower corner of the menu. Check Guest Service and click OK.

    enable-guest-services

Steps to share devices with Hyper-v virtual machine:

  1. Start a virtual machine and click Show Options in the pop-up windows.

    connect-to-vm

    Or click "Edit Session Settings..." in the Actions panel on the right

    edit-session-sessions

    It may only appear when you're (able to get) connected to it. If it doesn't appear try Starting and then Connecting to the VM while paying close attention to the panel in the Hyper-V Manager.

  2. View local resources. Then, select the "More..." menu.

    click-more

  3. From there, you can choose which devices to share. Removable drives are especially useful for file sharing.

    choose-the-devices-that-you-want-to-use

  4. Choose to "Save my settings for future connections to this virtual machine".

    save-my-settings-for-future-connections-to-this-vm

  5. Click Connect. Drive sharing is now complete, and you will see the shared drive in this PC > Network Locations section of Windows Explorer after using the enhanced session mode to sigh to the VM. You should now be able to copy files from a physical machine and paste them into a virtual machine, and vice versa.

    shared-drives-from-local-pc

Source (and for more info): Share Files, Folders or Drives Between Host and Hyper-V Virtual Machine

Drawbacks

  • While this solution is easy and probably works faster then when using internal network, it has its own drawback: the drive is mapped only while there is a connection via the VMConnect client. If you run a vm with some background services or you connect to it via RDP, this approach isn't gonna work. (thanks @sich for pointing this out)

Upvotes: 203

Kris_Jiaqi_Xie
Kris_Jiaqi_Xie

Reputation: 7

My version is Hyper-V Version: 10.0.22509.1000,I think the best and most convenient way in windows is that configuring the host and the vm in the same subnet,So you can just use the ctrl+c and ctrl+v Seamlessly between host and vm.

Upvotes: -4

quervernetzt
quervernetzt

Reputation: 11621

  • Open Hyper-V Manager
  • Create a new internal virtual switch (e.g. "Internal Network Connection")
  • Go to your Virtual Machine and create a new Network Adapter -> choose "Internal Network Connection" as virtual switch
  • Start the VM
  • Assign both your host as well as guest an IP address as well as a Subnet mask (IP4, e.g. 192.168.1.1 (host) / 192.168.1.2 (guest) and 255.255.255.0)
  • Open cmd both on host and guest and check via "ping" if host and guest can reach each other (if this does not work disable/enable the network adapter via the network settings in the control panel, restart...)
  • If successfull create a folder in the VM (e.g. "VMShare"), right-click on it -> Properties -> Sharing -> Advanced Sharing -> checkmark "Share this folder" -> Permissions -> Allow "Full Control" -> Apply
  • Now you should be able to reach the folder via the host -> to do so: open Windows Explorer -> enter the path to the guest (\192.168.1.xx...) in the address line -> enter the credentials of the guest (Choose "Other User" - it can be necessary to change the domain therefore enter ".\"[username] and [password])

There is also an easy way for copying via the clipboard:

  • If you start your VM and go to "View" you can enable "Enhanced Session". If you do it is not possible to drag and drop but to copy and paste.

Enhanced Session

Upvotes: 72

Related Questions