Q. How do I manually and cleanly perform a disk defragmentation or use Chkdsk on a Cluster Shared Volume (CSV)?

John Savill

March 17, 2009

5 Min Read
ITPro Today logo in a gray background | ITPro Today

A. CSVs introduce challenges because they access multiple nodes in a cluster directly through the use of direct access (direct IO), which allows all the nodes to read and write from a LUN simultaneously.

Because CSVs lock at a file level and not a LUN level, if you try to defragment a disk or use Chkdsk on a CSV with nodes performing direct access, files will be "pinned," or locked, by other nodes and the operations will fail. You therefore have two choices, and which you should pick depends on the maintenance action you want to perform. You can run on redirected access for the CSV, which means only the coordinator node accesses the LUN and all other nodes pass their IO using SMB2 to the coordinator. Or you can or turn on maintenance, which means the CSV is actually removed from the ClusterStorage namespace and any virtual machines (VMs) that use the CSV are stopped by their default actions.

Below is the minimum level you need the CSV in to perform various actions. Redirected access is preferable to maintenance, which takes resources offline.

  • ChkDsk - Reporting only requires redirected access

  • ChkDsk /f - Fixing requires maintenance

  • Defrag /a - Analysis only requires redirected access

  • Defrag /d - Defragmentation only requires redirected access

The interesting point is that ChkDsk and Defrag want to operate on a disk and not a reparse point under %systemdrive%ClusterStorage, so you need to know the GUID of the disk to pass to the commands. In fact, using a GUID is your only option if you're in maintenance mode, because the LUN is no longer visible in the ClusterStorage namespace. If you try to pass a path such as C:ClusterStorageVolumeX, the command will run the action on the C drive, which isn't what you want. We therefore need to perform a number of actions:

  1. Move the CSV to the node you're running the commands on.

  2. Get the GUID of the CSV.

  3. Place the CSV in redirected access or maintenance mode, depending on the action you're taking.

  4. Perform the action using the GUID of the disk.

  5. Bring the disk out of maintenance mode and enable direct access.

While you can do items 1, 3, and 5 from the Failover Cluster Management interface, here I'll show how do perform all the steps from PowerShell. First, load the Failover Cluster library into PowerShell, running with an elevated PowerShell instance. The Get-Module isn't required but it shows the module has been loaded.

PS C:Userssavadmin> Import-Module failoverclustersPS C:Userssavadmin> Get-ModuleName : failoverclustersPath : C:WindowsSystem32WindowsPowerShellv1.0Modulesfailoverclustersfailoverclusters.psd1

To move the CSV to the local node, use the Move-ClusterSharedVolume cmdlet, as shown here.

PS C:Userssavadmin> Move-ClusterSharedVolume "Cluster Disk 3"-Node $env:computernameName State Node---- ----- ----Cluster Disk 3 Online savdalvs01

To obtain the GUID of the disk, use the Get-ClusterSharedVolume cmdlet and pipe the output to fc *, command to get all parameters. You want the Name attribute under the ClusterDiskpartitionInfo class, as shown here. Piping to Fc* performs a custom format using the Format-Custom cmdlet.

PS C:Userssavadmin> Get-ClusterSharedVolume "Cluster Disk 3" | fc *class ClusterSharedVolume{Name = Cluster Disk 3State = OnlineOwnerNode =class ClusterNode{Name = savdalvs01State = Up}SharedVolumeInfo =[class ClusterSharedVolumeInfo{FaultState = NoFaultsFriendlyVolumeName = C:ClusterStorageVolume2Partition =class ClusterDiskPartitionInfo{Name = \?Volume{3803bb0f-05b0-11de-bb45-001fbc00f79d}DriveLetter =

Now put the CSV in redirect or maintenance mode using the Suspend-ClusterResource cmdlet. The commands are shown below, first for redirected mode then for maintenance mode. Obviously, you use only one of the commands.

PS C:Userssavadmin> Get-ClusterSharedVolume "Cluster Disk 3" | Suspend-ClusterResource -RedirectedIOSuspend-ClusterResourceAre you sure that you want to enable redirected IOfor Cluster Shared Volume 'Cluster Disk 3'?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): YName State Node---- ----- ----Cluster Disk 3 Online savdalvs01PS C:Userssavadmin> Get-ClusterSharedVolume "Cluster Disk 3" | Suspend-ClusterResourceSuspend-ClusterResourceAre you sure you want to enable maintenance for Cluster SharedVolume 'Cluster Disk 3'? Putting this shared volume intomaintenance will take all services or applications usingthis volume offline and interrupt client access.[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): YName State Node---- ----- ----Cluster Disk 3 Online savdalvs01

Now you can run commands such as chkdsk or defrag using the GUID of the disk from a cmd.exe prompt.

C:Userssavadmin>chkdsk /f \?Volume{3803bb0f-05b0-11de-bb45-001fbc00f79d}The type of the file system is NTFS.Volume label is Test.

Once you're done, put the CSV back in direct access mode using the Resume-ClusterResource cmdlet.

PS C:Userssavadmin> Get-ClusterSharedVolume "Cluster Disk 3" |Resume-ClusterResourceName State Node---- ----- ----Cluster Disk 3 Online savdalvs01

Finally, if you used maintenance mode you need to manually start any VMs that were using the CSV. Use the Start-ClusterResource cmdlet to do this.

PS C:Userssavadmin> Start-ClusterResource "Virtual Machine savdalxpvrt"Name State Group ResourceType---- ----- ----- ------------Virtual Machine savdalxpvrt Online savdalxpvrt Virtual Machine

The good news is that in the final release of Server 2008 R2, a PowerShell cmdlet will be available to do all this for you, and I'll cover this nearer R2's release when the nondisclosure agreement has lifted. But it's still good to know how to do it manually.

Watch this video to learn more about Windows Server 2008 R2 clustering and virtualization



Related Reading:

Videos:


Check out hundreds more useful Q&As like this in John Savill's FAQ for Windows. Also, watch instructional videos made by John at ITTV.net.

About the Author

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