How to Run ChkDsk and Defrag on Cluster Shared Volumes in Windows Server 2012 R2
Published Mar 15 2019 02:41 PM 32.9K Views
Microsoft
First published on MSDN on Jan 01, 2014
Cluster Shared Volumes (CSV) is a layer of abstraction on either the ReFS or NTFS file system (which is used to format the underlying private cloud storage). Just as with a non-CSV volume, at times it may be necessary to run ChkDsk and Defrag on the file system. In this blog, I am going to first address the recommended procedure to run Defrag on your CSV, in Windows Server 2012 R2 and later. I will then discuss how ChkDsk is run on your CSVs.

Running Defrag on a CSV:


Fragmentation of files on a CSV can impact the perceived file system performance by increasing the seek time to retrieve file system metadata. It is therefore recommended to periodically run Defrag on your CSV volume. Fragmentation is primarily a concern when running dynamic VHDs and less prevalent with static VHDs. On a stand-alone server defrag runs as part of the “Maintenance Task”, so it runs automatically. However, on a CSV volume it will never run automatically, so you need to run it manually or script it to run (potentially using a Clustered Scheduled Task ). It is recommended to conduct this process during non-peak production times, as performance may be impacted.  The following are the steps to defragment your CSV:

1.       Determine if defragmentation is required for your CSV by running the following on an elevated command prompt:
Defrag.exe <CSV Mount Point> /A /U /V
/A           Perform analysis on the specified volumes
/U           Print the progress of the operation on the screen
/V           Print verbose output containing the fragmentation statistics



Note: If your CSV is backed by thinly provisioned storage, slab consolidation analysis (not the actual slab consolidation) is run during defrag analysis. Slab consolidation analysis requires the CSV to be placed in redirected mode before execution. Please refer to step 2, for instructions on how to place your CSV into redirected mode.



2.       If defragmentation is required for your CSV, put the CSV into redirected mode.  This can be achieve in either of the following ways:

a.       Using Windows PowerShell© open a new elevated Windows PowerShell console and run the following:



Suspend-ClusterResource <Cluster Disk Name> -RedirectedAccess


b.      Using the Failover Cluster Manager right-click on the CSV and select “Turn On Redirected Access”:



Note: If you attempt to run Defrag on a CSV without first putting it in redirected mode, it will fail with the following error:

CSVFS failed operation as volume is not in redirected mode. (0x8007174F)



You may also run into the following error: This operation is not supported on this filesystem. (0x89000020)


3.       Run defrag on your CSV by running the following on an elevated command prompt:
Defrag.exe <CSV Mount Point>


4.       Once defrag has completed, revert the CSV back into direct mode by using either of the follow methods:

a.       Using Windows PowerShell© open a new elevated Windows PowerShell console and run the following:



Resume-ClusterResource <Cluster Disk Name>


b.      Using the Failover Cluster Manager right-click on the CSV and select “Turn Off Redirected Access”:







Running ChkDsk on a CSV:


During the lifecycle of your file system corruptions may occur which require resolution through ChkDsk. As you are aware, CSVs in Windows Server 2012 R2 also supports the ReFS file system. However, the ReFS filesystem achieves self-healing through integrity checks on metadata. As a consequence, ChkDsk does not need to be run for CSV volumes with the ReFS file system. Thus, this discussion is scoped to corruptions in CSV with the NTFS file system. Also, note the redesigned ChkDsk operation introduced with Windows Server 2012, which separates the ChkDsk scan for errors (online operation) and the ChkDsk fix (offline operation). This results in higher availability for your Private Cloud storage since you only need to take your storage offline to fix corruptions in your storage (which is a significantly faster process than the scan for corruptions). In Windows Server 2012, we integrated ChkDsk /SpotFix into the cluster IsAlive health check for the Physical Disk Resource corresponding to the CSV. As a consequence we will now attempt to fix corruptions in your CSV without any perceptible downtime for your application.

Detection of Corruptions – ChkDsk /Scan:


The following is the workflow on Windows Server 2012 R2 or later systems to scan for NTFS corruptions:



Note: If the system is never idle it is possible that the ChkDsk scan will never be run. In this case the administrator will need to invoke this operation manually. To invoke this operation manually, on an elevated command prompt run the following:
chkdsk.exe <CSV mount point name> /scan



Resolution of CSV corruptions during Physical Disk Resource IsAlive Checks:


The following is the CSV workflow in Windows Server 2012 R2 or later to fix corruptions:



Note: In the rare event that a single CSV corruption takes greater than 15 seconds to fix, the above workflow will not resolve the error.  In this case the administrator will need to manually fix this error.  A CSV does not need to be place in maintenance or redirected mode before invoking chkdsk. The CSV will re-establish its state automatically once the chkdsk run has completed. To invoke this operation manually, on an elevated command prompt run the following:
chkdsk.exe <CSV mount point name> /SpotFix

Running Defrag or ChkDsk through Repair-ClusterSharedVolume cmdlet:


Running Defrag or ChkDsk on your CSV, through the Repair-ClusterSharedVolume, is deprecated with Windows Server 2012 R2 and the cmdlet has been removed completely in Windows Server 2016. It is instead highly encouraged to directly use either Defrag.exe or ChkDsk.exe for your CSV, using the procedure indicated in the preceding sections. While not recommended the use of the Repair-ClusterSharedVolume cmdlet is still supported by Microsoft. To use this cmdlet to run chkdsk or defrag, run the following on a new elevated Windows PowerShell console:
Repair-ClusterSharedVolume <Cluster Disk Name> -ChkDsk –Parameters <ChkDsk parameters>

Repair-ClusterSharedVolume <Cluster Disk Name> –Defrag –Parameters <Defrag parameters>


You can determine the Cluster Disk Name corresponding to your CSV using the Get-ClusterSharedVolume cmdlet by running the following:
Get-ClusterSharedVolume | fl *


Thanks!

Subhasish Bhattacharya
Senior Program Manager
Clustering and High Availability
Microsoft
2 Comments
Version history
Last update:
‎Mar 15 2019 02:41 PM
Updated by: