Sunday 29 October 2017

How to Get ESXi Boot Device

How to get ESXi boot device?

If you need to see the current boot device of ESXi or from which device ESXi is running then follow below steps.


1. Enable SSH on ESXi host.

2. Login to ESXi server using root and its password.

3. Run below Command to get boot volume

#ls -l /bootbank | awk -F"-> " '{print $2}'

E.g output
[root@esxi01:~] ls -l /bootbank | awk -F"-> " '{print $2}'
/vmfs/volumes/50705ae3-b08ce25f-a1b8-bc56258253ad

4. Copy vmfs volume and run below command to get more details about volume.

#vmkfstools -P vmfsVolumeID

[root@esxi01:~] vmkfstools -P /vmfs/volumes/50705ae3-b08ce25f-a1b8-bc56258253ad
vfat-0.04 (Raw Major Version: 0) file system spanning 1 partitions.
File system label (if any):
Mode: private
Capacity 261853184 (63929 file blocks * 4096), 90677248 (22138 blocks) avail, max supported file size 0
UUID: 50705ae3-b08ce25f-a1b8-bc56258253ad
Partitions spanned (on "disks"):
       eui.00a0504658335330:5
Is Native Snapshot Capable: NO

5. From above command output copy the disks/partition UID and run below command to get device details.

#esxcli storage core device list | grep -A27 deviceID

[root@esxi01:~] esxcli storage core device list | grep -A27 eui.00a0504658335330
eui.00a0504658335330
  Display Name: Local USB Direct-Access (eui.00a0504658335330)
  Has Settable Display Name: false
  Size: 30436
  Device Type: Direct-Access
  Multipath Plugin: NMP
  Devfs Path: /vmfs/devices/disks/eui.00a0504658335330
  Vendor: Cypress
  Model: SDRAID
  Revision: 0000
  SCSI Level: 2
  Is Pseudo: false
  Status: on
  Is RDM Capable: false
  Is Local: true
  Is Removable: true
  Is SSD: false
  Is VVOL PE: false
  Is Offline: false
  Is Perennially Reserved: false
  Queue Full Sample Size: 0
  Queue Full Threshold: 0
  Thin Provisioning Status: unknown
  Attached Filters:
  VAAI Status: unsupported
  Other UIDs: vml.0000000000766d68626133323a303a30
  Is Shared Clusterwide: false
  Is Local SAS Device: false
  Is SAS: false
  Is USB: true
  Is Boot USB Device: true
  Is Boot Device: true
  Device Max Queue Depth: 1
  No of outstanding IOs with competing worlds: 32

In above command you can see, this ESXi host is booted and running from USB device.

Above process looks simple and useful.
If you have large number of ESXi hosts and want to export all ESXi hosts boot device then you can automate it using PowerShell and bash scripting.

How to Export ESXi Boot Device?

  1. Enable SSH on all ESXi hosts for which you want to get boot device. You can use PowerShell script to automate enabling SSH service on many esxi hosts at once.

  1. Create a text file with below command and save it as c:\temp\ESXi-boot-device-cmd.txt

b=`ls -l /bootbank | awk -F"-> " '{print $2}'`
d=`vmkfstools -P $b | egrep 'mpx|naa|eui' | awk -F":" '{print $1 }' | sed -e 's/^[ \t]*//'`
esxcli storage core device list | grep -A27  $d | egrep 'Display Name:|Size:|Multipath Plugin:|Devfs Path:|Vendor:|Model:|Revision:|Is RDM Capable:|Is Local:|Is Removable:|Is Shared Clusterwide:|Is USB:|Is Boot USB Device:|Is Boot Device:' | awk -F":" '{print $2}' |sed  's/ //g' | awk -vRS="" -vOFS=',' '$1=$1'

3. Download plink.exe and save it in c:\temp\ folder

https://the.earth.li/~sgtatham/putty/latest/w32/plink.exe
Plink is a command line connection tool similar to unix SSH.

What is plink?

4. Below is a PowerShell script to Export boot device of all ESXi hosts.

Change below variable in script -
$folder - folder where you have saved esxi command file, plink.exe
$vcenter - change vcenter name
$password - enter your ESXi password.

This script connect to all ESXi hosts which are connected in vCenter, then it connect to each ESXi hosts using SSH and execute ESXi command and finally it exports boot device to $vcenter-boot-device-info.csv file.


$folder = "C:\temp\"
$vcenters = "vcenter01"
$password = 'EsxiPassword'

foreach ( $vcenter in $vcenters ) {

   connect-viserver $vcenter

   $vmhosts = get-vmhost | where { $_.connectionState -ne "NotResponding" } | sort Name

$report = @()

foreach ( $vmhost in $vmhosts.name ) {

   $details = " " | select HostName,DeviceName,SettableDisplay,Size,MPP, DevfSPath, Vendor,Model,Revision,RDM,Local,Removable,QueueSize,isShared,isUSB,BootUSB,isBootDevice

   $details.Hostname = $vmhost

   echo y | $folder\plink.exe  -ssh root@$vmhost -pw $password hostname
   $hostdetails = $folder\plink.exe  -ssh root@$vmhost -pw $password -m $folder\cmd.txt
   $details.devicename = $hostdetails

   $report += $details
   }
   $report | export-csv -NoTypeInformation -path $folder\$vcenter-boot-device-info.csv
}

Once you get CSV, you would need to open it in Excel and select all cell from B2 and do text to column and separate all cells from B2 text with comma as delimiter.   

E.g. output



No comments:

Post a Comment