Mounting VHD Error Message “Sorry, there was a problem mounting the file”


Windows as well as Windows Server has this small but great feature to mount ISO and VHD images locally. This makes certain scenarios much easier, like the VM Offline Patching explained in another article. In some situations, the operating system might not mount the image and return an error message instead:

 Sorry, there was a problem mounting the file

Gentle as always… But was does it mean? Usually this file isn’t damaged, and working fine which means there is something else. First thing to check is the file attributes.

Analyze the data

For the file that has the problem on the file server node, check the file for the presence sparse attribute using the following command. The command just checks for sparse attributes:

fsutil sparse queryflag

Assuming it is like the outcome below, this points that the issue probably lies with the fact that the sparse file attribute (FILE_ATTRIBUTE_SPARSE) is set .

PS D:\MSSCVMMLibrary\VHDs> fsutil sparse queryflag .\SQL2012_disk_1.vhdx
This file is set as sparse

The behavior we are seeing is consistent with the expectation, as the VHD stack will not mount a file marked sparse. The issue however remains on how the files ended up as sparse. Either the file was sparse to begin with or the sparse flag was enabled on the file by some application.

How to fix the problem

To unblock this file, you would have to make a copy of the files showing this behavior to clear the sparse flag and start using the copy. Alternatively it’s also possible to use fsutil to change the sparse flag:

fsutil sparse setflag 0

However, if you attempt to clear the FILE_ATTRIBUTE_SPARSE_FILE attribute, the operation is valid only if there is no sparse region in the file. Therefore copy is safer since we don’t know for sure if the original file was actually sparse on disk to begin with. The copied file will have the entire file data without the sparseness. Since it is a copy, the copy process strips the sparse flag which is why it can be mounted.

After copying the file, check again the file attribute. The output should have changed and looks similar to this:

PS D:\MSSCVMMLibrary\VHDs> fsutil sparse queryflag .\SQL2012_disk_1.vhdx
This file is NOT set as sparse

This still leaves the question, why was the sparse flag explicitly applied to this file? In Windows NTFS file systems, files are not made sparse by default. The application or user needs to explicitly mark the file sparse. This means, it could have happened if for example one of the following happened…

  • Internet Explorer was downloading the file;
  • Buggy application, failed restore;
  • The file was a target of DFS-R and the source file was deduplicated. In this case the target file of the replica will have the sparse attribute set;

In case data deduplication is enabled

In case the volume where the image is stored on has been configured for data deduplication, there might be some additional steps to consider.

First of all to check if a file has been deduplicated using “fsutil reparsepoint query”. Deduplicated files have a reparse tag value of 0x80000013. When following the process above, i.e. if you copied the file to rehydrate it and clear the sparse attribute, then the next deduplication job will process the copy and deduplicate it. Per default, this would be picked up depending on the “MinimumFileAgeDays” setting when Dedup was configured on the volume. Optionally this process can sped up by setting the “MinimumFileAgeDays” to “0” using the following cmdlet (don’t forget to set it back after the job has been completed):

Set-DedupVolume -MinimumFileAgeDays "0" -Volume "D:"

Thanks to Microsoft colleague Sriprasad Bhat Kasargod (Microsoft PM) who helped me analyzing and fixing this problem.

More Information

Troubleshooting , Windows Server , Windows Server 2012 , Windows Server 2012 R2

, ,

About the Author

Michel Luescher is a solution architect in the worldwide Datacenter & Cloud Infrastructure Center of Excellence (CoE) at Microsoft Corporation based out of Zurich, Switzerland. Primarily, Michel is focused on hybrid cloud solutions (Hyper-V, System Center and Microsoft Azure). In addition Michel is speaker, blogger and author of several books.

Leave a Reply.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Virtual Machine Template Patching