Have you had a situation in which you wanted to detach a RDM LUN or LUN using NAA id, but could not because there were multiple LUNs with the same size. In such a situation you cannot distinguish which LUN NAA to pick? This post is your answer because what you need is to map the NAA id to a VM. LUNs already in use will show connected to a VM and the LUNs that are not in use should not be attached to any VM. It’s that simple.
Today I was looking to detach some LUNs and it worked fine for the most part until I came across one LUN which had a conflict with another.
Two LUNs had the same size and the same HLU. Moreover, they were also presented as RDM in the same cluster. So it made a bit confusing to find out which LUN I should remove since all I could was identify the LUN using naa id.
Looking around, I came across VMware KB – 2001823 that shows very clearly how to identify virtual machines with Raw Device Mappings (RDMs) attached to them.
The command is very simple and all you need to do is connect to vCenter and run the query –
connect-viserver -server EnterYourvCenterName
Get-VM | Get-HardDisk -DiskType “RawPhysical”,”RawVirtual” | Select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl > output.txt
Note that I took the output to a file (KB uses a different syntax). When you work with a large number of LUNs it is great to have flexibility in searching through a file.
The output came across in the following format :
Parent : Virtual Machine Display Name
Name : Hard disk 4
DiskType : RawVirtual
ScsiCanonicalName : naa.600601602ec03800b92de53df9a6e411
DeviceName : vml.020000000060123456789abcdef0123456789abcde1234567890ab
When I ran the above command, I received a listing of all VMs with their RDM devices. All I had to do after the output was generated was to copy the LUN Identifier (NAA id) from vCenter – one naa id at a time, and search in this file.
If you find it then skip that NAA identifier and do not detach the LUN because that particular LUN is in use. If you search and cannot find the NAA identifier in this file – that would be the one to detach.
Now if anyone has the question – what if there are multiple LUN naa id’s and they cannot be found in this file, then my answer is – you can detach all of those LUNs since they are not being used. If you need to present any LUNs always try to use unique Host LUN Id’s and you would never have any confusion.
In my case, I was trying to remove something that was a legacy item and hence I had a situation with multiple LUNs having same Host LUN ID (HLU).