Back To Basics

Linux – Configure iSCSI Initiator

This blog is not to explain what is iSCSI but rather a reference to steps which an administrator should follow for configuring iSCSI on their Linux host (CentOS in my case)

Prerequisites

  1. Make sure Linux host has IP connectivity to storage appliance which is acting as iSCSI target
  2. Storage appliance has iSCSI configured and service is running

Steps

Install iSCSI initiator on Linux host. Below is the example

# yum install iscsi-initiator-utils
Loaded plugins: ulninfo
Resolving Dependencies
--> Running transaction check
---> Package iscsi-initiator-utils.x86_64 0:6.2.0.874-11.0.1.el7 will be installed
--> Processing Dependency: iscsi-initiator-utils-iscsiuio >= 6.2.0.874-11.0.1.el7 for package: iscsi-initiator-utils-6.2.0.874-11.0.1.el7.x86_64
--> Running transaction check
---> Package iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-11.0.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================
 Package                                          Arch                     Version                                  Repository                    Size
=======================================================================================================================================================
Installing:
 iscsi-initiator-utils                            x86_64                   6.2.0.874-11.0.1.el7                     ol7_latest                   428 k
Installing for dependencies:
 iscsi-initiator-utils-iscsiuio                   x86_64                   6.2.0.874-11.0.1.el7                     ol7_latest                    93 k

Transaction Summary
=======================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 521 k
Installed size: 2.6 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): iscsi-initiator-utils-6.2.0.874-11.0.1.el7.x86_64.rpm                                                                    | 428 kB  00:00:00
(2/2): iscsi-initiator-utils-iscsiuio-6.2.0.874-11.0.1.el7.x86_64.rpm                                                           |  93 kB  00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                  1.1 MB/s | 521 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iscsi-initiator-utils-iscsiuio-6.2.0.874-11.0.1.el7.x86_64                                                                          1/2
  Installing : iscsi-initiator-utils-6.2.0.874-11.0.1.el7.x86_64                                                                                   2/2
  Verifying  : iscsi-initiator-utils-6.2.0.874-11.0.1.el7.x86_64                                                                                   1/2
  Verifying  : iscsi-initiator-utils-iscsiuio-6.2.0.874-11.0.1.el7.x86_64                                                                          2/2

Installed:
  iscsi-initiator-utils.x86_64 0:6.2.0.874-11.0.1.el7

Dependency Installed:
  iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-11.0.1.el7

Complete!

Once iSCSI package is installed then edit the iSCSI configuration file and enable node.startup = automatic. You will need to find node.startup in the config file and remove the # from start of the line. This will make sure that iSCSI is logging to target automatically on startup

vi /etc/iscsi/iscsid.conf

node.startup = automatic

Now configure the iSCSI service to start automatically. Run below command

# systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.

Start iSCSI service

# systemctl start iscsid

Now at this point you’ve iSCSI enabled on your Linux server. If you want to view iSCSI initiator name of your server then run below command. Note that in most cases iSCSI initiator name will reflect into logged in initiators on your storage appliance in some cases you’ll need to provide the initiator name.

# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1988-12.com.oracle:b0ed4f9c9b9d

Now let’s discover iSCSI target nodes using your storage system iSCSI IP address.

# iscsiadm -m discovery -t st -p 172.16.1.11
172.16.1.11:3260,2 iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2
172.16.1.12:3260,1 iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2

You can run below commands to list discovered iSCSI nodes

# iscsiadm -m node
172.16.1.11:3260,2 iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2
172.16.1.12:3260,1 iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2

or 

# ls /var/lib/iscsi/send_targets
172.16.1.11,3260

# ls /var/lib/iscsi/nodes
iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2
iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2

Once iSCSI nodes are discovered you can run below command to login into iSCSI target

# iscsiadm -m node --targetname "iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2" --portal "172.16.1.11:3260" --login
Logging in to [iface: default, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2, portal: 172.16.1.11,3260] (multiple)
Login to [iface: default, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2, portal: 172.16.1.11,3260] successful.

# iscsiadm -m node --targetname "iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2" --portal "172.16.1.12:3260" --login
Logging in to [iface: default, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2, portal: 172.16.1.12,3260] (multiple)
Login to [iface: default, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2, portal: 172.16.1.12,3260] successful.

At this stage you’ve Linux host configured as iSCSI initiator and logged in successfully to target storage. Now you can ask storage admin to create LUNs and assign to Linux host.

Once LUNs are assigned to Linux host you can run below command to scan new devices

# iscsiadm -m session --rescan
Rescanning session [sid: 1, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.a2, portal: 172.16.1.11,3260]
Rescanning session [sid: 2, target: iqn.1992-04.com.emc:cx.asfnsdbgfkdjfgdk.b2, portal: 172.16.1.12,3260]

You can view new devices using fdisk -l or multipath -l command

Categories: Back To Basics

Tagged as: , ,

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s