Get iSCSI iqn from the ESX Command Line

I was in my personal ESX about to upgrade to update 1. I was distracted by trying to setup iSCSI from the command line. Right before I looked to the vSphere Client to get the iqn I said, “There is surely a way for me to find this from the command line.”

Searching around I found the command vmkiscsi-tool. Really good stuff, I can complete the rest of my setup without the GUI. One thing though to list out the iqn for iscsi after you enable it you must know the device name (ie vmhba??).

Using this command:
vmkiscsi-tool -I -l

I usually guess the iscsi hba is vmhba33 or 32 but how do I know for sure?
esxcfg-scsidevs -a
Ok great, now we know it is vmhba33

[[email protected] sbin]# vmkiscsi-tool -I -l vmhba33
iSCSI Node Name:
[[email protected] sbin]#

Now with a few more vmkiscsi-tool commands I can finish configuring my iSCSI.
Add the Ip of the SAN:
[[email protected] sbin]# vmkiscsi-tool -D -a vmhba33
Now rescan:
[[email protected] sbin]# esxcfg-rescan -a vmhba33

ESX Commands: esxcfg-vswitch

This is a command I use the most often. It is big when I configure Equalogic and MPIO in vSphere. Additionally, many times I show up on site and the network is not configured prior to my arrival. Even if I sent all the configs ahead of time. People like to wait until the last minute. When building the ESX environment then I may build it with the Service Console in the default vlan or in which ever one it is plugged into in the physical network. So oftern the network guy catches up and sets the dot1q trunk and I lose connectivity and I have to go to the console and set the vlans correctly. Like this:
esxcfg-vswitch -v 8 -p "Service Console" vSwitch0
Speaking of iSCSI you will also set your jumbo frames on the vSwitch from this command
esxcfg-vswitch -m 9000 vSwitch1
Of course there is a ton more you can do from this command. Here is some man page action for you:

esxcfg-vswitch(8) VMware ESX Manual esxcfg-vswitch(8)

esxcfg-vswitch - VMware ESX Virtual Switch Configuration tool

esxcfg-vswitch OPTIONS [VSWITCH]

esxcfg-vswitch provides an interface for adding, removing, and modifying virtual switches and their settings. By default,
there is a single virtual switch called vSwitch0.

-a --add
Add a new virtual switch to the system. It requires a virtual switch name to be provided.

-d --delete
Delete a virtual switch. This will fail if any ports on the virtual switch are still in use by VMkernel networks,
vswifs, or VMs.

-l --list
List all virtual switches and their portgroups.

-L --link
Add an uplink to a virtual switch. This will attach a new unused physical NIC to a virtual switch.

-U --unlink
Remove an uplink from a virtual switch. This will remove a NIC from the uplink list of a virtual switch. If it is
the last uplink, physical network connectivity for that switch will be lost.

-R --restore-uplinks
Restore uplinks for all virtual switches from config file. This will restore all uplinks for each virtual switch from
configurtion file. INTERNAL USE ONLY.

-M --add-pg-uplink
Add an uplink to the list of uplinks for a portgroup

-N --del-pg-uplink
Delete an uplink from the list of uplinks for a portgroup

-P --add-dvp-uplink
Add an uplink to a DVPort on a DVSwitch. Must specify --dvp in the same commnad.

-Q --del-dvp-uplink
Delete an uplink from a DVPort on a DVSwitch. Must specify --dvp in the same commnad.

-p --pg
Provide the name of the portgroup. For the â--vlanâ option, "ALL" can be specified to operate on all portgroups of a
virtual switch.

-V --dvp
Provide the DVPort ID of a DVSwitch.
-v --vlan
Set the VLAN ID for a specific portgroup of a virtuals switch Using the option "0" will disable VLAN for this port-
group. Requires that the --pg option is also specified.

-c --check
Check to see if a virtual switch exists. The program prints a "1" if it exists; otherwise it prints "0".

-A --add-pg
Add a new portgroup to a virtual switch with the given name.

-D --del-pg
Delete a portgroup. This operation will fail if the portgroup is in use.

-C --check-pg
Check whether the specified name is in use for a portgroup. Prints "1" if the name is in use, prints "0" otherwise.

-B --set-cdp
Set the CDP status for a given virtual switch. To set pass one of "down", "listen", "advertise", "both".

-b --get-cdp
Print the current CDP setting for this switch.

-X --set-maxactive
Set the max active uplinks for the virtual switch.

-x --get-maxactive
Get the max active uplinks for the virtual switch.

-m --mtu
Set the MTU for the vswitch. This affects all the NICs attached to the vswitch.

-r --restore
Used at system startup to restore configuration. INTERNAL USE ONLY.

-h --help
Print a simple help message.

Add a Virtual Switch:

esxcfg-vswitch --add vSwitch1

Add a Portgroup to vSwitch0:

esxcfg-vswitch --add-pg="New Portgroup" vSwitch0

VMware ESX is Copyright 1998-2009 VMware, Inc. All rights reserved.

VMware ESX 4.0 November 22, 2009 VMware ESX 4.0

ESX Commands: esxcfg-pciid,rescan,resgrp,swiscsi,upgrade, vmhbadevs

I have been writing on ESX command line stuff for far too long now. I just need to finish it before ESX 5 comes out with no command line support and my year long series is rendered obsolete before it is finished.

Here is a few more commands from ESX 3.5u4. They are pretty short and sweet. So enjoy.
Used to read the xml files under /etc/vmware/pciid/ – from what I can tell it is used in the process of getting unsupported hardware to work.

Supply this command with a vm hba and it will rescan for new LUNs.

Do a esxcfg-resgrp -l and get a ton of information try following it with a “| more”: esxcfg-resgrp -l | more
It does include options to add remove and restore resource groups. Here is a place on the interwebs with information on how to use it.

Used to enable and disable the Software iSCSI Initiator. esxcfg-swiscsi -q will give you the list of the status.
Make sure to create a vmkernel port first.

According to the ESX Configuration Guide this command is not for general use but is used to upgrade VMFS2 to VMFS3. Would be very smart to have moved all VM’s off of the VMFS2 before messing with this command.

Use the -m tag to list all vmfs volumes. Typical output will look like this:
vmhba0:0:0:3 /dev/sda3 4afc26df-ddbe3ee5-2037-000c29acbc0a

Upgrade to vSphere already

OK, SRM and View 4 are out. Go ahead and start planning those upgrades from 3.x to 4. I mean really, vSphere is out now for almost 6 months. Get Enterprise Plus or the Acceleration kit, just get to vSphere. Here are a few of my reason’s why.

1. Round Robin Storage IO. Those without can giant Fiber Channel SAN infrastructure can start to stack the Software iSCSI ports and get performance above and beyond what was possible before with iSCSI. Equalogic, Lefthand and other iSCSI SAN manufacturers have to be throwing huge parties about this. While talking about iSCSI you don’t need a Service Console just for every iSCSI VMkernel port. This always seemed like extra setup in 3.x.

2 Thin Provisioning, I am not technical enough with storage to know if SAN based thin provisioning is better for some reason. It is great to be able to save space with template and other large footprint VM’s.

3. dVSwitch, VMsafe and vShield zones. New hooks for security will eventually give us insight into areas of the VI we could not see before. VMsafe will let vendors tie into the kernel (at least that is how I understand it). Additionally the new dVSwitch (Distributed Virtual Switch, sometimes it is called something else) will give control and sight into the network stack in ways that was impossible before.

This is stuff many may have read on the release date in May, but now that I have seen vSphere in action and some of the biggest hurdles (SRM and View) have been overcome, it is now time to upgrade, already.