iSCSI Storage Configuration Using Iscsiadm Command



In this article I would try to explain iscsi storage configuration on linux distro. We will first need iscsi initiator installed , that will use iscsi commands to communicate with the iscsi storage. What I would care more on this article , is to understand usage is iscsi commands to access / manage storage. First requirement is to install iscsi package and you can use open iscsi from open iscsi or you try installing using yum.

[[email protected] ~]# yum install iscsi-initiator-utils
Query iscsi-initiator package installed or not

[[email protected] ~]# rpm -qa | grep -i iscsi
[[email protected] ~]#

Keep note of iscsi intiator name

[[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi
[[email protected] ~]#

Start the Iscsi service.

[[email protected] ~]# service iscsi start
By default, the newly added iscsi initiator is not enabled at boot, which is the reason for each of the run levels listed to have the service set to off. To enable this at boot, again use the chkconfig command as follows.

[[email protected] ~]# chkconfig –-add iscsi
[[email protected] ~]# chkconfig iscsi on

Log into all targets

[[email protected] ifaces]# iscsiadm –m node –l
To see the connection status

[email protected] ifaces]# iscsiadm -m session
Login individual target

You can also Log into an individual target as below. You might see multiple iface because I have configured multipathing.

[[email protected] ifaces]# iscsiadm -m node -l -T -l -p
Logging in to [iface: default, target:, portal:,3260] (multiple)
Login to [iface: default, target:, portal:,3260] successful.
[[email protected] ifaces]#

Logging out all targets.

[[email protected] ifaces]# iscsiadm –m node –u
Logging off an individual target.

Shown an example below

iscsiadm –m node –u –T –p <Group IP address>:3260
Find device name

Find the newly created device name, using the iscsiadm command. In this test configuration, the new volume is /dev/sdb. At the end of the output you could see attached scsi disk name.

[[email protected] ifaces]# iscsiadm -m session -P3
Dev Mapper device name

You can find the device name in /dev/mapper directory. I have configured multipath so you could see alias name as "centos_storage_node1". We could cover multipath configuration in another article.

[[email protected] ifaces]# ls /dev/mapper/centos_*

Create physical volume

Now from here its more simple. Creating physical volume

[[email protected] ifaces]# pvcreate /dev/mapper/centos_storage_node1
  Physical volume "/dev/mapper/centos_storage_node1" successfully created
[[email protected] ifaces]#

Creating a volume group

[[email protected] ifaces]# vgcreate vg01 /dev/mapper/centos_storage_node1
  Volume group "vg01" successfully created
[[email protected] ifaces]#

Creating logical volume

[[email protected] /]# lvcreate -L 9G -n data vg01
  Logical volume "data" created
[[email protected] /]#

Display logical volume

[[email protected] /]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg01/data
  LV Name                data
  VG Name                vg01
  LV UUID                dHGUcq-Smy9-4QuL-EW9e-mo7a-SLtE-ea2ySm
  LV Write Access        read/write
  LV Creation host, time centos-cluster-node1.local, 2013-05-22 09:16:57 -0400
  LV Status              available
  # open                0
  LV Size                9.00 GiB
  Current LE            2304
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:3
[[email protected] /]#

Filesystem creation

Now you are ready for creating a file system with journaling mode enabled

[[email protected] /]# mke2fs –j /dev/vg01/data
If you are using storage clustering try below gfs filesystem

[[email protected] /]# mkfs.gfs2 -p lock_dlm -t cluster-centos:database -j 8 /dev/vg01/data
This will destroy any data on /dev/vg01/data.
It appears to contain: symbolic link to `../dm-3'

Are you sure you want to proceed? [y/n]

Device:                    /dev/vg01/data
Blocksize:                4096
Device Size                9.00 GB (2359296 blocks)
Filesystem Size:          9.00 GB (2359294 blocks)
Journals:                  8
Resource Groups:          36
Locking Protocol:          "lock_dlm"
Lock Table:                "cluster-centos:database"
UUID:                      f05156fa-cdf3-eaab-cda9-74c2d73d931a
[[email protected] /]#

Some useful iscsiadm options

Delete session records

To manually delete the records sessions -o delete option. Be sure to enter the appropriate iscsi targetname

iscsiadm –o delete
Rescan lun

When you expand the volume or disk, you might need to rescan. So the below command will help.

iscsiadm -m node -p --rescan


Last edited:

$100 Digital Ocean Credit
Get a free VM to test out Linux!