How to Use PowerShell to Fix Corruption on ReFS Volumes

ReFS volumes can become corrupt due to any number of underlying storage problems.

Brien Posey

March 26, 2021

5 Min Read
How to Use PowerShell to Fix Corruption on ReFS Volumes

The ReFS file system got its name by being the “resilient file system.” It uses a feature called integrity streams to keep the file system healthy. Even so, ReFS volumes can become corrupt due to any number of underlying storage problems.

Microsoft makes it possible for administrators to fix the problem. That’s the good news. The bad news is that if you create an ReFS volume using default options, repairing corrupt files and folders may not be an option. You may have little choice but to restore the volume from backup. There are two things you need to do to be able to recover from corruption on an ReFS volume.

The first thing that you will have to do is to enable integrity streams for file data. Integrity streams work by creating checksums for volume data and metadata. The ReFS file system can determine whether a particular object is corrupt by comparing an object to its checksum.

It is worth noting that ReFS integrity streams are enabled by default for file system metadata. If however, you want to use integrity streams at the file level or at the volume level, you will have to enable the integrity streams manually. Microsoft presumably leaves file and volume level integrity streams disabled because of their impact on storage performance.

To check and see if integrity streams are enabled for a particular resource, use the Get-FileIntegrity cmdlet. In doing so, you will need to provide the -Filename switch, followed by the path and filename of the file that you wish to examine. If, for example, you wanted to look at a file named E:DFS 1.jpg, then you would use this command:

Get-FileIntegrity -FileName ‘E:DFS 1.jpg’

As you can see in Figure 1, the results indicate that file integrity is not enabled for this particular file.

 ReFS Corruption 1.jpg

ReFS Corruption 1

Figure 1

Integrity streams are not currently enabled for this file.

If we wanted to enable integrity streams for this particular file, we could do so by using the Set-FileIntegrity cmdlet. The command is as follows:

Set-FileIntegrity -FileName ‘E:DFS 1.jpg’ -Enable $True

As you can see in Figure 2, integrity streams are now enabled for the file. For this demonstration, I have enabled integrity streams for a single file, but you can enable integrity streams at the folder level, or even for an entire volume.

 ReFS Corruption 2.jpg

ReFS Corruption 2

Figure 2

Integrity streams are now enabled.

The second thing that you will need to do to be able to recover from corruption on an ReFS volume is to enable storage redundancy. More specifically, the data will need to reside on a resilient mirror or on a volume with parity enabled through Storage Spaces Direct.

Repairing Corruption

If you have enabled integrity streams for the files on a volume and you the volume physically resides on redundant storage within Storage Spaces Direct, then there is a good chance that the repair will happen automatically. The ReFS file system uses a mechanism called an integrity scrubber to automatically track down and repair corruption. However, you can also manually repair corruption by using the Repair-FileIntegrity cmdlet.

To use this cmdlet, simply append the -Filename parameter followed by the path and filename of the file that you want to repair. If for example, if I wanted to repair the E:DFS 1.jpg file, the command would look like this:

Repair-FileIntegrity -FileName ‘E:DFS 1.jpg’

When you use this command, the ReFS file system will compare the file to its checksum to determine if corruption exists. If corruption is found, a copy of the data is retrieved from the redundant storage and the file is repaired. When that happens, PowerShell will not produce any visible output. If, however, the volume is hosted on non-redundant storage, you will see an error message like the one shown in Figure 3 and the data will not be repaired.

 ReFS Corruption 3.jpg

ReFS Corruption 3

Figure 3

The file cannot be repaired because no storage redundancy exists.

The big takeaway here is that if you are using the ReFS file system then you really need to be using integrity streams and storage redundancy if you are to get the most out of it. The one caveat to this is that you may not be able to use integrity streams if doing so negatively impacts the storage performance in a noticeable way.

If you do happen to experience corruption on an ReFS volume, but are not using integrity streams or are not using redundant storage, there is one thing that you can try doing to repair the volume. Before you do what I am about to show you, however, it’s important to make a backup because this technique has the potential to cause further damage. With that said, you can try using this command:

Repair-Volume -DriveLetter E -OfflineScanAndFix

This command will take the volume offline and attempt to correct any errors that may exist. It will bring the volume back online when the process completes. You can see what happens when I run the command against a healthy volume in Figure 4. Incidentally, this technique can also be used on NTFS volumes.

ReFS Corruption 4.jpg

ReFS Corruption 4

Figure 4

This command attempts to perform an offline volume repair.

 

About the Author

Brien Posey

Brien Posey is a bestselling technology author, a speaker, and a 20X Microsoft MVP. In addition to his ongoing work in IT, Posey has spent the last several years training as a commercial astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space.

https://brienposey.com/

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like