I thought you’d be interested in these jobs at Secure-24.

I thought you'd be interested in these jobs at Secure-24..

Match a VM by its MAC address

If you have a MAC address and need to find the VM that uses it:

Get-vm | Select Name, @{N=“Network“;E={$_ | Get-networkAdapter | ? {$_.macaddress -eq “00:50:56:A1:50:43“}}} |Where {$_.Network-ne “”}

Correlate an naa to datastore name via command line

If trying to determine what datastore corresponds to an naa you can use the command below:

esxcfg-scsidevs -m | grep 600601600d00230096fe1215e85ae011

Multipathing Commands

Three commands that are very useful when dealing with multipath policies in vSphere:

Storage Array Type Plugin (SATP)
esxcli nmp satp list

List the LUNs from the SAN represented as their device names
esxcli nmp device list

List the LUNs from the SAN represented as their device names
esxcli nmp device list

Find A Dead Path From Command Line

If you are having pathing issues and the ESX host cannot be managed via vCenter, you can utilize the command line to troubleshoot by using the following commands:
esxcfg-mpath -L | grep dead

You will receive output like the following if there is a dead path:

vmhba1:C0:T1:L14 state:dead naa.60a98000572d43525434575134744343 vmhba1 0 1 14 NMP dead san fc.2000a4badb12b8b2:2002a4badb12b8b2 fc.500a0980892acde5:500a0981992acde5

You can then use the following command to gather more info on the troublesome LUN:

esxcfg-scsidevs -l -d naa.60a98000572d43525434575134744343
naa.60a98000572d43525434575134744343

This will provide output like the following:

Device Type: Direct-Access
Size: 512015 MB
Display Name: NETAPP Fibre Channel Disk (naa.60a98000572d43525434575134744343)
Plugin: NMP
Console Device: /dev/sds
Devfs Path: /vmfs/devices/disks/naa.60a98000572d43525434575134744343
Vendor: NETAPP Model: LUN Revis: 7310
SCSI Level: 4 Is Pseudo: false Status: on
Is RDM Capable: true Is Removable: false
Is Local: false
Other Names:
vml.02000e000060a98000572d435254345751347443434c554e202020

Find What Host A Guest Is Running On And What Datastore It Is Stored On.

If you are in the need of finding what host a VM is running on and want to use PowerCLI to do so, this script will work. It will prompt you for the vCenter FQDN and VM Guest name. Also, it will provide what datastore the VM lives on.

$vcenter = Read-Host -Prompt "vCenter Server (FQDN)"
$guest = Read-Host -Prompt "VM Guest Name"

connect-viserver $vcenter

$vms = Get-VM $guest | Sort Name
$vms | Select Name, @{N="Cluster";E={Get-Cluster -VM $_}}, `
@{N="VMHost";E={Get-VMHost -VM $_}}, `
@{N="Datastore";E={Get-Datastore -VM $_}}

Recreate A Missing VMDK Descriptor File

To create a virtual machine disk:

Log in to the terminal of the VMware ESX host.
For VMware ESX 4.1 and earlier, see Connecting to an ESX host using a SSH client (1019852). Alternatively, access the system directly and press Alt+F1 to begin the login process. Log in as root.
For VMware ESXi 4.1, see Using Tech Support Mode in ESXi 4.1 (1017910).
For VMware ESXi 4.0 and 3.5, see Tech Support Mode for Emergency Support (1003677).

Navigate to the directory that contains the virtual machine disk with the missing descriptor file using the command:

cd /vmfs/volumes/myvmfsvolume/mydir

Identify the type of SCSI controller the virtual disk is using. You can do this by examining the virtual machine configuration file (.vmx). The controller is identified by the line scsi#.virtualDev, where # is the controller number; there may be more than one controller and controller type attached to the virtual machine. This example uses lsilogic:
scsi0.present = “true”
scsi0.sharedBus = “none”
scsi1.present = “true”
scsi1.sharedBus = “virtual”
scsi1.virtualDev = “lsilogic”

Identify and record the exact size of the -flat file using a command similar to:

# ls -l vmdisk0-flat.vmdk

-rw——- 1 root root 4294967296 Oct 11 12:30 vmdisk0-flat.vmdk

Use the vmkfstools command to create a new virtual disk:

# vmkfstools -c 4294967296 -a lsilogic -d thin temp.vmdk

This command uses these flags:

-c (This is the size of the virtual disk).
-a (Whether the virtual disk was configured to work with BusLogic or LSILogic).
-d thin (This creates the disk in a thin-provisioned format).

Note: To save disk space, we create the disk in a thin-provisioned format using the type thin. The resulting flat file then consumes minimal amounts of space (1MB) instead of immediately assuming the capacity specified with the -c switch. The only consequence, however, is the descriptor file contains an extra line that must be removed manually in a later step.

The files temp.vmdk and temp-flat.vmdk are created as a result.

Delete temp-flat.vmdk, as it is not needed. Run the command:

# rm temp-flat.vmdk

Rename temp.vmdk to the name that is required to match the orphaned .flat file (or vmdisk0.vmdk, in this example):

# mv temp.vmdk vmdisk0.vmdk

Edit the descriptor file with a text editor:
Under the Extent Description section, change the name of the .flat file to match the orphaned .flat file you have.
Find and remove the line ddb.thinProvisioned = “1″ if the original .vmdk was not a thin disk. If it was, retain this line.

# Disk DescriptorFile
version=1
CID=fb183c20
parentCID=ffffffff
createType=”vmfs”

# Extent description
RW 8388608 VMFS “vmdisk0-flat.vmdk”

# The Disk Data Base
#DDB

ddb.virtualHWVersion = “4″
ddb.geometry.cylinders = “522″
ddb.geometry.heads = “255″
ddb.geometry.sectors = “63″
ddb.adapterType = “lsilogic”
ddb.thinProvisioned = “1″

The virtual machine is now ready for power on. Verify your changes before starting the virtual machine.

Enable Round Robin For Hosts In A Cluster

Here is a script to enable Round Robin for all hosts in a cluster:

$input | ForEach-Object {
Connect-VIServer vCenterName
Foreach ($ESXhost in get-cluster "ClusterName"| get-vmhost) { Get-VMHost $ESXhost |Get-ScsiLun -LunType "disk"|where {$_.MultipathPolicy -ne "RoundRobin"}| Set-ScsiLun -MultipathPolicy "RoundRobin"
}
}

To set the default adapter type in ESXi console:

esxcli nmp satp setdefaultpsp --satp VMW_SATP_ALUA_CX --psp VMW_PSP_RR

To set Round Robin to all storage presented to a single host:

Get-VMHost FQDNofESXhost | Get-ScsiLun -LunType "disk" | where {$_.MultipathPolicy -ne "RoundRobin"} | Set-ScsiLun -MultipathPolicy "RoundRobin"

Hosts Disconnect From vCenter After 2 Minutes

Scenario:

You add ESX hosts to vCenter. After a couple minutes they appear as disconnected until you reconnect them manually.

Resolution:

Make sure port 902 is open between the vCenter and the hosts and between the hosts themselves. Managed hosts send a heartbeat over UDP 902 to the vCenter server. If this port is blocked the result is disconnected hosts.

Disconnected ESX Server Will Not Reconnect

If an ESX server shows disconnected from the vCenter server and won’t reconnect using more conventional methods, go to the following path in ESX to search the logs for : /var/log/ messages, and look for the following error:

watchdog-hostd: PID file /var/run/vmware/watchdog-hostd.PID not found

Solution:

Run vmware-watchdog -r hostd

If you get /var/run/vmware/watchdog-hostd.PID not found, delete /var/run/vmware/vmware-hostd.PID

Run ps -auwwwwx | grep “vmware-hostd” , Delete the process that exists. For example: [root@xxxxx root]# ps -auwwwwx | grep “vmware-hostd” root 1934 0.9 16.4 136900 44308 ? S Jul19 194:01 /usr/lib/vmware/hostd/vmware hostd /etc/vmware/hostd/config.xml -u root 31287 0.0 0.2 3708 676 pts/0 S 15:04 0:00 grep vmware-hostd [root@xxxxx root]# kill -9 1934
Check if the timestamp of the file watchdog-hostd.PID has changed
ls -lah /var/run/vmware/watchdog-hostd.PID
Run service mgmt-vmware restart
Make sure that /var/run/vmware/vmware-hostd.PID was recreated

←Older