Examples of iscsiadm Command on Linux

Today In this article we will see how to discover iSCSI targets, login targets, logout targets, Delete targets from your iSCSI storage array using iscsiadm command.

The iscsiadm utility is a command-line tool allowing discovery and login to iSCSI targets, as well as access and management of the open-iscsi database.

As previous we have completed the scenario of installing iSCSI SAN Storage, refer the below link.

How to Build your Own Secure Storage Using iSCSI SAN Storage.

1) Discovering iSCSI Targets.

Note that many of the node and discovery operations require that the iSCSI daemon (iscsid) be running. It will use the ‘iscsiadm’ userspace utility to discover, login and logout iSCSI targets.

Get the list of available targets following command is used.

[root@dbserver ~]# iscsiadm -m discoverydb -t sendtargets -p 192.168.1.1:3260 -D
192.168.1.1:3260,1 iqn.2017-01.in.ittroubleshooter:wwn
[root@dbserver ~]#

#iscsiadm -m discoverydb -t sendtargets -p 192.168.1.1:3260 -D

Where,“iscsiadm” is open-iscsi administration utility.
“-m  (or –mode)discoverydb” It specify  the mode. Other possible modes are: discovery, node, fw, host iface or session.
“-t  (or –-type)sendtargets”  It specify  the type. Other possible type are: sendtargets(or abbreviated as st), fw, and iSNS.
“-p  (or –portal) <Group IP address>:3260” It specify the ip-address and port of target portal.If  port is not passed in the default port value is 3260.
“-D  (or –discover)” It will discover the targets using the discovery record with the discovery type(i.e sendtargets) and the discoverydb mode, portal passed in.

You also use the below command to Discover the iSCSI Targets.

[root@dbserver ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260
192.168.1.1:3260,1 iqn.2017-01.in.ittroubleshooter:wwn
[root@dbserver ~]#

2) Logging in iSCSI Targets session.

Once you have discovered your iSCSI targets, you need to login to the iSCSI target by using the following command;

[root@dbserver ~]# iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260] (multiple)
Login to [iface: default, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260] successful.
[root@dbserver ~]#

if you want to login an individual iSCSI target the following command;

[root@dbserver ~]# iscsiadm -m node -T iqn.2017-01.in.ittroubleshooter:wwn  -p 192.168.1.1:3260 -l
Logging in to [iface: default, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260] (multiple)
Login to [iface: default, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260] successful.
[root@dbserver ~]#

#iscsiadm -m node -T <Complete Target Name>  -p <Group IP>:3260 -l

Where,
“-l (or –login)” login for a specified record.

3) Browse the connection information.

If you want to browse the connection information about the target portal,connection and parameters used by the connected device, following command is used.

[root@dbserver ~]# iscsiadm -m session -P 3
iSCSI Transport Class version 2.0-870
version 6.2.0.873-21
Target: iqn.2017-01.in.ittroubleshooter:wwn (non-flash)
        Current Portal: 192.168.1.1:3260,1
        Persistent Portal: 192.168.1.1:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.2017-01.in.ittroubleshooter:allserveracl
                Iface IPaddress: 192.168.1.2
                Iface HWaddress: <empty>
                Iface Netdev: <empty>
                SID: 3
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE
                *********
                Timeouts:
                *********
                Recovery Timeout: 120
                Target Reset Timeout: 30
                LUN Reset Timeout: 30
                Abort Timeout: 15
                *****
                CHAP:
                *****
                username: <empty>
                password: ********
                username_in: <empty>
                password_in: ********
                ************************
                Negotiated iSCSI params:
                ************************
                HeaderDigest: None
                DataDigest: None
                MaxRecvDataSegmentLength: 262144
                MaxXmitDataSegmentLength: 262144
                FirstBurstLength: 65536
                MaxBurstLength: 262144
                ImmediateData: Yes
                InitialR2T: Yes
                MaxOutstandingR2T: 1
                ************************
                Attached SCSI devices:
                ************************
                Host Number: 5  State: running
                scsi5 Channel 00 Id 0 Lun: 0
                        Attached scsi disk sdb          State: running
                scsi5 Channel 00 Id 0 Lun: 1
                        Attached scsi disk sdc          State: running
                scsi5 Channel 00 Id 0 Lun: 2
                        Attached scsi disk sdd          State: running
[root@dbserver ~]#

#iscsiadm -m session [-P 0|1|2|3]  show information active sessions.

Where,
“-P N It is used to set the command detail level, with 3  specifying the most verbose output.

Note: The new iSCSI target records are saved on /var/lib/iscsi/nodes directory.

[root@dbserver ~]# cd /var/lib/iscsi/nodes/
[root@dbserver nodes]# ls
iqn.2017-01.in.ittroubleshooter:wwn
[root@dbserver nodes]#

4) Log out in iSCSI Targets session.

When we want to disconnect the iSCSI block device by logging out the iSCSI target, following command is used;

[root@dbserver ~]#  iscsiadm -m node -T iqn.2017-01.in.ittroubleshooter:wwn  -p 192.168.1.1:3260 -u
Logging out of session [sid: 4, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260]
Logout of [sid: 4, target: iqn.2017-01.in.ittroubleshooter:wwn, portal: 192.168.1.1,3260] successful.
[root@dbserver ~]#

#iscsiadm -m node -T iqn.2017-01.in.ittroubleshooter:wwn  -p 192.168.1.1:3260 -u

Where,
“-u (or –logout)” logout for a specified record.

You can also use other command to log out the iSCSI Targets session.
# iscsiadm -m node -l

Now check the records on /var/lib/iscsi/nodes directory. The records are still there.

[root@dbserver ~]# cd /var/lib/iscsi/nodes/
[root@dbserver nodes]# ls
iqn.2017-01.in.ittroubleshooter:wwn
[root@dbserver nodes]#

5) Delete the node records.

To delete the node records the following command is used;

[root@dbserver ~]#  iscsiadm -m node -T iqn.2017-01.in.ittroubleshooter:wwn  -p 192.168.1.1:3260 -o delete
[root@dbserver ~]#

# iscsiadm -m node -T iqn.2017-01.in.ittroubleshooter:wwn  -p 192.168.1.1:3260 -o delete

Now confirm that the node records on /var/lib/iscsi/nodes directory.

[root@dbserver ~]# cd /var/lib/iscsi/nodes/
[root@dbserver nodes]# ls
[root@dbserver nodes]#

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments and Stay tune for more updates with ittroubleshooter.in ..!!!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz