Unable to export VM from Hyper-V

0

TLDR;
Incorrect function (0x80070001) means the Hard Disk is stuffed. If this is you, hope you had backups!

The full story
I'm trying to move a Virtual Machine from 1 disk to another on the host.
However, when I try to export the VM it runs for about 15 minutes with the progress in the status column slowly ticking along and then eventually it pops up the following error:

An error occurred while attempting to export the virtual machine.
Failed to copy file during export.
Failed to copy file from 'D:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx' 
to 'E:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx': 
Incorrect function. (0x80070001).

Exporting via powershell gives the same error in a slightly different format.

Export-VM : Failed to copy file during export.
Failed to copy file from 'D:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx' 
to 'E:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx'
: Incorrect function. (0x80070001).
At line:1 char:1
+ Export-VM -Name SuperServer -Path 'E:\VMs\'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Export-VM], VirtualizationException
+ FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.ExportVM

No files are created, just an empty folder. There are other VMs on this disk in the same folder.
The vhdx file is over 100GB and the avhdx file is 25GB.
The source hard disk has 800GB free, and the target disk has 300GB free. Smaller I know, but its SSD.
The VM is in the "Off" State when I try to export it.
There are no errors in the event viewer when this happens.

Edit 1:
Possibly related to the problem is that the scheduled backup for all VMs is also failing. We're using the built in Windows Server Backup. The error that this is giving is:

Error in backup of D:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx during read: 
Error [0x80070001] Incorrect function.

Writer Id: {some hexadecimal string}
Component: some other hexadecimal string
Caption     : Offline\SuperServer
Logical Path: 
Error           : 8078010E
Error Message   : Copy of the files failed.

Detailed Error  : 80070001
Detailed Error Message : (null)

The backup destination is a Spanned volume of multiple disks which has a total of 4TB free. All the disks report as healthy.

Edit 2:
Trying to simply copy the files is also giving errors. I've tried Robocopy, but it fails on the 2 biggest files. I tried with and without the /J flag for unbuffered copy.

robocopy D:\VMs\SuperServer E:\VMs\SuperServer /E /ZB /DCOPY:T /COPYALL /R:1 /W:1 /V /TEE /LOG:Robocopy.log

The rest of the files copied fine but these 2 files were unsuccessful

87.5%      New File             109.3 g        SuperServer.vhdx
2020/10/28 13:22:43 ERROR 5 (0x00000005) Copying File D:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx
Access is denied.
Waiting 1 seconds... Retrying...
87.5%      New File             109.3 g        SuperServer.vhdx
2020/10/28 13:49:45 ERROR 5 (0x00000005) Copying File D:\VMs\SuperServer\Virtual Hard Disks\SuperServer.vhdx
Access is denied.
ERROR: RETRY LIMIT EXCEEDED.

7.6%      New File              23.9 g        SuperServer_Some_Hex_String.avhdx
2020/10/28 13:51:21 ERROR 5 (0x00000005) Copying File D:\VMs\SuperServer\Virtual Hard Disks\SuperServer_Some_Hex_String.avhdx
Access is denied.
Waiting 1 seconds... Retrying...
7.6%      New File              23.9 g        SuperServer_Some_Hex_String.avhdx
2020/10/28 13:51:21 ERROR 5 (0x00000005) Copying File D:\VMs\SuperServer\Virtual Hard Disks\SuperServer_Some_Hex_String.avhdx
Access is denied.

At the same time there was a number of these Warnings in the event viewer:

An error was detected on device \Device\Harddisk3\DR3 during a paging operation.

and HardDisk3 is indeed D drive.

Edit 3:
I ran a chkdsk /f and it reported no errors. I was loath to run chkdsk /R because it has to demount the drive and it takes many hours. I've got other VMs on that disk, so to lose all of them for half a day was a pain. However, once running it, it started reporting bad clusters in exactly the files that I was unable to copy. In addition, this disk was so bad that it had run out of space to move the bad sectors.

The disk does not have enough space to replace bad clusters detected in file 88 of name \VMs\SUPERSERVER\VIRTUA~1\SUPERSERVER.vhdx. 

And in case you are wondering, yes there was plenty of free space on the drive, but bad sectors need a different kind of free space.

To make matters worse, after the chkdsk had finished, another of the VMs on the same drive was no longer able to be booted and had to be recovered from a backup.

hyper-v
windows-server-2016
asked on Server Fault Oct 27, 2020 by JumpingJezza • edited Oct 30, 2020 by JumpingJezza

3 Answers

1

The backup and the export have one thing in common: the source. There is probably something wrong with your VHD or other Hyper-V files.

This guy solved it by copying the data inside the VM using Robocopy, but that may not work for you: https://evotec.xyz/hyper-v-incorrect-function-when-trying-to-move-files/


Your updated post shows that your drive is failing. If chkdsk /r can't fix it, you'll need to use a different recovery method. Data loss is a near certainty here. You need to decide if saving this machine is worth it, or if you want to rebuild. No matter what, you need to stop using this disk, even if chkdsk /r can fix it.

answered on Server Fault Oct 28, 2020 by longneck • edited Oct 29, 2020 by longneck
0

Try exporting the VM to a folder on the source disk. If this works then the problem is with the destination.

Also, if this works then try to copy the exported VM to the destination and import it from there and see if you get the same errors.

answered on Server Fault Oct 28, 2020 by joeqwerty
0

A week after having to recover the VM from backups, the physical hard disk was recovered!

This was done by removing it from the server and then it was reattached and reimported and started working again. So worth a try if all else fails.

answered on Server Fault Dec 1, 2020 by JumpingJezza

User contributions licensed under CC BY-SA 3.0