From Segfault
Jump to navigation Jump to search



All major Linux distributions switched to LIO now and should have the targetcli-fb package available.[1]

apt-get install targetcli-fb                                                               # Debian, Ubuntu
dnf install targetcli                                                                      # Fedora
emerge sys-block/?                                                                         # Gentoo

The targetcli utility must can be used to create and configure our target in an interactive dialog.[2][3] Once configured, the actual configuration file is then saved to /etc/target (resp. /etc/rtslib-fb-target in Debian), which can be looked at, but shoud not be edited.

Let's create a simple target:

/> cd backstores/fileio
/backstores/fileio> create disk0 /var/tmp/disk0.img
Created fileio disk0 with size 1073741824
/backstores/fileio> cd /iscsi
/iscsi> create                             # iSCSI Qualified Name according to RFC 3720
Created target
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (, port 3260.

Adjust the portal address if needed:

/iscsi> cd
/iscsi/iqn.20.../tpg1/portals> delete 3260 
Deleted network portal

/iscsi/iqn.20.../tpg1/portals> create ip_address= ip_port=3260
Using default IP port 3260
Created network portal

Create a LUN:

/iscsi/iqn.20...xample:0/tpg1> cd ../luns
/iscsi/iqn.20...e:0/tpg1/luns> create /backstores/fileio/disk0
Created LUN 0.

Create a default ACL, for the initiator from /etc/iscsi/initiatorname.iscsi:

/iscsi/iqn.20...e:0/tpg1/luns> cd ../acls
/iscsi/iqn.20...e:0/tpg1/acls> create
Created Node ACL for
Created mapped LUN 0.

Exiting the configuration tool will save the configuration. Once an initiator is connected, we can see its session too:

/> sessions
alias: fedora    sid: 1 type: Normal session-state: LOGGED_IN

Adding (and removing) new disks can be summarized as:

/> /backstores/fileio/ create disk3 /var/tmp/disk3.img
/> /iscsi create

/> /iscsi/ delete 3260                        # Only if needed!
/> /iscsi/ create ip_address= ip_port=3260   # Only if needed!

/> /iscsi/ create /backstores/fileio/disk3

/> /iscsi/ create


Contrary to targetcli-fb above, tgt can be used to set up an iSCSI target in user space.



NetBSD has iscsi-target that can be configured[4] as follows.




The initiator has been implemented via the open-iscsi tools in Linux - install as needed:

apt-get install open-iscsi                                                                 # Debian, Ubuntu
dnf install iscsi-initiator-utils                                                          # Fedora

Our own InitiatorName[5][6] can be obtained via:

$ grep ^I /etc/iscsi/initiatorname.iscsi

Or generated via:

$ iscsi-iname -p iqn.$(date +%Y-%m).org.$(uname -n)

The syntax for iscsiadm is quite complicated, so let's show a few examples.

Discover existing targets via the portal interface:

$ iscsiadm -m discovery -t sendtargets -p localhost,1

Once discovered, it will show up via discoverydb:

$ iscsiadm -m discoverydb -o show
localhost:3260 via sendtargets

Login to the target discovered above:

$ iscsiadm -m node -T --login
Logging in to [iface: default, target:, portal:,3260] (multiple)
Login to      [iface: default, target:, portal:,3260] successful.

With that a new device should be present on our machine:

lsblk --scsi
sdb  1:0:0:0    disk LIO-ORG  disk0            4.0  iscsi
$ dmesg -t | tail 
iscsi: registered transport (iser)
scsi host7: iSCSI Initiator over TCP/IP
scsi 7:0:0:0: Direct-Access     LIO-ORG  disk0         4.0  PQ: 0 ANSI: 5
sd 7:0:0:0: Attached scsi generic sg1 type 0
sd 7:0:0:0: [sda] 3906521088 512-byte logical blocks: (2.00 TB/1.82 TiB)
sd 7:0:0:0: [sda] Write Protect is off
sd 7:0:0:0: [sda] Mode Sense: 43 00 10 08
sd 7:0:0:0: [sda] Write cache: enabled, read cache: enabled, supports DPO and FUA
sd 7:0:0:0: [sda] Optimal transfer size 2048 logical blocks > dev_max (256 logical blocks)
sd 7:0:0:0: [sda] Attached SCSI disk

List active session entries:

$ iscsiadm -m session 
tcp: [3],1 (non-flash)

Logout from a particular node:

$ iscsiadm -m node -T --logout
Logging out of session [sid: 3, target:, portal:,3260]
Logout of              [sid: 3, target:, portal:,3260] successful.

While the session has been logged out from, it can still be found in discoverydb:

$ iscsiadm -m discoverydb
localhost:3260 via sendtargets

To remove this entry:

iscsiadm -m discoverydb -t sendtargets -p localhost:3260 -o delete



On NetBSD the initiator can be configured via iscsictl.

Enable the initiator and start it:

$ grep iscsi /etc/rc.conf

$ /etc/rc.d/iscsid start

Add a target:

$ iscsictl add_send_target -a localhost:3260
Added Send Target 1

List targets:

$ iscsictl refresh_targets

$ iscsictl list_targets

Login to the target:

$ iscsictl login -P 1
iscsictl: login: The login failed

We haven't created an ACL on the target yet:

kernel: iSCSI Initiator Node: is not authorized to access iSCSI target portal group: 1.
kernel: iSCSI Login negotiation failed.

Once the ACL has been configured, we can try again:

$ iscsictl login -P 1
Created Session 3, Connection 1

$ dmesg
scsibus0 at iscsi0: 1 target, 16 luns per target
sd0 at scsibus0 target 0 lun 0: <LIO-ORG, disk0, 4.0> disk fixed
sd0: fabricating a geometry
sd0: 1024 MB, 1024 cyl, 64 head, 32 sec, 512 bytes/sect x 2097152 sectors
sd0: fabricating a geometry
sd0: async, 8-bit transfers, tagged queueing

List sessions:

$ iscsictl list_sessions
Session 3: Target

And logout again:

$ iscsictl logout -I 3

$ iscsictl list_sessions
iscsictl: list_sessions: The list is empty


FreeBSD carries iscsictl as well, albeit with a different syntax:

iscsictl -A -p -t

Our own InitiatorName is still set to its default, but we can simplify our initiator setup with iscsi.conf:

$ cat /etc/iscsi.conf
foobar {
       targetaddress   =;
       targetname      = "";
       initiatorname   = "";

Login with:

$ iscsictl -A -n foobar
$ iscsictl -L
Target name                          Target portal    State           Connected: da0 da1 da2 da3




Newer Windows versions can configure initiators via %systemroot%\System32\iscsicpl.exe.[7]