Configuring the server (target) using LIO
# aptitude install targetcli-fb
This installs the command targetcli and associated python scripts.
The command can be used in two ways:
- To enter a special semi-graphical "targetcli" shell, and issue sub-commands inside it
- By prefixing all required commands with "targetcli", which makes it possible to use it from a script
Example:
# targetcli ls o- / ......................................................................... [...] o- backstores .............................................................. [...] | o- block .................................................. [Storage Objects: 1] | | o- iscsivolume1 ..................... [/dev/md5 (8.1TiB) write-thru activated] | | o- alua ................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................... [ALUA state: Active/optimized] | o- fileio ................................................. [Storage Objects: 0] | o- pscsi .................................................. [Storage Objects: 0] | o- ramdisk ................................................ [Storage Objects: 0] o- iscsi ............................................................ [Targets: 1] | o- iqn.2020-09.network.hostname:share ................................ [TPGs: 1] | o- tpg1 ............................................... [no-gen-acls, no-auth] | o- acls .......................................................... [ACLs: 2] | | o- iqn.1993-08.org.debian:01:81ab2ca5ba15 ............... [Mapped LUNs: 1] | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | | o- iqn.2020-09.network.clientname:openiscsi ............. [Mapped LUNs: 1] | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | o- luns .......................................................... [LUNs: 1] | | o- lun0 ............... [block/iscsivolume1 (/dev/md5) (default_tg_pt_gp)] | o- portals .................................................... [Portals: 1] | o- 0.0.0.0:3260 ..................................................... [OK] o- loopback ......................................................... [Targets: 0] o- vhost ............................................................ [Targets: 0] o- xen-pvscsi ....................................................... [Targets: 0]
This shows that I am sharing an 8.1 Tbyte device named /dev/md5 under the name iqn.2020-09.network.hostname:share and this is accessible from two clients iqn.1993-08.org.debian:01:81ab2ca5ba15 and iqn.2020-09.network.clientname:openiscsi.
Example
I want to share the Logical Volume /dev/SCSItarget/share to any machine on my local network 192.168.42.0/24
Pseudo-shell
Here are the first steps shown in the semi-graphical pseudo-shell:
# targetcli targetcli shell version 2.1.fb48 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd /backstores/block /backstores/block> create iscsivolume2 /dev/SCSItarget/share Created block storage object iscsivolume2 using /dev/SCSItarget/share. /backstores/block> cd /iscsi /iscsi> create iqn.2021-01.network.hostname:bigshare Created target iqn.2021-01.network.hostname:bigshare. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi> cd iqn.2021-01.network.hostname:bigshare/tpg1/luns /iscsi/iqn.20...tec/tpg1/luns> create /backstores/block/iscsivolume2 Created LUN 0. /iscsi/iqn.20...tec/tpg1/luns> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/rtslib-fb-target/backup. Configuration saved to /etc/rtslib-fb-target/saveconfig.json
At the end of this, we have:
# targetcli ls o- / ......................................................................... [...] o- backstores .............................................................. [...] | o- block .................................................. [Storage Objects: 2] | | o- iscsivolume1 ..................... [/dev/md5 (8.1TiB) write-thru activated] | | | o- alua ................................................... [ALUA Groups: 1] | | | o- default_tg_pt_gp ....................... [ALUA state: Active/optimized] | | o- iscsivolume2 ....... [/dev/SCSItarget/share (13.6TiB) write-thru activated] | | o- alua ................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................... [ALUA state: Active/optimized] | o- fileio ................................................. [Storage Objects: 0] | o- pscsi .................................................. [Storage Objects: 0] | o- ramdisk ................................................ [Storage Objects: 0] o- iscsi ............................................................ [Targets: 2] | o- iqn.2020-09.network.hostname:share ................................ [TPGs: 1] | | o- tpg1 ............................................... [no-gen-acls, no-auth] | | o- acls .......................................................... [ACLs: 2] | | | o- iqn.1993-08.org.debian:01:81ab2ca5ba15 ............... [Mapped LUNs: 1] | | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | | | o- iqn.2020-09.network.clientname:openiscsi ............. [Mapped LUNs: 1] | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | | o- luns .......................................................... [LUNs: 1] | | | o- lun0 ............... [block/iscsivolume1 (/dev/md5) (default_tg_pt_gp)] | | o- portals .................................................... [Portals: 1] | | o- 0.0.0.0:3260 ..................................................... [OK] | o- iqn.2021-01.network.hostname:bigshare ............................. [TPGs: 1] | o- tpg1 ............................................... [no-gen-acls, no-auth] | o- acls .......................................................... [ACLs: 0] | o- luns .......................................................... [LUNs: 1] | | o- lun0 .. [block/iscsivolume2 (/dev/SCSItarget/share) (default_tg_pt_gp)] | o- portals .................................................... [Portals: 1] | o- 0.0.0.0:3260 ..................................................... [OK] o- loopback ......................................................... [Targets: 0] o- vhost ............................................................ [Targets: 0] o- xen-pvscsi ....................................................... [Targets: 0]
Standard command-line
Personally I find that sort of thing pretty tedious, so here's the scripted way of doing it, including adding the ACLs to allow the same clients to access the new share:
# targetcli /backstores/block create iscsivolume2 /dev/SCSItarget/share Created block storage object iscsivolume2 using /dev/SCSItarget/share. # targetcli /iscsi create iqn.2021-01.network.hostname:bigshare Created target iqn.2021-01.network.hostname:bigshare. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. # targetcli /iscsi/iqn.2021-01.network.hostname:bigshare/tpg1/luns create /backstores/block/iscsivolume2 Created LUN 0. # targetcli /iscsi/iqn.2021-01.network.hostname:bigshare/tpg1/acls/ create iqn.1993-08.org.debian:01:81ab2ca5ba15 Created Node ACL for iqn.1993-08.org.debian:01:81ab2ca5ba15 Created mapped LUN 0. # targetcli /iscsi/iqn.2021-01.network.hostname:bigshare/tpg1/acls/ create iqn.2020-09.network.clientname:openiscsi Created Node ACL for iqn.2020-09.network.clientname:openiscsi Created mapped LUN 0. # targetcli saveconfig Last 10 configs saved in /etc/rtslib-fb-target/backup/. Configuration saved to /etc/rtslib-fb-target/saveconfig.json
The result of the above commands is then:
# targetcli ls o- / ......................................................................... [...] o- backstores .............................................................. [...] | o- block .................................................. [Storage Objects: 2] | | o- iscsivolume1 ..................... [/dev/md5 (8.1TiB) write-thru activated] | | | o- alua ................................................... [ALUA Groups: 1] | | | o- default_tg_pt_gp ....................... [ALUA state: Active/optimized] | | o- iscsivolume2 ....... [/dev/SCSItarget/share (13.6TiB) write-thru activated] | | o- alua ................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ....................... [ALUA state: Active/optimized] | o- fileio ................................................. [Storage Objects: 0] | o- pscsi .................................................. [Storage Objects: 0] | o- ramdisk ................................................ [Storage Objects: 0] o- iscsi ............................................................ [Targets: 2] | o- iqn.2020-09.network.hostname:share ................................ [TPGs: 1] | | o- tpg1 ............................................... [no-gen-acls, no-auth] | | o- acls .......................................................... [ACLs: 2] | | | o- iqn.1993-08.org.debian:01:81ab2ca5ba15 ............... [Mapped LUNs: 1] | | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | | | o- iqn.2020-09.network.clientname:openiscsi ............. [Mapped LUNs: 1] | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume1 (rw)] | | o- luns .......................................................... [LUNs: 1] | | | o- lun0 ............... [block/iscsivolume1 (/dev/md5) (default_tg_pt_gp)] | | o- portals .................................................... [Portals: 1] | | o- 0.0.0.0:3260 ..................................................... [OK] | o- iqn.2021-01.network.hostname:bigshare ............................. [TPGs: 1] | o- tpg1 ............................................... [no-gen-acls, no-auth] | o- acls .......................................................... [ACLs: 2] | | o- iqn.1993-08.org.debian:01:81ab2ca5ba15 ............... [Mapped LUNs: 1] | | | o- mapped_lun0 .......................... [lun0 block/iscsivolume2 (rw)] | | o- iqn.2020-09.network.clientname:openiscsi ............. [Mapped LUNs: 1] | | o- mapped_lun0 .......................... [lun0 block/iscsivolume2 (rw)] | o- luns .......................................................... [LUNs: 1] | | o- lun0 .. [block/iscsivolume2 (/dev/SCSItarget/share) (default_tg_pt_gp)] | o- portals .................................................... [Portals: 1] | o- 0.0.0.0:3260 ..................................................... [OK] o- loopback ......................................................... [Targets: 0] o- vhost ............................................................ [Targets: 0] o- xen-pvscsi ....................................................... [Targets: 0]
Either way
Take your pick whether you prefer the pseudo-shell environment or the scriptable command-line method, but the significant commands from the above are:
- /backstores/block create iscsivolume2 /dev/SCSItarget/share
- defines the device to be shared
- /iscsi create iqn.2021-01.network.hostname:bigshare
- gives it a name to be connected to
- /iscsi/iqn.2021-01.network.hostname:bigshare/tpg1/luns create /backstores/block/iscsivolume2
- associates the name with the device
- /iscsi/iqn.2021-01.network.hostname:bigshare/tpg1/acls/ create iqn.2020-09.network.clientname:openiscsi
- allows the client/s to connect
You can then connect to the new share from the client.
Status
For reasons which are beyond me, the standard startup script /etc/init.d/iscsi-target (or, in later releases, the spectacularly unmemorable and non-obviously-named /etc/init.d/rtslib-fb-targetctl) supports a status parameter, the effect of which is to print out Not supported!.
Somebody actually went to the bother of providing a status command which is totally pointless, when a useful version is so simple.
Edit whichever version of the startup script is on your machine and replace the following line:
echo "Not supported!"
with:
targetcli ls targetcli sessions detail
Now the status command will tell you what this machine is making available, and which other machines are currently connected to it.
Note to package maintainer: Now, that wasn't so hard, was it?
Go up
Return to main index.