how do i copy a file from host to hyperv vm


  1. Posts : 2
    windows 10
       #1

    how do i copy a file from host to hyperv vm


    Where am I going wrong. I am on windows10 pro; have enabled guest services and tried this command top copy to the hyperv vm:

    Copy-VMFile "raspi" -SourcePath "D:\temp.txt" -DestinationPath "/home/pi" -CreateFullPath -FileSource host

    Copy-VMFile : Failed to initiate copying files to the guest.
    Failed to copy the source file 'D:\temp.txt' to the destination '/home/pi' in the guest.
    'raspi' failed to initiate copying files to the guest: Unspecified error (0x80004005). (Virtual machine ID 3C028648-F65B-4565-ADCA-40F1290FB0BE)
    'raspi' failed to copy the source file 'D:\temp.txt' to the destination '/home/pi' in the guest: Unspecified error (0x80004005). (Virtual machine ID 3C028648-F65B-4565-ADCA-40F1290FB0BE)
    At line:1 char:1
    + Copy-VMFile "raspi" -SourcePath "D:\temp.txt" -DestinationPath "/home ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Copy-VMFile], VirtualizationException
    + FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.CopyVMFile
    ####################################################
      My Computer


  2. Posts : 31,666
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #2

    rainbow3 said:
    Where am I going wrong. I am on windows10 pro; have enabled guest services and tried this command top copy to the hyperv vm:

    Copy-VMFile "raspi" -SourcePath "D:\temp.txt" -DestinationPath "/home/pi" -CreateFullPath -FileSource host

    Welcome to Ten Forums.


    You haven't said what the guest OS is, but from your destination path it would appear to be some form of Linux. Depending on which one it may, or may not, have the required Linux Integration Services. This may help, if not for Copy-VMFile itself, then it suggests alternative ways to transfer a file. Method 4, a transfer vhdx, should work whatever the guest OS is.

    The PowerShell method that I’m going to show you makes use of the Linux Integration Services (LIS). It doesn’t work on all distributions/versions. Check for your distribution on TechNet. Specifically, look for “File copy from host to guest”.....

    ....

    Verifying the Linux Guest’s File Copy Service

    You can quickly check that the service in the guest is prepared to accept a file from the host:

    ps -u root | grep hyper Look in the output for hypervfcopyd
    altaro.com | 4 Ways to Transfer Files to a Linux Hyper-V Guest

    My guest VMs are all various versions of MS Windows, Copy-VMFile works for them.
      My Computers


  3. Posts : 1,325
    Windows 11 Pro 64-bit
       #3

    Other than the service being available...
    It might be just that: CreateFullPath too long. "/home/..."
    CreateFullPath can only create one folder. If you ask it to create a directory tree (ex: -CreateFullPath ‘/downloads/new’ ), you’ll get an error that includes the text “failed to initiate copying files to the guest: Unspecified error (0x80004005)“.
    Just seen in same article @Bree mentioned.
      My Computers


  4. Posts : 2
    windows 10
    Thread Starter
       #4

    It is raspberry pi desktop which is debian linux
    "ps -u root | grep hyper" finds nothing so I guess copyvm wont work...(I do have guest services installed but perhaps they don' support that command)
    The folder already exists. I tried without CreateFullPath and still did not work.

    It seems like it should be common to copy a file into the VM yet I have not been able to do it. I have also tried:

    * mount from windows - "not initialized or does not have drive letters"
    * create a virtual switch - it says set the ip address of the vm but how do I do that?
    * copy/paste using extended services - does nothing

    I could replace hyperv with virtualbox but I use docker which requires hyperv.
      My Computer


  5. Posts : 31,666
    10 Home x64 (22H2) (10 Pro on 2nd pc)
       #5

    rainbow3 said:
    It seems like it should be common to copy a file into the VM yet I have not been able to do it. I have also tried:

    * mount from windows - "not initialized or does not have drive letters"
    * create a virtual switch - it says set the ip address of the vm but how do I do that?
    * copy/paste using extended services - does nothing....

    Extended Mode requires the guest to be a Pro version of Windows, W8 or W10.

    The simplest way would be to create a new .vhd or .vhdx drive using Hyper-V Manager. Mount it in the Host, it will be a blank new drive so you will have to format it (perhaps Fat32 for compatibility?). You can do that in Disk Management. Then copy the files to it. Now use Disk Management to dismount it. You can then attach it as a second drive for your guest VM.
      My Computers


  6. Posts : 1,325
    Windows 11 Pro 64-bit
       #6

    I see this is marked as solved...

    In any case there is enhanced mode for Linux guests as well since the Ubuntu template from 'quick create' has it.
    I've tested and was able to enable enhanced mode under a Fedora 33 VM using this:
    GitHub - secana/EnhancedSessionMode: Contains scripts to enable "Hyper-V Enhanced Session Mode" for Linux

    EDIT: it might not work in Debian with those scripts.
    But since it works in Ubuntu which is Debian-based there may still be hope.
    I believe there are Hyper-V packages you can install via apt (though some distros include the open source module in the kernel already) then enable all services and test again.

    - - - Updated - - -

    One last thing:
    I use Ubuntu 18.04 LTS VM from the provided 'quick create' template. Enhanced mode is enabled.
    Code:
    ps -u root | grep hyper
    Returns nothing. Empty.

    Then I tried copying a file with Ctrl+C on host - Ctrl+V in VM...
    It works!
    ...catastrophic...

    EDIT: it seems to create the files of the right size but they're unreadable. So without the right services this goes nowhere.

    I'll go to PS command or try the VHDX way as long I don't figure out how this copy / paste works.

    - - - Updated - - -
    UPDATE
    In my case, I've fixed it!

    Here's how:
    Ubuntu on Hyper-V . GitHub

    I've installed all services as instructed; it wasn't working until I got it for the right version of kernel + reboot.

    Service has to run in VM:
    how do i copy a file from host to hyperv vm-image.png

    systemctl status hv-fcopy-daemon.service
    Note: on older systems you may need to use ps -u root | grep hyper
    That's why was always empty... (newer system here)
    source:
    server - Confirm Hyper-V Integration Services are Running - Ask Ubuntu

    Note:
    Via "Copy-VMFile" works fine. Advantage for big files -> the progress bar.
    Copy with Ctrl+C - Ctrl+V works also but be patient with large files, there is no indication where the copy operation is ready, at least none I could see in Nautilus file manager.

    Cheers!
      My Computers


  7. Posts : 1,325
    Windows 11 Pro 64-bit
       #7

    Now that I got it working on multiple Linux guests on the Hyper-V host, here's a small checkup to pin this down.
    Install all needed packages and enable Enhanced Session.

    On the host:
    (guest must be turned off for this one)
    Code:
    Set-VM -VMName "Linux VM Name" -EnhancedSessionTransportType HvSocket
    And enable the Guest services in the VM Settings GUI or via command:
    Code:
    Enable-VMIntegrationService -VMName "Linux VM Name" -Name "Guest Service Interface"
    Then on the guest:
    install xrdp and hyperv tools: linux-image-virtual, linux-tools-virtual, linux-cloud-tools-virtual packages on current kernel...
    (package names may differ per distro)
    ***
    The Ubuntu template from Hyper-V has everything already installed.
    Install the needed packages if you installed Ubuntu manually.
    Fedora uses an installation script I previously linked. This facilitates the manual installation.
    Important: In any distro, if you update the kernel, you'll need to check/reinstall the hyperv tools again.
    ***

    How to check the Hyper-V copy service is running in guest.

    On Ubuntu:
    Code:
    systemctl status hv-fcopy-daemon.service
    how do i copy a file from host to hyperv vm-ubuntu.png

    On Fedora:
    Code:
    systemctl status hypervfcopyd
    how do i copy a file from host to hyperv vm-fedora.png

    If copy via "Copy-VMFile" PowerShell command on the host works, then you also have Ctrl+C (host) Ctrl+V (guest) functionality.
    I've confirmed this in both Ubuntu and Fedora VMs.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 18:00.
Find Us




Windows 10 Forums