How to Run ChkDsk and Defrag on Cluster Shared Volumes in Windows Server 2012 R2

How to Run ChkDsk and Defrag on Cluster Shared Volumes in Windows Server 2012 R2

Rate This
  • Comments 23

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. I will then discuss how ChkDsk is run on your CSVs.

Procedure to run Defrag on your 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)

 

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”:

 

How is ChkDsk run on your 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 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 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. 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. The use of the Repair-ClusterSharedVolume cmdlet, however 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
Program Manager
Clustering and High Availability
Microsoft

Leave a Comment
  • Please add 6 and 7 and type the answer here:
  • Post
  • Thank you Subhasish !

    FYI we have an Other case open with NetApp: A 700 Go  quick format take about 5 minutes : very strange...

  • Hello Subhasish Bhattacharya

    As you already stated, defrag has a bug for analyse process when disk is thin provisioned so we have to switch disk to redirected mode.

    In my case it is worse that I am not possible to do defrag /a or Optimize-Volume -analyse in any mode except "Maintenance Mode" what is unacceptable for Hyper-V CSV disks.

    When I run defrag /a in redirected mode I received "Slab Analysis:  0% complete..." and then "Incorrect function. (0x80070001)"

    Powershell equivalent shows "The specified extrinsic Method does not exist."

    Disk is thin provisioned.

    When I tried Defrag GUI, analyse process doesn't work same way as optimize when in redirected mode.

    Difference is for defrag.exe and powershell command where defrag itself works in redirected mode!

    Problem is for SCOM or regular analyse checks which can never pass sucessfully on disks also in redirected mode.

    Is this a known bug?

    Thanks for your answer

    BR

    Filip

  • Hi Filip,

    Which OS version are you running? Are you up-to date on your hotfixes? Which storage array do you have?

    To make sure I understand correctly...

    - When you use defrag.exe or PowerShell you are able to run analyze in redirected mode

    - When you use SCOM you have to use maintenance mode? What do you mean by "regular" analyze checks?

    Thanks!

    Subhasish

  • Hi Subhasish and sorry for my late answer.

    OS is 2012 R2 with latest updates.

    Storage array is EMC Symmetrix VMAX, thin provisioned.

    When I am trying to use defrag via defrag.exe or Optimize-Volume and disk is in redirected mode, if I try to -ANALYZE only, it will fail. Slab Analysis (which is run as part of -analyze process) will return "The specified extrinsic Method does not exist" so command is cancelled.

    If I tried to use -Defrag param instead of -Analyze, where slab analysis is not used I suppose (-Verbose doesn't mention SLAB Analysis is run in this case), command completes successfully.

    In short, defrag analysis (Optimize-Volume -Analyze) is not possible in normal or redirected mode. Only maintenance mode allows to pass defrag analysis successfully. But if I use defragging without analyzing disk (Optimize-Volume -Defrag), it completed successfully, perhaps because there is no "Slab Analysis" used which seems to be root cause.

    If Defrag GUI is used, it is not possible to Analyze and also Defrag disks in Redirected mode. It seems it is because GUI forces -analyze all the time before "-defrag only" is applied so GUI is useless here.

    About SCOM: I mentioned it because it checks disks for fragmentation so (Optimize-Volume -Analyze equivalent) is used to detect if disk is fragmented. This can't complete successfully because of the bug mentioned above, also in case disk is in "redirected mode".

    Thanks for any feedback

    Filip

  • Hi Filip,

    Thanks for the information!

    I believe we have identified the cause of this issue and will be rolling out a fix for WS2012 R2 (and possibly WS2012). I don't have an estimate for when the QFE will be available but I expect within the next 3 months.

    Best,

    Subhasish

  • The NetApp array has options that allow it to be Thinly provisioned, but report differently. To check this use the command 'lun show -vserver vsa1 -volume vol2 -lun lunname -fields space-allocation. It will tell you if space allocation reporting is on. use the LUN modify option to change the setting. With this disabled, the LUN will not report back as thin to the OS, and defrag may do the wrong things.

    Another option that works more broadly is to use the NetApp Powershell Toolkit (free download) and works on CSVs or regular volumes, Win2008r2-2012r2, and can be used to execute a the same trim type operations. Command is 'invoke-nahostspacereclaim C:\ClusterStorage\Volume1' or whatever volume you want thined out.

    For more specific help, are you running 7-Mode or C-Mode, and what version of the Array code (8.1, 8.2, etc)

  • Hi,

    any update on QFE ?

    I have the same 'defrag /a in redirected mode received "Slab Analysis:  0% complete..." and then "Incorrect function. (0x80070001)"'

    and would appreciate a solution :)

  • @AndrzejP, Thanks for your note. A QFE for this issue is currently slated for an October 2014 release...

Page 2 of 2 (23 items) 12