Well I’ve been buried lately under a lot of LUNs. Spring is over and a customer I’m at has forgotten to do their spring cleaning! Needless to say, the LUN presentation and maintenance to their VMware clusters is a mess! In order to audit the system and ensure things were going in my favor, I wrote quite a few PowerShell code blocks/1 liners.
I’ve tried to document as many of them as I could. It’s been one of those projects where a script won’t fix it, but little one liners to jump in and pull out necessary data here and there has made my life so much easier.
Report on VMs with Raw Device Mappings (RDMs)
These few lines show a count of how many RDMs that a VM has. Why is this important to know? Well SCSI has a limitation of 256 LUN mappings. If you have a VM with 30 RDMs, you’ve just cut down the amount of regular data stores you can present. What if you have 8 VMs with 30 LUNs? Well with my math 8×30=240. That’s 240 LUNs. Probably 1 more for a boot lun, and that leaves you with 14 more LUNs. This will generally limit the amount of VMs you’re going to run in your cluster.
$vms = Get-VM $hds = $vms | Get-HardDisk $VMsRdms = $hds | Where {$_.persistence -eq "IndependentPersistent"} $report = $VMsRdms | Group-Object -Property Parent | Sort-Object -Property count
Incompatible device backing specified for device ‘x’
There were quite a few times that an RDM usually ended blocking me from doing a storage migration. I would end up with Incompatible Device Backing for Device “x”. Well device “x” doesn’t really help me determine which hard disk I’m dealing with. PowerShell ….
$deviceX = 17 $vm = Get-VM MYVM $device = $vm.ExtensionData.Config.Hardware.Device[$deviceX] $device.DeviceInfo $device.Backing.Filename
VM Data Store Locations
Not surprisingly at all, there were quite a few VMs that were located on different data stores. Well this works, but it when mapping LUNs, you need to be aware of where the VMs are located!
(Get-VM MYVM | Get-HardDisk).Filename.Split(" ", 2)[0] | Group-Object
Get the LUNID for a VML/RDM File
Quite a few times, I needed to represent an RDM LUN to a set of different hosts. To do this, I :
- Edited the VM
- Located the RDM hard drive
- Copied the VML file location
- Canceled that
- Noted which host the VM was running on and then ran the following code
$vmhost = "Esxi07.corp.ad" $vml = "vml.021101982308f80812830182301923766616277712317919827616" $naa = "naa." + $vml.Substring(14, 32) $lun = Get-ScsiLun -CanonicalName $naa -VmHost $vmhost $PathInfo = $lun | Get-ScsiLunpath $PathInfo | Select-Object Name, @{Name="LunId"; Expression={$_.lunpath -Replace ".*?(\d+$)", '$1'}} | Group-Object -Property LunId