PowerCLI Script to set RDM LUNs to Perennially Reserved – Fixes Slow Boot of ESXi 5.1 with MSCS RDMs

Written by Sam McGeown
Published on 6/3/2013 - Read in about 3 min (482 words)

vmware logoI’ve previously posted around this topic as part of another problem but having had to figure out the process again I think it’s worth re-posting a proper script for this. VMware KB 1016106 is snappily titled “ESXi/ESX hosts with visibility to RDM LUNs being used by MSCS nodes with RDMs may take a long time to boot or during LUN rescan” and describes the situation where booting ESXi (5.1 in my case) takes a huge amount of time to boot because it’s attempting to gain a SCSI reservation on an RDM disk used by MS Clustering Services. It also details the fix.

The process is fairly simple, but a bit labour intensive if you’re doing it manually on a large cluster.

  1. Retrieve the ScsiCanonicalName for each RDM
  2. Set the configuration for each RDM on each Host to “PerenniallyReserved”

Step 1 - Retrieve the ScsiCanonicalName for each RDM

This PowerCLI command lists the RDM disks attached to any VMs in a particular cluster. What we need here specifically is the SCSI canonical name (often known as the naa or eui identifier), but for the sake of sanity I suggest running it manually and examining the disks to ensure you’re happy with the ones the script will set to PerenniallyReserved:

Get-VM -Location "DefinIT Lab Cluster" | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent,Name,DiskType,ScsiCanonicalName
List RDM Disks in PowerCLI

List RDM Disks in PowerCLI

Step 2 - Set the configuration for each RDM on each Host to “PerenniallyReserved”

Once we have the list of RDM disks, we can then set the reservation via Get-EsxCli

Connect-VIServer "host01.definit.local" -Credential (Get-Credential)
$esxcli = Get-EsxCli
$esxcli.storage.core.device.setconfig($false, "naa.6005076307ffc7930000000000000109", $true)

Building Steps 1 and 2 into a script

Now it’s just a simple case of constructing a script to loop through the hosts in a cluster and the RDMs on each host:

	[string]	$TargetCluster,
	$RootCredentials = (Get-Credential)

# Create a connection object to all hosts in the Target Cluster
Get-Cluster $TargetCluster | Get-VMHost | % { Connect-VIServer $_ -Credential $RootCredentials | Out-Null }

# Find the ScsiCanonicalName for all RDM Disks attached to VMs in the Target Cluster
$RDMDisks = Get-VM -Location $TargetCluster | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select ScsiCanonicalName

# Retrieve and EsxCli instance for each connection
foreach($esxcli in Get-EsxCli) {
	# And for each RDM Disk
	foreach($RDMDisk in $RDMDisks) {
		# Set the configuration to "PereniallyReserved".
		# setconfig method: void setconfig(boolean detached, string device, boolean perenniallyreserved)
		$esxcli.storage.core.device.setconfig($false, ($RDMDisk.ScsiCanonicalName), $true)

# Disconnect the connection objects created for the Target Cluster
Disconnect-VIServer * -Confirm:$false | Out-Null

The script connects to each ESXi instance in the target cluster, queries all VMs on the target cluster and returns the RDM disks and then sets the PerenniallyReserved flag for each of the cluster hosts and RDM disks.

As usual, post any comments or improvements!

Edit: After my conversations with Mike, I’ve modified the script a little and attached as a zip file to download here: Set-RDMReservations



Share this post