Configuring an iSCSI Initiator

  1. Install the iscsi-initiator-utils package:

    sudo dnf install iscsi-initiator-utils
  2. Use a discovery method, such as SendTargets or the Internet Storage Name Service (iSNS), to discover the iSCSI targets at the specified IP address.

    For example, you would use SendTargets as follows:

    sudo iscsiadm -m discovery -t sendtargets -p 10.150.30.72

    The following output is displayed:

    10.150.30.72:3260,1 iqn.2013-01.com.mydom.host01.x8664:sn.ef8e14f87344

    This command also starts the iscsid service if it's not already running.

    Note:

    Before running the discovery process, ensure that the firewall is configured to accept communication with an iSCSI target and that ICMP traffic is allowed.

  3. View information about the targets that are now stored in the discovery database.

    sudo iscsiadm -m discoverydb -t st -p 10.150.30.72
    # BEGIN RECORD 6.2.0.873-14
    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 = <empty>
    discovery.sendtargets.auth.password = <empty>
    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.reopen_max = 5
    discovery.sendtargets.timeo.auth_timeout = 45
    discovery.sendtargets.timeo.active_timeout = 30
    discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
    # END RECORD
  4. Establish a session and log in to a specific target:

    sudo iscsiadm -m node -T iqn.2013-01.com.mydom.host01.x8664:sn.ef8e14f87344 \
    -p 10.150.30.72:3260 -l
    
    Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:
    sn.ef8e14f87344, portal: 10.150.30.72,3260] successful.
  5. Verify that the session is active and display the available LUNs:

    sudo iscsiadm -m session -P 3

    The following output is displayed:

    iSCSI Transport Class version 2.0-870
    version 6.2.1.9
    Target: iqn.2003-01.com.mydom.host01.x8664:sn.ef8e14f87344 (non-flash)
    	Current Portal: 10.0.0.2:3260,1
    	Persistent Portal: 10.0.0.2:3260,1
    		**********
    		Interface:
    		**********
    		Iface Name: default
    		Iface Transport: tcp
    		Iface Initiatorname: iqn.1994-05.com.mydom:ed7021225d52
    		Iface IPaddress: 10.0.0.2
    		Iface HWaddress: <empty>
    		Iface Netdev: <empty>
    		SID: 5
    		iSCSI Connection State: LOGGED IN
    		iSCSI Session State: LOGGED_IN
    		Internal iscsid Session State: NO CHANGE
    .
    .
    .
    		************************
    		Attached SCSI devices:
    		************************
    		Host Number: 8	State: running
    		scsi8 Channel 00 Id 0 Lun: 0
    			Attached scsi disk sdb		State: running
    		scsi8 Channel 00 Id 0 Lun: 1
    			Attached scsi disk sdc		State: running

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

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

To distinguish between target LUNs, examine the paths under /dev/disk/by-path, which is displayed by using the following command:

ls -l /dev/disk/by-path/
lrwxrwxrwx  1 root root  9 May 15 21:05
  ip-10.150.30.72:3260-iscsi-iqn.2013-01.com.mydom.host01.x8664:
  sn.ef8e14f87344-lun-0 -> ../../sdb
lrwxrwxrwx 1 root root  9 May 15 21:05
  ip-10.150.30.72:3260-iscsi-iqn.2013-01.com.mydom.host01.x8664:
  sn.ef8e14f87344-lun-1 -> ../../sdc

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

sudo grep sdb /var/log/messages
...
May 18 14:19:36 localhost kernel: [12079.963376] sd 8:0:0:0: [sdb] Attached SCSI disk
...

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

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

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

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

Note:

When adding iSCSI LUN entries to /etc/fstab, see the LUN by using UUID= UUID rather than the device path. A device path can change after reconnecting the storage or rebooting the system. To display the UUID of a block device, the blkid command.

Any discovered LUNs remain available across reboots if the target continues to serve those LUNs and you don't log the system off the target.

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