To setup an Iscsi initiator on Linux

To setup an Iscsi initiator on Linux

The instructions below were executed on Red Het E.L. 5.3 x86_64

0. Install scsi-target-utils
This comes with the DVD:

# rpm -i iscsi-initiator-utils-6.2.0.868-0.18.el5.x86_64.rpm
package iscsi-initiator-utils-6.2.0.868-0.18.el5.x86_64 is already installed
[root@server1 Server]#

Add the DAG repository:
# rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

Then add the software:
# yum install scsi-target-utils

Create a file, this will be your LUN later on:
# dd if=/dev/zero of=bigfile bs=1024 count=100000

1. Create the iscsi – lun:
————————-
# /etc/init.d/tgtd start
# tgtadm –lld iscsi –op new –mode target –tid 1 -T  iqn.1994-05.com.redhat:disk1

-> this target name was taken from /etc/iscsi/initiatorname.iscsi

List the target:
# tgtadm –lld iscsi –op show –mode target
Target 1: iqn.1994-05.com.redhat:disk1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET     00010000
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
Account information:
ACL information:

Add the LUN (here the file is used..):
# tgtadm –lld iscsi –op new –mode logicalunit –tid 1 –lun 1 -b /root/bigfile1

View:
# tgtadm –lld iscsi –op show –mode target
Target 1: iqn.1994-05.com.redhat:disk1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET     00010000
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET     00010001
SCSI SN: beaf11
Size: 102 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /root/bigfile1
Backing store flags:
Account information:
ACL information:

To add more iSCSI disks / targets:
Create a second target:
# tgtadm –lld iscsi –op new –mode target –tid 2 -T  iqn.1994-05.com.redhat:disk2
# tgtadm –lld iscsi –op new –mode logicalunit –tid 2 –lun 1 -b /root/bigfile2

-> this adds a LUN 1 to TARGET ID 2 -> iqn.1994-05.com.redhat:disk2.

To add a LUN to existing TARGET ID 1 ->
# tgtadm –lld iscsi –op new –mode logicalunit –tid 1 –lun 2 -b /root/bigfile2
Notice the TargetID here being 1, which refers to the first target created.

To remove this:
# tgtadm –lld iscsi –op delete –mode logicalunit –tid 1 –lun 2

Here we add some more targets and luns to them:
# tgtadm –lld iscsi –op new –mode target –tid 3  -T  iqn.1994-05.com.redhat:disk3
#  tgtadm –lld iscsi –op new –mode logicalunit –tid 3  –lun 1 -b /root/bigfile3

# tgtadm –lld iscsi –op new –mode target –tid 4   -T  iqn.1994-05.com.redhat:disk4
#  tgtadm –lld iscsi –op new –mode logicalunit –tid 4  –lun 1 -b /root/bigfile4
#
# tgtadm –lld iscsi –op new –mode target –tid 5   -T  iqn.1994-05.com.redhat:disk5
#  tgtadm –lld iscsi –op new –mode logicalunit –tid 5  –lun 1 -b /root/bigfile5
#
# tgtadm –lld iscsi –op new –mode target –tid 6   -T  iqn.1994-05.com.redhat:disk6
#  tgtadm –lld iscsi –op new –mode logicalunit –tid 6  –lun 1 -b /root/bigfile6

-> don’t forget to allow all initiator=client IPs to connect!:
# tgtadm –lld iscsi –op bind –mode target –tid 1 -I ALL
# tgtadm –lld iscsi –op bind –mode target –tid 2 -I ALL
# tgtadm –lld iscsi –op bind –mode target –tid 3 -I ALL
# tgtadm –lld iscsi –op bind –mode target –tid 4 -I ALL
# tgtadm –lld iscsi –op bind –mode target –tid 5 -I ALL
# tgtadm –lld iscsi –op bind –mode target –tid 6 -I ALL

# netstat -tulpn | grep 3260
tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      3224/tgtd
tcp        0      0 :::3260                     :::*                        LISTEN      3224/tgtd

IMPORTANT:
to make it persistent across reboots:
# tgt-admin –dump > /etc/tgt/targets.conf
-> here is a bug:
“No action specified” -> appearently solved in RH 5.6..

# chkconfig tgtd on -> this takes care of starting the tgtd after a reboot.

3. Now discover on the client:
——————————
The following commands are issues on the initiator / client:

# yum -y install iscsi-initiator-utils
# chkconfig iscsid on
# service iscsid start
# iscsiadm -m discovery -t sendtargets -p server1
10.100.0.254:3260,1 iqn.1994-05.com.redhat:disk1

-> YES!

4. Now use it..
—————
The following commands are issues on the initiator / client:

# iscsiadm -m node -T iqn.1994-05.com.redhat:disk1 -l    -> here -l is login &
no authentication has been set.
# iscsiadm -m node -T iqn.1994-05.com.redhat:disk1 -o update -n node.startup -v automatic
-> this will force the client to (initiator) to login after boot.

Check some more info:
# iscsiadm -m session -P 1
Target: iqn.1994-05.com.redhat:disk1
Current Portal: 10.100.0.254:3260,1
Persistent Portal: 10.100.0.254:3260,1
**********
Interface:
**********
Iface Name: default
Iface Transport: tcp
Iface Initiatorname: iqn.1994-05.com.redhat:053b55cd37e
Iface IPaddress: 10.100.0.2
Iface HWaddress: default
Iface Netdev: default
SID: 1
iSCSI Connection State: LOGGED IN
iSCSI Session State: Unknown
Internal iscsid Session State: NO CHANGE

Here -P <nr> is the printlevel from 1 – 3.

At this stage install the DAG repo on the client as before and continue installing software:
# yum install -y lssci
# lsscsi
[0:0:0:0]    disk    ATA      WDC WD2500JS-60M 10.0  /dev/sda
[1:0:0:0]    cd/dvd  HL-DT-ST DVD+-RW GSA-H31L W616  /dev/scd0
[5:0:0:0]    storage IET      Controller       0001  -
[5:0:0:1]    disk    IET      VIRTUAL-DISK     0001  /dev/sdb

So here the disk is represented as /dev/sdb

# pvcreate /dev/sdb
# vgcreate iSCSIvg /dev/sdb
# lvcreate iSCSIvg -L 30M -n sales
Rounding up size to full physical extent 32.00 MB
Logical volume “sales” created

# mkfs -j /dev/iSCSIvg/sales

To disconnect:
# iscsiadm -m node -T iqn.1994-05.com.redhat:disk1 -u

And life seems wonderfull..

This entry was posted in Solaris / linux, Technical. Bookmark the permalink.

One Response to To setup an Iscsi initiator on Linux

  1. Matchless onderwerp , het is heel interessant voor mij )))) Thanks ulimit.nl team groeten!

Leave a Reply to Appliance repair Burbank Cancel reply

Your email address will not be published. Required fields are marked *


2 × = sixteen

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

What is 13 + 15 ?
Please leave these two fields as-is: