RSS Feed

ISCSI Target and ISCSI initiator


November 30, 2009 by admin

I had an older server with a bunk of disk and decided that it would be cool to share those disks to another host using ISCSI. I will try and give you a step by step walk through of what I did to create an iscsi target and initiator.

I started by downloading the target source code from

Because I’m using centos 5.4  I decided to use the spec file that comes with the iscsitarget to build an rpm package.

You will need to have the kernel devel package installed  in order to build the kernel driver module

rpm -ta iscsitarget-1.4.19.tar.gz

Wrote: /usr/src/redhat/RPMS/i386/iscsitarget-1.4.19-1.i386.rpm
Wrote: /usr/src/redhat/RPMS/i386/kmod-iscsitarget-1.4.19-1_2.6.18_164.6.1.el5.i386.rpm

Next install the rpm packages

rpm -ivh /usr/src/redhat/RPMS/i386/iscsitarget-1.4.19-1.i386.rpm \

in order to configure the ISCSI target will need to know what hardrive devices are installed in your server

you can run the fdisk -l command on your command prompt

My output looks like this

[root@server ~]# fdisk  -l

Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14       14593   117113850   8e  Linux LVM

Disk /dev/hdb: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/hdb doesn’t contain a valid partition table

In order to configure the iscsi target  edit the /etc/iet/ietd.conf

vi /etc/iet/ietd.conf

Mine looks like this

Lun 0 Path=/dev/hdb,Type=fileio
Alias storage_disk1

Next save your file and get ready to startup the service

/etc/init.d/iscsi-target start

Next go over the the client server and install the Centos 5.4 ISCSI initiator

yum install iscsi-initiator-utils

In this example we did not use a username and password in the ietd.conf so we will not need to configure this feature.

Set iscsi to start on boot, and start it now:
chkconfig iscsid on ; service iscsid start
chkconfig iscsi on ; service iscsi start

Use iscsiadm to discover your iSCSI targets, replacing the IP with your own portal IP:

iscsiadm -m discovery -t st -p
Once discovery tells you the target names, log into the one you want to work with:
iscsiadm -m node -T  -p -l

If you want to automatically login at boot:

iscsiadm -m node -T -p -o update -n node.startup -v automatic

Now the iSCSI volume should be detected by your system as a block device. You can check what device it was detected as by tailing your log.
tail -n 50 /var/log/messages
Let’s assume that the block device was detected as /dev/sdb. We will have to partition and format our filesystem at this point. You can either use a straight Linux partition, or you can use Linux Volume Management. I prefer LVM because it allows for more flexibility, including easy volume growth. You must use LVM if your device will be over 2TB, which is a limitation of regular Linux partitions.
For LVM, we will Initialize the block device as a physical volume, create a volume group, create a logical volume and format it as ext3. Note that with LVM, you do not use fdisk or create the sdb1 partition:

pvcreate /dev/sdb
vgcreate SANVolGroup01 /dev/sdb
lvcreate –extents 100%VG –name SANLogVol01 SANVolGroup01
mkfs -t ext3 -m 1 -L mysan1 -O dir_index,filetype,has_journal,sparse_super /dev/SANVolGroup01/SANLogVol01

mkdir /mnt/san01

mount /dev/SANVolGroup01/SANLogVol01 /mnt/san01


You must be logged in to post a comment.