Intr

iSCSI is an Internet Protocol (IP)-based storage networking standard for linking data storage facilities. By carrying SCSI commands over IP networks, iSCSI is used to facilitate data transfers over intranets and to manage storage over long distances.

iSCSI is a client-server protocol. the server side is called 'target', while the client side is referred as the ' initiator'. Both target and initiator are uniquely identified by a string called the iSCSI Qualified Name(iQN).

 

Clients (called Initiators) sends SCSI commands (CDBs) to SCSI storage devices (Linux-IO Targets) on remote servers over internet. Unlike traditional Fibre Channel, which requires special-purpose cabling, iSCSI can be run over long distances using existing network infrastructure.

There are two different type of target, one is hardware based(iSCSI storage box), the other is software based. Here I'm going to show you how to config server side target on Linux. In this example, I'm using SL6.4, same to RHEL6.4, CentOS6.4, also can be reference to other Linux distributions.

Package installation

# yum install scsi-target-utils.x86_64 iscsi-initiator-utils.x86_64

================================================================================================
 Package                      Arch      Version          Repository       Size
================================================================================================
Installing:
 iscsi-initiator-utils       x86_64  6.2.0.873-10.el6   sl             685 k
 scsi-target-utils            x86_64   1.0.24-10.el6     sl             174 k
Installing for dependencies:
perl-Config-General          noarch      2.52-1.el6         sl              71 k
sg3_utils                    x86_64    1.28-5.el6       sl             470 k

Transaction Summary
===============================================================================================
Install       4 Package(s)

Total download size: 1.4 M
Installed size: 4.1 M
Is this ok [y/N]: y

Installed:
  iscsi-initiator-utils.x86_64 0:6.2.0.873-10.el6   scsi-target-utils.x86_64 0:1.0.24-10.el6    

Dependency Installed:
perl-Config-General.noarch 0:2.52-1.el6     sg3_utils.x86_64 0:1.28-5.el6              

Start iSCSI target service

To start target service

# service tgtd start
Starting SCSI target daemon:                               [  OK  ]

To stop target service

 # service tgtd stop
Stopping SCSI target daemon:                               [  OK  ]

Add device to iSCSI target

Two ways to add device to iSCSI target. The following examples in different way creates a target with id 1 (the iqn is iqn.2015-01.com.fibrevillage.pps11:pps11.target1) and adds a logical unit (backed by a block device /dev/mapper/ddnlun1) with lun 1.

Note:

backing-store or direct-store directives where backing-store refers to either a file or a block device, and direct-store refers to local SCSI devices. In the example below, it's a block device.

Command line, using tgtadm and tgt-admin

Step1: Create a target device
# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2015-01.com.fibrevillage.pps11:pps11.target1
Step2: Add a logic unit
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/mapper/ddnlun1
Step3: Enable target to accept any initiator
# tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
Step4: Save the configuration
# tgt-admin --dump
default-driver iscsi

<target iqn.2015-01.com.fibrevillage.pps11:pps11.target1>
    backing-store /dev/mapper/ddnlun1
</target>

# tgt-admin --dump >>targets.conf

Direct modify the configuration file, /etc/tgt/targets.conf

Add the following lines to /etc/tgt/targets.conf

default-driver iscsi

<target iqn.2015-01.com.fibrevillage.pps11:pps11.target1>
    backing-store /dev/mapper/ddnlun1
</target>

Then, restart tgt service, that's it.

Note about iSCSI IQN:

iSCSI Qualified Name (IQN)
Format: The iSCSI Qualified Name is documented in RFC 3720, with further examples of names in RFC 3721. Briefly, the fields are:
  • literal iqn (iSCSI Qualified Name)
  • date (yyyy-mm) that the naming authority took ownership of the domain
  • reversed domain name of the authority (e.g. org.alpinelinux, com.example, to.yp.cr)
  • Optional ":" prefixing a storage target name specified by the naming authority.
From the RFC:
                  Naming     String defined by
     Type  Date    Auth      "example.com" naming authority
    +--++-----+ +---------+ +-----------------------------+
    |  ||     | |         | |                             |     
 
    iqn.1992-01.com.example:storage:diskarrays-sn-a8675309
    iqn.1992-01.com.example
    iqn.1992-01.com.example:storage.tape1.sys1.xyz
    iqn.1992-01.com.example:storage.disk2.sys1.xyz[10]

List iSCSI targets

#  tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2015-01.com.fibrevillage.pps11:pps11.target1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 8001581 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/mapper/ddnlun1
            Backing store flags:
    Account information:
    ACL information:
        ALL
[root@pps11 tgt]

Restart iSCSI target service

# service tgtd restart
Stopping SCSI target daemon:                               [  OK  ]
Starting SCSI target daemon:                               [  OK  ]

Query iSCSI target

 # tgt-admin -s
Target 1: iqn.2015-01.com.fibrevillage.pps11:pps11.target1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 8001581 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/mapper/ddnlun1
            Backing store flags:
    Account information:
    ACL information:
        ALL

More advanced parameters setting

Specify lun id instead of using auto assignment, add the following line in the targets.conf file for the target

lun 2

Also, you can add parameters such as

vendor info, product info etc..

Here is a small example:

default-driver iscsi

<target iqn.2015-01.fibrevillage.pps11:pps11.target1>
    backing-store /dev/mapper/ddnlun1
lun 2
write-cache off
scsi_sn 0D6212C60100000
vendor_id fibrevillage
product_id iscsi-soft
product_rev 1.0
</target>

 

More parameters you can find in default /etc/tgt/targets.conf,

#iSNSServerIP 192.168.111.222
#iSNSServerPort 3205
#iSNSAccessControl On
#iSNS On
    # Some more parameters which can be specified locally or globally:
    #scsi_id ...
    #scsi_sn ...
    #vendor_id ...
    #product_id ...
    #product_rev ...
    #sense_format ...
    #removable ...
    #online ...
    #readonly [1 | 0] - 1 means readonly and 0 is read-write
    #path ...
    #mode_page 8:0:18:0x10:0:0xff....
    #mode_page 8:0:18:0x10:0:0xff....
    #device-type ...
    #bs-type ...        # backing store type - default rdwr, can be aio, mmap, etc...
    #allow-in-use yes   # if specified globally, can't be overwritten locally
...

For example, on iscsi client, you can see the output of the iscsi target device

# lsscsi
[6:0:0:0]    storage IET      Controller       0001  -       
[6:0:0:2]    disk    Fibrevil iscsi-soft       1.0   /dev/sdbf