Using LIO_Utils to create an iSCSI storage server

openSUSE / SLES is probably one of the best choices for a Linux Storage appliance. In this tutorial I will demonstrate how to use the built-in (LIO) iSCSI target and access block devices exported via iSCSI.



Although openSUSE comes with Yast which is by far the best UI for system administration in the Linux world, one can always use the CLI to achieve anything on the server.
Besides that, one must always consider that there is a user space tool for managing iSCSI target with LIO called targetcli. See this article.

I will start the target, create LUNs, map LUNs, export them and access them from a client machine.
The system used is:

linux-7f15:/ # cat /etc/os-release
NAME=openSUSE
VERSION="13.2 (Harlequin)"
VERSION_ID="13.2"
PRETTY_NAME="openSUSE 13.2 (Harlequin) (x86_64)"
ID=opensuse
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:opensuse:13.2"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://opensuse.org/"
ID_LIKE="suse"

To start the target:

linux-7f15:/ # systemctl start target

One can use disk devices (/dev/sdb for instance) or create files which will be used as block devices (Neatpp LUNs for example are such files, zfs based systems use the same to create LUNs)

Will use /luns to create LUNs with LIO_utils
linux-7f15:/ # mkdir /luns

Create a target: 

linux-7f15:/ # lio_node --addtpg=iqn.test-target.0001.786-67875-test 2
linux-7f15:/ # lio_node --listendpoints
\------> iqn.test-target.0001.786-67875-test
\-------> tpgt_2 TargetAlias: LIO Target
TPG Status: DISABLED
TPG Network Portals:
TPG Logical Units:

'iqn.test-target.0001.786-67875-test' is just a name I generated for my IQN, 2 is the Target Portal Group I defined, which will be translated into tpgt_2.

Add a network portal to allow incoming connections over 3260, and bind one (or all) IPs:

linux-7f15:/ # lio_node --addnp=iqn.test-target.0001.786-67875-test 2 172.21.11.81:3260

linux-7f15:/ # lio_node --listendpoints
\------> iqn.test-target.0001.786-67875-test
\-------> tpgt_2 TargetAlias: LIO Target
TPG Status: DISABLED
TPG Network Portals:
\-------> 172.21.11.86:3260
TPG Logical Units:

Enable the TPG:

linux-7f15:/ # lio_node --enabletpg=iqn.test-target.0001.786-67875-test 2
linux-7f15:/ # lio_node --listendpoints
\------> iqn.test-target.0001.786-67875-test
\-------> tpgt_2 TargetAlias: LIO Target
TPG Status: ENABLED
TPG Network Portals:
\-------> 172.21.11.86:3260
TPG Logical Units:

NOTE: the target alias can be changed like this:

linux-7f15:/ # echo "SUSE iSCSI Target" > /sys/kernel/config/target/iscsi/iqn.test-target.0001.786-67875-test/tpgt_2/param/TargetAlias
linux-7f15:/ # lio_node --listendpoints
\------> iqn.test-target.0001.786-67875-test
\-------> tpgt_2 TargetAlias: SUSE iSCSI Target
TPG Status: ENABLED
TPG Network Portals:
\-------> 172.21.11.86:3260
TPG Logical Units:


Create LUNs:

3 types of devices can be used as LUNs:
• File IO
• Block IO
• Raw SCSI disk
• RAMDISK

The tool used to create LUNs is tcm_node

The syntax is : --fileio=HBA/DEV <FILE> <SIZE_IN_BYTES>

linux-7f15:/ # tcm_node --fileio fileio_0/my_file0 /luns/my_lun0 1000000000
Status: DEACTIVATED Max Queue Depth: 0 SectorSize: 512 HwMaxSectors: 16384
TCM FILEIO ID: 0 File: /luns/my_lun0 Size: 1000000000 Mode: O_DSYNC

Display the LUN SN:

linux-7f15:/ # tcm_node --wwn fileio_0/my_file0
T10 VPD Unit Serial Number: 9e538618-f191-4a07-b6a9-76ea15be972e

Mapping the LUN:

Syntax:  --addlun=TARGET_IQN TPGT LUN PORT_ALIAS TCM_HBA/DEV

linux-7f15:/ # lio_node --addlun iqn.test-target.0001.786-67875-test 2 2 lun_2 fileio_0/my_file0
linux-7f15:/ # lio_node --listendpoints
\------> iqn.test-target.0001.786-67875-test
\-------> tpgt_2 TargetAlias: SUSE iSCSI Target
TPG Status: ENABLED
TPG Network Portals:
\-------> 172.21.11.81:3260
TPG Logical Units:
\-------> lun_2/lun_2 -> target/core/fileio_0/my_file0

Add the initiator to the Node's ACL to allow logins: 

linux-7f15:/ # lio_node --addnodeacl=iqn.2015-10.com.ovi:6430c7d2-ebe6-4dca-9d1b-ff8f38112a1c 1 iqn.2005-03.org.open-iscsi:c04e8f17af18
 NOTE: Can also be added per LUN using --addlunacl

<<On one server I HAD to add LUN acls before being able to discover the LUN by the innitiator>>

Disable authentication:

linux-7f15:/ # lio_node --disableauth iqn.test-target.0001.786-67875-test 2

Restart the iscsi target using systemctl restart target

Login from the client:

# iscsi_discovery 172.21.11.81 -l
iscsiadm: No active sessions.
Set target iqn.test-target.0001.786-67875-test to automatic login over tcp to portal 172.21.11.81:3260
discovered 1 targets at 172.21.11.81

The new LUN is now visible as a disk on my client. Multipath is not configured on the client, so I see it twice.

sdf 81:0:0:0 disk LIO-ORG FILEIO 4.0 iscsi
sdg 81:0:0:2 disk LIO-ORG FILEIO 4.0 iscsi

Save the current configuration:

linux-7f15:/ # tcm_dump --o

Backup the configuration:

linux-7f15:/ # tcm_dump --t <file name>

The backup file will be /etc/target/backup/tcm_backup-<file name>.sh