Todd Smith Org

March 17, 2009

Linux iSCSI target compile HOWTO

Filed under: Server Technology — admin @ 5:27 pm

This will probably work just fine on other linux distributions as well such as Fedora, CentOS, and even Slackware. These notes are from my installation on Ubuntu Server 8.10 (Intrepid Ibex) amd64. Btw, this server will act an an iSCSI Target for Xen Virtualization.

iSCSI

  • All major server distributions support iSCSI
  • iSCSI is based on open standards
  • iSCSI is often a requirement for people setting up virtual machines
  • iSCSI is the most inexpensive way to build a SAN

The question is now do I go with LIO or IET?

EIT appears to me to be the most mature software. I’ll use it.

So I download it from sourceforge: iscsitarget-04.17.tar.gz

I want to build this on a solid fresh base, and so I’ll do an apt-get update and an apt-get upgrade to make sure I’ve got all of the latest software, libraries, and header files.

Turns out that on this installation of Ubuntu Server, I don’t have “make” installed.

I’ll use apt-get install build-essential to update my system with all the goodies that I’ll need to build the system. Stuff like gcc, make, binutils, g++ and so forth.

I extract the iscsitarget to /usr/src, and cd /usr/src/iscsitarget-0.4.17, and issue the make command.

I get an error right off the bat:

chap.c:20:25: error: openssl/sha.h: No such file or directory
chap.c:21:25: error: openssl/md5.h: No such file or directory
chap.c: In function ‘chap_calc_digest_md5’:

Looks like I need the openssl development headers installed. Simply: apt-get install libssl-dev

Let’s try make again. Okay another error, but we’ve made some progress:

make -C /lib/modules/2.6.27-7-server/build SUBDIRS=/usr/src/iscsitarget-0.4.17/kernel modules
make: *** /lib/modules/2.6.27-7-server/build: No such file or directory. Stop.
make: *** [kernel] Error 2

Let’s try again: apt-get install kernel-package linux-libc-dev linux-source linux-headers-`uname -r`

Is it there now? /lib/modules/$(uname -r)/build

Yes! apt-get is so cool!

For Redhat/CentOS based OSs try yum -y install gcc openssl-devel kernel-devel

Try again: make clean && make

root@opennas-kc01:/usr/src/iscsitarget-0.4.17# make clean && make
make -C usr clean
make[1]: Entering directory `/usr/src/iscsitarget-0.4.17/usr’
rm -f *.o ietd ietadm
make[1]: Leaving directory `/usr/src/iscsitarget-0.4.17/usr’
make -C /lib/modules/2.6.27-7-server/build SUBDIRS=/usr/src/iscsitarget-0.4.17/kernel clean
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-server’
CLEAN /usr/src/iscsitarget-0.4.17/kernel/.tmp_versions
CLEAN /usr/src/iscsitarget-0.4.17/kernel/Module.symvers
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-server’
make -C usr
make[1]: Entering directory `/usr/src/iscsitarget-0.4.17/usr’
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o ietd.o ietd.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o iscsid.o iscsid.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o conn.o conn.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o session.o session.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o target.o target.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o message.o message.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o ctldev.o ctldev.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o log.o log.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o chap.o chap.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o event.o event.c
event.c: In function ‘handle_iscsi_events’:
event.c:86: warning: format ‘%#lx’ expects type ‘long unsigned int’, but argument 4 has type ‘long long unsigned int’
event.c:91: warning: format ‘%#lx’ expects type ‘long unsigned int’, but argument 2 has type ‘long long unsigned int’
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o param.o param.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o plain.o plain.c
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o isns.o isns.c
cc ietd.o iscsid.o conn.o session.o target.o message.o ctldev.o log.o chap.o event.o param.o plain.o isns.o -o ietd -lcrypto
cc -O2 -fno-inline -Wall -Wstrict-prototypes -g -I../include -D_GNU_SOURCE -c -o ietadm.o ietadm.c
cc ietadm.o param.o -o ietadm
make[1]: Leaving directory `/usr/src/iscsitarget-0.4.17/usr’
make -C /lib/modules/2.6.27-7-server/build SUBDIRS=/usr/src/iscsitarget-0.4.17/kernel modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.27-7-server’
CC [M] /usr/src/iscsitarget-0.4.17/kernel/tio.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/iscsi.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/nthread.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/wthread.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/config.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/digest.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/conn.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/session.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/target.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/volume.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/iotype.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/file-io.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/null-io.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/target_disk.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/event.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/param.o
CC [M] /usr/src/iscsitarget-0.4.17/kernel/block-io.o
LD [M] /usr/src/iscsitarget-0.4.17/kernel/iscsi_trgt.o
Building modules, stage 2.
MODPOST 1 modules
CC /usr/src/iscsitarget-0.4.17/kernel/iscsi_trgt.mod.o
LD [M] /usr/src/iscsitarget-0.4.17/kernel/iscsi_trgt.ko
make[1]: Leaving directory `/usr/src/linux-headers-2.6.27-7-server’
root@opennas-kc01:/usr/src/iscsitarget-0.4.17#

root@opennas-kc01:/usr/src/iscsitarget-0.4.17# make install
`usr/ietd’ -> `/usr/sbin/ietd’
`usr/ietadm’ -> `/usr/sbin/ietadm’
`etc/initd/initd.debian’ -> `/etc/init.d/iscsi-target’
`etc/ietd.conf’ -> `/etc/ietd.conf’
`etc/initiators.allow’ -> `/etc/initiators.allow’
`etc/initiators.deny’ -> `/etc/initiators.deny’
`doc/manpages/ietadm.8′ -> `/usr/share/man/man8/ietadm.8′
`doc/manpages/ietd.8′ -> `/usr/share/man/man8/ietd.8′
`doc/manpages/ietd.conf.5′ -> `/usr/share/man/man5/ietd.conf.5′
install: creating directory `/usr/share/doc/iscsitarget’
`ChangeLog’ -> `/usr/share/doc/iscsitarget/ChangeLog’
`COPYING’ -> `/usr/share/doc/iscsitarget/COPYING’
`README’ -> `/usr/share/doc/iscsitarget/README’
`README.vmware’ -> `/usr/share/doc/iscsitarget/README.vmware’
install: creating directory `/lib/modules/2.6.27-7-server/kernel/iscsi’
`kernel/iscsi_trgt.ko’ -> `/lib/modules/2.6.27-7-server/kernel/iscsi/iscsi_trgt.ko’
Running depmod
root@opennas-kc01:/usr/src/iscsitarget-0.4.17#

I run the start command: /etc/init.d/iscsi-target start && tail /var/log/messages

And I see good stuff:

Mar 17 00:09:22 opennas-kc01 kernel: [15876.392301] iSCSI Enterprise Target Software – version 0.4.15
Mar 17 00:09:22 opennas-kc01 kernel: [15876.392404] iscsi_trgt: Registered io type fileio
Mar 17 00:09:22 opennas-kc01 kernel: [15876.392407] iscsi_trgt: Registered io type blockio
Mar 17 00:09:22 opennas-kc01 kernel: [15876.392410] iscsi_trgt: Registered io type nullio

Configuration

man ietd.conf

From the ietd.conf manpage:

DESCRIPTION
/etc/ietd.conf contains configuration information for the ietd (8) command. This is the place, where you configure your iSCSI
targets and daemon defaults.

Only lines starting with ‘#’ are ignored. Putting ’#’ in the middle of a line is disallowed. A line may be extended across multi‐
ple lines by making the last character a backslash.

The “Yes” and “No” for parameter values are case sensitive. The parameter names are case insensitive.

The file consists of a global part and zero or more “Target” stanzas. Everything until the first target definition belongs to the
global configuration.

Here is an example:

IncomingUser joe secret
OutgoingUser jack secret2

Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
IncomingUser jim othersecret
OutgoingUser james yetanothersecret
Lun 0 Path=/dev/sdc,Type=fileio
Lun 1 Sectors=10000,Type=nullio
Alias Test
HeaderDigest None
DataDigest None
MaxConnections 1
InitialR2T Yes
ImmediateData No
MaxRecvDataSegmentLength 8192
MaxXmitDataSegmentLength 8192
MaxBurstLength 262144
FirstBurstLength 65536
DefaultTime2Wait 2
DefaultTime2Retain 20
MaxOutstandingR2T 8
DataPDUInOrder Yes
DataSequenceInOrder Yes
ErrorRecoveryLevel 0

Stanzas start with the word “Target” and the target name. This name must be a globally unique name, as defined by the iSCSI stan‐
dard : the “iSCSI Qualified Name”. The daemon brings the targets up in the order listed.

In the following example configuration I used an LVM device (/dev/mapper/lvmxen-capacity–root) it could have been any other block device however such as /dev/sdb1.

Target iqn.2001-10.org.toddsmith:storage.vps.mac.blacktop
IncomingUser toddin 012345678901
OutgoingUser toddout 012345678901
Lun 0 Path=/dev/mapper/lvmxen-capacity–root,Type=fileio,ScsiId=Sup3rSCS1D3V1C31

The IncomingUser is used for iSCSI initiator discovery, and outgoing user authenticates the iSCSI target server to the initiator client. Hint, the RFC specifies that the password must be exactly 12 characters.

I hope you found this HOWTO useful.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress