iSCSI Multi LUN Howto

Recently I needed to connect a server to multiple iSCSI targets with each target requiring a unique username and password. From what I can tell this isn’t a well documented feature of openiscsi, nor is it handled cleanly in the config file. All that I could find was an email thread that briefly outlined how to get it working.

Here’s how I implemented this on a RHEL 5 host with an equallogic backend.

How it works

From what I gather, In order to make this work you first need to add multiple new discovery records. Each time changing the contents of /etc/iscsi/iscsid.conf to reflect your differ username/password combinations. This must be done in a particular way to avoid the default discovery behavior which removes records that are no longer present (for your current user). The command used to perform discovery is as follows, the ‘-o new’ argument prevents removal of old records.

  # edit /etc/iscsi/iscsid.conf to change user/pass for current target, then
  iscsiadm -m discovery -t st -p portal_ip_address -o new --discover

Once discovered, the username and password needs to be set individually for that target.

  iscsiadm -m node --targetname TARGET -p PORTAL -o update -n node.session.auth.username -v USERNAME
  iscsiadm -m node --targetname TARGET -p PORTAL -o update -n node.session.auth.password -v PASSWORD

At this point you should be able to log in/out of that target

  iscsiadm -m node --targetname TARGET -p PORTAL --login

Now rince, lather and repeat for the remainder if your target/portal/username/password combinations.

Scripting the process

This script takes an array of portal ips, usernames and passwords then loops through them attempting to log in to all available iSCSI available. Once performed once the connections should be remembered across iSCSI logouts and reboots.

This is currently working well for me on RHEL5, YMMV.

# - Set up connections for multiple iSCSI targets having 
#                        unique portal/user/password combinations.
#			 This script will attempt to log in to all available targets
#			 on the supplied portal addresses.
#                        2012 Keith Herron <[email protected]>
while [ $i -lt ${#PORTAL[@]} ]; do
  echo Discovering on ${PORTAL[$i]} as user ${USERNAME[$i]}:
  # Set discovery user/pass in /etc/iscsi/iscsid.conf
  sed -i "s/^#\?discovery.sendtargets.auth.username.*/discovery.sendtargets.auth.username = ${USERNAME[$i]}/g" /etc/iscsi/iscsid.conf
  sed -i "s/^#\?discovery.sendtargets.auth.password.*/discovery.sendtargets.auth.password = ${PASSWORD[$i]}/g" /etc/iscsi/iscsid.conf
  sleep 1
  # Perform discovery (note -o new argument, this is important)
  TARGET[$i]=`iscsiadm -m discovery -t st -p ${PORTAL[$i]} -o new --discover | awk '{ print $2}'`
  echo Found IQN: ${TARGET[$i]}
  # Set username/password individually for each target, and login
  iscsiadm -m node --targetname ${TARGET[$i]} -p ${PORTAL[$i]} -o update -n node.session.auth.username -v ${USERNAME[$i]}
  iscsiadm -m node --targetname ${TARGET[$i]} -p ${PORTAL[$i]} -o update -n node.session.auth.password -v ${PASSWORD[$i]}
  iscsiadm -m node --targetname ${TARGET[$i]} -p ${PORTAL[$i]} --login
  # Log out of target
  iscsiadm -m node --targetname ${TARGET[$i]} --logout 
# Set discovery user/password to nothing in hopes to prevent manual discovery
sed -i "s/^discovery.sendtargets.auth.username.*/discovery.sendtargets.auth.username = /g" /etc/iscsi/iscsid.conf
sed -i "s/^discovery.sendtargets.auth.password.*/discovery.sendtargets.auth.password = /g" /etc/iscsi/iscsid.conf
# Log in to all nodes now
echo Logging in to all nodes
iscsiadm -m node --login

Hope that helps, please leave a comment if you found this helpful. Or if you were able to adapt it to work on a different distribution.

5 Responses to “iSCSI Multi LUN Howto”

  1. serhan Says:

    thank you! saved me hours!


  2. Joe Says:

    Seriously! I was looking through all the docs and everything I saw said you couldn’t do this. Put your script in and it worked immediately.

    I’ve got the same setup: Centos with Equallogic


  3. Gerhard Says:

    thank you very much! It helped me connecting different targets (on our centos fileserver) to one other centos system


  4. Martin Says:

    Big thanks for this. You have saved me hours of research time.


  5. Amaya Says:

    saeid salamgprs to ksvreahhaye digeh kar mikhone ?exp:Turkiyekhate MCI daram sharj ham tosh hast , ama in setting ro ke vared mikonam ,,kar nemikone !GPRS am active hast az site active kardam ,pakage 24H -150mg gereftam vaseye testama kar nakardmitonin komakam konin ?ba tashakorsaeid


Join the Conversation