18.7.2 Configuring an iSCSI Initiator

To configure an Oracle Linux system as an iSCSI initiator:

  1. Install the iscsi-initiator-utils package:

    # yum install iscsi-initiator-utils
  2. Use the SendTargets discovery method to discover the iSCSI targets at a specified IP address:

    # iscsiadm -m discovery --type sendtargets -p 10.150.30.72
    Starting iscsid:                               [ OK ]
    10.150.30.72:3260,1 iqn.2012-01.com.mydom.host01:target1
    10.150.30.72:3260,1 iqn.2012-01.com.mydom.host01:target2
    Note

    An alternate discovery method is Internet Storage Name Service (iSNS).

    The command also starts the iscsid service if it is not already running.

    The following command displays information about the targets that is now stored in the discovery database:

    # iscsiadm -m discoverydb -t st -p 10.150.30.72
    # BEGIN RECORD 2.0-872.41.el6
    discovery.startup = manual
    discovery.type = sendtargets
    discovery.sendtargets.address = 10.150.30.72
    discovery.sendtargets.port = 3260
    discovery.sendtargets.auth.authmethod = None
    discovery.sendtargets.auth.username_in = <empty>
    discovery.sendtargets.auth.password_in = <empty>
    discovery.sendtargets.timeo.login_timeout = 15
    discovery.sendtargets.use_discoveryd = No
    discovery.sendtargets.discoveryd_poll_inval = 30
    discovery.sendtargets.repoen_max = 5
    discovery.sendtargets.timeo.auth_timeout = 45
    discovery.sendtargets.timeo.active_timeout = 30
    discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
  3. Establish a session and log in to a specific target:

    # iscsiadm -m node --targetname iqn.2012-01.com.mydom.host01:target1 \
      -p 10.150.30.72:3260 -l
    Login to [iface: default, target: iqn.2012-01.com.mydom.host01:target1, 
    portal: 10.150.30.72:3260] successful.
  4. Verify that the session is active, and display the available LUNs:

    # iscsiadm -m session -P 3
    Target: iqn.2012-01.com.mydom.host01:target1
    Current Portal: 10.150.30.72:3260,1
    Persistent Portal: 10.150.30.72:3260,1
    **********
    Interface:
    **********
    Iface Name: default
    Iface Transport: tcp
    Iface Initiatorname: iqn.1988-12.com.mydom:392a7cee2f
    Iface IPaddress: 192.0.2.101
    Iface HWaddress: <empty>
    Iface Netdev: <empty>
    SID: 1
    iSCSI Connection State: LOGGED IN
    iSCSI Session State: LOGGED IN
    Internal iscsid Session State: NO CHANGE
    .
    .
    .
    ************************
    Attached SCSI devices:
    ************************
    Host Number: 4 State: running
    scsi10 Channel 00 Id 0 Lun:0
    scsi10 Channel 00 Id 0 Lun:1
        Attached scsi disk sdb
    State: running
    scsi10 Channel 00 Id 0 Lun:2
        Attached scsi disk sdc
    State: running

    The LUNs are represented as SCSI block devices (sd*) in the local /dev directory, for example:

    # fdisk -l | grep /dev/sd[bc]
    Disk /dev/sdb: 10.7 GB, 10737418240 bytes
    Disk /dev/sdc: 10.7 GB, 10737418240 bytes

    To distinguish between target LUNs, examine their paths under /dev/disk/by-path:

    # ls -l /dev/disk/by-path/
    lrwxrwxrwx  1 root root  9 May 15 21:05
      ip-10.150.30.72:3260-iscsi-iqn.2012-01.com.mydom.host01:02:
      084591f8-6b8b-c857-f002-ecf8a3b387f3-lun-1 -> ../../sdb
    lrwxrwxrwx 1 root root  9 May 15 21:05
      ip-10.150.30.72:3260-iscsi-iqn.2012-01.com.mydom.host01:02:
      084591f8-6b8b-c857-f002-ecf8a3b387f3-lun-2 -> ../../sdc

    You can view the initialization messages for the LUNs in the /var/log/messages file:

    # grep -i scsi /var/log/messages
    Apr 8 15:08:53 host02 kernel: scsi12 : iSCSI Initiator over TCP/IP
    Apr 8 15:08:53 host02 kernel: sd 4:0:0:1: [sdb] Attached SCSI disk
    Apr 8 15:08:53 host02 kernel: sd 4:0:0:2: [sdc] Attached SCSI disk

    You can configure and use a LUN in the same way as you would any other physical storage device. For example, you can configure it as an LVM physical volume, file system, swap partition, Automatic Storage Management (ASM) disk, or raw device.

    Specify the _netdev option when creating mount entries for iSCSI LUNs in /etc/fstab, for example:

    UUID=084591f8-6b8b-c857-f002-ecf8a3b387f3     /iscsi_mount_point     ext4     _netdev   0  0

    This option indicates the file system resides on a device that requires network access, and prevents the system from attempting to mount the file system until the network has been enabled.

    Note

    Specify an iSCSI LUN in /etc/fstab by using UUID=UUID rather than the device path. A device path can change after re-connecting the storage or rebooting the system. You can use the blkid command to display the UUID of a block device.

    Any discovered LUNs remain available across reboots provided that the target continues to serve those LUNs and you do not log the system off the target.

For more information, see the iscsiadm(8) and iscsid(8) manual pages.