Manage Learn to apply best practices and optimize your operations.

Create a SAN with the Linux LIO iSCSI target

With the LIO iSCSI target service, Linux shops have an affordable SAN option that ranks up there with expensive proprietary storage solutions.

The LIO iSCSI target service and targetcli command enable any Linux data center to set up an iSCSI storage area...

network without a large investment.

Both Red Hat Enterprise Linux (RHEL) 7 and SUSE Linux Enterprise Server (SLES) 12 use the Linux-IO (LIO) iSCSI target to create an iSCSI storage area network (SAN). An iSCSI SAN connects clients and targets over Internet Protocol networks.

You will need the targetcli shell and LIO packages to set up an iSCSI SAN. In the targetcli shell, you can work with common Linux commands, such as ls and set. Use ls to see an overview of the current configuration (See listing 1). This tells you the available backing storage devices where you can create an iSCSI logical unit number (LUN).

Listing 1. The command ls pulls up a storage configuration overview on SLES and RHEL servers.

/> ls

o- / ....................................................................................[...]

  o- backstores .........................................................................[...]

  | o- block .............................................................[Storage Objects: 0]

  | o- fileio ............................................................[Storage Objects: 0]

  | o- pscsi .............................................................[Storage Objects: 0]

  | o- ramdisk ...........................................................[Storage Objects: 0]

  o- iscsi .......................................................................[Targets: 0]

  o- loopback ....................................................................[Targets: 0]

The LIO iSCSI target provides access to various storage devices. Use block when reaching a block device, such as an LVM logical volume. Use fileio to create a file of a specific size, or pscsi to work with a physical SCSI device. Use ramdisk to access a RAM device. All data stored in a RAM will be lost when the server reboots.

To create a device, use cd backstores to get in the appropriate branch and then add the devices. From the backstores branch, type block/ create block1 /dev/vgdisk/lviscsi1 to create an iSCSI block device with the name block1. The underlying block device must already exist in order to create a block.

To create a fileio device, use fileio/ create file1 /root/iscsidisk1 100M. When using a file device, the underlying image file is created on the spot.

Listing 2. Learn these commands when setting up a Linux-based iSCSI SAN.

/backstores> block/ create block1 /dev/vgdisk/lviscsi1

Created block storage object block1 using /dev/vgdisk/lviscsi1.

/backstores> block/ create block2 /dev/vgdisk/lviscsi2

Created block storage object block2 using /dev/vgdisk/lviscsi2.

/backstores> fileio/ create file1 /root/iscsidisk1 100M

Created fileio file1 with size 104857600

/backstores> ls

o- backstores ........................................................................... [...]

  o- block ...............................................................[Storage Objects: 2]

  | o- block1 ........................[/dev/vgdisk/lviscsi1 (100.0MiB) write-thru deactivated]

  | o- block2 ........................[/dev/vgdisk/lviscsi2 (100.0MiB) write-thru deactivated]

  o- fileio ..............................................................[Storage Objects: 1]

  | o- file1 .............................[/root/iscsidisk1 (100.0MiB) write-back deactivated]

  o- pscsi ...............................................................[Storage Objects: 0]

  o- ramdisk .............................................................[Storage Objects: 0]

After establishing the devices, create an iSCSI target. Go to the /iscsi branch and then use the create command. While creating the target, specify its iSCSI Qualified Name (IQN), as well as the target identifier (Listing 3).

Listing 3. To create an LIO iSCSI target, use the commands in this list.

/backstores> cd /iscsi

/iscsi> create iqn.2014-07.com.rhatcert:iscsidisk

Created target iqn.2014-07.com.rhatcert:iscsidisk.

Created TPG 1.

/iscsi> ls

o- iscsi ......................................................................... [Targets: 1]

  o- iqn.2014-07.com.rhatcert:iscsidisk ............................................. [TPGs: 1]

    o- tpg1 ............................................................ [no-gen-acls, no-auth]

      o- acls ....................................................................... [ACLs: 0]

      o- luns ....................................................................... [LUNs: 0]

      o- portals ................................................................. [Portals: 0]

/iscsi>

This command establishes the iSCSI target device with the name tgp1. Here, you can specify an access control list (ACL) to tie the target to specific iSCSI clients. The name "tpg" comes from Target Portal Group -- the collection of IP addresses and ports to which the target listens. In the ACL, which can be assigned to each TPG, the client is referred to by its IQN, which needs to be configured before the client can access the target (Listing 4).

Listing 4. Use these commands to set up an access control list.

/iscsi> cd iqn.2014-07.com.rhatcert:iscsidisk/

/iscsi/iqn.20...ert:iscsidisk> cd tpg1

/iscsi/iqn.20...scsidisk/tpg1> acls/ create iqn.2014-07.com.rhatcert:server1

Created Node ACL for iqn.2014-07.com.rhatcert:server1

/iscsi/iqn.20...scsidisk/tpg1>

You still have to create and activate LUNs for each new backstore. Because an ACL already exists for the TPG, it will automatically be assigned to each new LUN (Listing 5).

Listing 5. An ACL is automatically assigned when you create LUNs for the LIO backstores.

/iscsi/iqn.20...scsidisk/tpg1> luns/ create /backstores/block/block1

Created LUN 0.

Created LUN 0->0 mapping in node ACL iqn.2014-07.com.rhatcert:server1

/iscsi/iqn.20...scsidisk/tpg1> luns/ create /backstores/block/block2

Created LUN 1.

Created LUN 1->1 mapping in node ACL iqn.2014-07.com.rhatcert:server1

/iscsi/iqn.20...scsidisk/tpg1> luns/ create /backstores/fileio/file1

Created LUN 2.

Created LUN 2->2 mapping in node ACL iqn.2014-07.com.rhatcert:server1

To complete the SAN setup, specify a portal to indicate on which IP address the LIO target should be available (Listing 6).

Listing 6. Create the portal for the iSCSI SAN from the targetcli.

/iscsi/iqn.20...scsidisk/tpg1> portals/ create 192.168.4.181

Using default IP port 3260

Created network portal 192.168.4.181:3260.

/iscsi/iqn.20...scsidisk/tpg1> ls

o- tpg1 ................................................................[no-gen-acls, no-auth]

  o- acls ........................................................................... [ACLs: 1]

  | o- iqn.2014-07.com.rhatcert:server1 ......................................[Mapped LUNs: 3]

  |   o- mapped_lun0 .................................................[lun0 block/block1 (rw)]

  |   o- mapped_lun1 .................................................[lun1 block/block2 (rw)]

  |   o- mapped_lun2 .................................................[lun2 fileio/file1 (rw)]

  o- luns ........................................................................... [LUNs: 3]

  | o- lun0 ............................................. [block/block1 (/dev/vgdisk/lviscsi1)]

  | o- lun1 ............................................. [block/block2 (/dev/vgdisk/lviscsi2)]

  | o- lun2 ................................................. [fileio/file1 (/root/iscsidisk1)]

  o- portals ..................................................................... [Portals: 1]

    o- 192.168.4.181:3260 ................................................................ [OK]

/iscsi/iqn.20...scsidisk/tpg1>

Quit the interface with the exit command, and write the configuration. The configuration writes to the file /etc/target/saveconfig.json. Don't edit this file directly; use the targetcli command to apply any modifications necessary. 

Next Steps

FC, iSCSI or NAS?

Comparing iSCSI and NFS for vSphere

Learn more about configuring iSCSI storage for SLES

This was last published in October 2014

Dig Deeper on Linux servers

PRO+

Content

Find more PRO+ content and other member only offers, here.

Join the conversation

2 comments

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

Trying this on SLES12 and finding it quite inadequate to create a persistent config. After two days of searching and attempts at getting it going, this is very frustrating.

Any special insights for SLES12? the YaST module also fails to produce a working configuration.
Cancel
Just realized my issue. The initiator name must match the acl on the target with what SLES assigns it to be.

So instead of a simple fqdn or hostname, for each initiator it looks like this:

iqn.1996-04.de.suse:01:14949226XXXX

Found this tidbit in the docs:

The Initiator Name is automatically completed with the corresponding value from the /etc/iscsi/initiatorname.iscsi file on the server.

That was the last bit I needed to get it running.
Cancel

-ADS BY GOOGLE

SearchWindowsServer

SearchServerVirtualization

SearchCloudComputing

Close