Home > Scripts > Making iSCSI Targets via CMD

Making iSCSI Targets via CMD

Adding iSCSI targets can be cumbersome when you have several volumes on the SAN and several network cards in several hosts.  At Orion there were 8 hosts with 4 NICs and 8 volumes to connect too.  That’s 256 iSCSI connections, and if you use the GUI to make these connections, then you’re talking about doing at least 15 clicks per connection (3840 total) and then try to keep everything straight.  Good luck!   

Rather than clicking 4,000 times (taking into account a few mistakes) I wrote a script that uses a command that Nate gave me to make a Multipath IO connection with iscsicli.exe.  It’s easy to use and should work on any flavor of Windows that uses Microsoft’s iSCSI Initiator (2008 Standard, Core, Hyper-V Server R2, Enterprise, Windows 7, etc).  You just need to discover what “position” your network iSCSI cards are in to prepare the script.   

First, log in to the server and from command line run “iscsicpl” to open the control panel.  Select any target, click Connect and then Advanced.  From here select the Microsoft iSCSI Initiator and then pull down the Initiator IP drop down list.  Use the screenshot below to determine what “Position ID” your iSCSI NICs use.  Then hit Cancel a couple times to back out without making changes.   

    

Now you can edit iSCSINICs.txt to list only the ID’s for each NIC that you want to connect.  Put one number per line for each NIC.  In this example, because the 172.16.0.* NIC’s are being used for iSCSI, you would use:  

5
6
7
8

I do not understand where the order for this list comes from, so I can’t explain why it is listed that way, but I can tell you that if you make changes to your network hardware (like a driver update or share the nic with a virtual network) the order can and likely will change and you’ll have to re-create the iSCSI connections.  So try to get that stuff settled before bothering with this too much.  

Next you can edit iSCSITargets.txt to list each of the iSCSI targets that you want to connect those NICs to.  For example:  

iqn.2001-05.com.equallogic:0-8a0906-d7899e704-8ba0000000b4b437-hv-hio-csv02
iqn.2001-05.com.equallogic:0-8a0906-f5b99e704-1860000000e4b437-hv-mio-csv02
iqn.2001-05.com.equallogic:0-8a0906-fc599e704-20a000000104b437-hv-mio-csv03
iqn.2001-05.com.equallogic:0-8a0906-ff199e704-bbc000000124b437-hv-mio-csv04
iqn.2001-05.com.equallogic:0-8a0906-01999e704-002000000144b438-hv-mio-csv05
iqn.2001-05.com.equallogic:0-8a0906-06799e704-ade000000164b438-hv-mio-csv06

You can pull the target names from the “Discovered Targets” list in iscsicpl by copying it from the “Connect to Target” window or copying it from the Properties page.  

Finally, save the txt files and run the makeTargets.cmd script.  It’ll loop through the list of targets and make a Multi-Path (MPIO) enabled connection for each NIC to it.  Repeat this process on each host.  Make sure to check the NIC ID’s, but you’ll likely only need to get the Targets once. 

@echo off
ECHO.
ECHO Create MPIO "Favorite Targets" for each Nic and Target in the txt files...
Pause
ECHO.</pre>
FOR /F %%T IN (iSCSITargets.txt) DO (
 echo %%T
 FOR /F %%N IN (iSCSINICs.txt) DO (
  echo Targeting Network Interface %%N
  iscsicli persistentlogintarget %%T T * * * %%N * 0x00000002 * * * * * * * * * 0
  REM Sleep for one second, just to let things sort of settle...
  PING -n 2 127.0.0.1>nul
 )
) 

start iscsicpl

Now that they are connected, your next task it to initialize the volume and create a partition…

Advertisements
Categories: Scripts Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: