Wednesday, February 3, 2016

Some useful storage related VMware Esxi commands

In this post I will talk about some useful storage related commands but before that I would like to mention about, getting help in Esxi local/remote shell or vCLI.

At any time to get help about any command or list all available namespace and options for a particular command we can use --help option.
We can use the --help option in same way for any other command.

Note: You can run these commands over local/remote shell or using vCLI. When using vCLI then you will also need to provide connection parameter and the command syntax would be as follows,
#esxcli --server ESXi_host_IP_or_Name --username noor --password noor2122 [<namespace> ...] <cmd> [cmd options]
#esxcli -s ESXi_host_IP_or_Name -u noor -p noor2122 [<namespace> ...] <cmd> [cmd options]

Now lets talk about some some useful storage related commands,

Command to view all LUNs presented to a host
#esxcfg-scsidevs -c  
And to check about a specific LUN,
#esxcfg-scsidevs -c | grep

To find the unique identifier of the LUN,  you may run this command:
# esxcfg-scsidevs -m
To find associated datastore using a LUN id
#esxcfg-scsidevs -m|grep

To get a list of RDM disks, you may run following command,
#find /vmfs/volumes/ -type f -name '*.vmdk' -size -1024k -exec grep -l '^createType=.*RawDeviceMap' {} \; > /Datastore123/rdmsluns.txt  This command will save the list of all RDM disk to a text file rdmluns.txt and save it to Datastore123.

Now Run following command to find the associated LUNs,             
#for i in `cat /tmp/rdmsluns.txt`; do vmkfstools -q $i; done
This command will give you the of rdm luns,
Now use following cmd to map to
#ls -luth /dev/disks/ |grep    in output of this command you will get LUN id/

To mark an RDM device as perennially reserved:
#esxcli storage core device setconfig -d --perennially-reserved=true   you may create an script to mark all RDMs as perennially reserved in one go.

Confirm that the correct devices are marked as perennially reserved by running this command on the host:
#esxcli storage core device list |less

To verify about an specific lun/device, run this command:
#esxcli storage core device list -d

The configuration is permanently stored with the ESXi host and persists across restarts.

To remove the perennially reserved flag, run this command
#esxcli storage core device setconfig -d --perennially-reserved=false

To obtain LUN multipathing information from the ESXi host command line:

To get detailed information regarding the paths.
#esxcli storage core path list
or To list the detailed information of the corresponding paths for a specific device,
#esxcli storage core path list -d naa.ID

To figure out if the device is managed by VMware’s native multipath plugin, the NMP or it is managed by a third-party plugin
#esxcli storage nmp device list -d  
This command not only confirms that the device is managed by NMP, but will also display the Storage Array Type Plugin (SATP) for path failover and the Path Selection Policy (PSP) for load balancing.

To list LUN multipathing information,
#esxcli storage nmp device list

To check the existing path selection policy
#esxcli storage nmp satp list

To change the multipathing policy
# esxcli storage nmp device set --device naa_id --psp path_policy

Note: These pathing policies apply to VMware's Native Multipathing (NMP) Path Selection Plug-ins (PSP). Third-party PSPs have their own restrictions 

To generate a list of all LUN paths currently connected to the ESXi host.
#esxcli storage core path list command

For the detail path information of a specific device
#esxcli storage core path list -d

To generate a list of extents for each volume and mapping from device name to UUID,
#esxcli storage vmfs extent list command

or To generate a compact list of the LUNs currently connected to the ESXi host, including VMFS version.
#esxcli storage filesystem list

To list the possible targets for certain storage operations,
#ls -alh /vmfs/devices/disks

To rescan all HBA Adapters,
#esxcli storage core adapter rescan --all

To rescan a specific HBA.
#esxcli storage core adapter rescan --adapter <vmkernel SCSI adapter name>  Where <vmkernel SCSI adapter name> is the vmhba# to be rescanned.

To get a list of all HBA adapters,
#esxcli storage core adapter list command
Note: There may not be any output if there are no changes.

To search for new VMFS datastores, run this command,
#vmkfstools -V

To check which VAAI primitives are supported.
#esxcli storage core device vaai status get -d

The esxcli storage san namespace has some very useful commands. In the case of fiber channel you can get information about which adapters are used for FC, and display the WWNN (nodename) and WWPN (portname) information, speed and port state
#esxcli storage san fc list

To display FC event information:
# esxcli storage san fc events get

For example: vml.02000b0000600508b4000f57fa0000400002270000485356333630
Breaking apart the VML ID for a closer understanding: The first 4 digits are VMware specific and
the next 2 digits are the LUN identifier in hexadecimal.

In the preceding example, the LUN is mapped to LUN ID 11 (hex 0b).

NAA id
NAA stands for Network Addressing Authority identifier. EUI stands for Extended Unique Identifier. The number is guaranteed to be unique to that LUN.

The NAA or EUI identifier is the preferred method of identifying LUNs and the number is generated by the storage device. Since the NAA or EUI is unique to the LUN, if the LUN is presented the same way across all ESXi hosts, the NAA or EUI identifier remains the same.

Path Identifier: vmhba<Adapter>:C<Channel>:T<Target>:L<LUN> 
This identifier is now used exclusively to identify a path to the LUN. When ESXi detects that paths associated to one LUN, each path is assigned this Path Identifier. The LUN also inherits the same name as the first path, but it is now used an a Runtime Name, and not used as readily as the above mentioned identifiers as it may be different depending on the host you are using. This identifier is generally used for operations with utilities such as vmkfstools.
Example: vmhba1:C0:T0:L0 = Adapter 1, Channel 0, Target 0, and LUN 0.

That's it... :)

1 comment: