Using iSCSI On Debian Lenny (Initiator And Target)

Version 1.0
Author: Falko Timme
Last edited 02/24/2009

This guide explains how you can set up an iSCSI target and an iSCSI initiator (client), both running Debian Lenny. The iSCSI protocol is a storage area network (SAN) protocol which allows iSCSI initiators to use storage devices on the (remote) iSCSI target using normal ethernet cabling. To the iSCSI initiator, the remote storage looks like a normal, locally-attached hard drive.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using two Debian Lenny servers here:

  • (Initiator): IP address
  • (Target): IP address


2 Setting Up The Target (server2)


First we set up the target (server2):

aptitude install iscsitarget iscsitarget-modules-`uname -r`

Open /etc/default/iscsitarget...

vi /etc/default/iscsitarget

... and set ISCSITARGET_ENABLE to true:


We can use unused logical volumes, image files, hard drives (e.g. /dev/sdb), hard drive partitions (e.g. /dev/sdb1) or RAID devices (e.g. /dev/md0) for the storage. In this example I will create a logical volume of 20GB named storage_lun1 in the volume group vg0:

lvcreate -L20G -n storage_lun1 vg0

(If you want to use an image file, you can create it as follows:

mkdir /storage
dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000

This creates the image file /storage/lun1.img with a size of 20GB.


Next we edit /etc/ietd.conf...

vi /etc/ietd.conf

... and comment out everything in that file. At the end we add the following stanza:

        IncomingUser someuser secret
        Lun 0 Path=/dev/vg0/storage_lun1,Type=fileio
        Alias LUN1
        #MaxConnections  6

The target name must be a globally unique name, the iSCSI standard defines the "iSCSI Qualified Name" as follows: iqn.yyyy-mm.<reversed domain name>[:identifier]; yyyy-mm is the date at which the domain is valid; the identifier is freely selectable. The IncomingUser line contains a username and a password so that only the initiators (clients) that provide this username and password can log in and use the storage device; if you don't need authentication, don't specify a username and password in the IncomingUser line. In the Lun line, we must specify the full path to the storage device (e.g. /dev/vg0/storage_lun1, /storage/lun1.img, /dev/sdb, etc.).

Now we tell the target that we want to allow connections to the device from the IP address (

vi /etc/initiators.allow


... and start the target:

/etc/init.d/iscsitarget start


3 Setting Up The Initiator (server1)


On server1, we install the initiator:

aptitude install open-iscsi

Next we open /etc/iscsi/iscsid.conf...

vi /etc/iscsi/iscsid.conf

... and set node.startup to automatic:

node.startup = automatic

Then we restart the initiator:

/etc/init.d/open-iscsi restart

Now we connect to the target (server2) and check what storage devices it has to offer:

iscsiadm -m discovery -t st -p

server1:~# iscsiadm -m discovery -t st -p,1

iscsiadm -m node

server1:~# iscsiadm -m node,1

The settings for the storage device on,1 are stored in the file /etc/iscsi/nodes/,3260,1/default. We need to set the username and password for the target in that file; instead of editing that file manually, we can use the iscsiadm command to do this for us:

iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.authmethod --value=CHAP
iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.username --value=someuser
iscsiadm -m node --targetname "" --portal "" --op=update --name node.session.auth.password --value=secret

Now we can log in, either by running...

iscsiadm -m node --targetname "" --portal "" --login

server1:~# iscsiadm -m node --targetname "" --portal "" --login
Logging in to [iface: default, target:, portal:,3260]
Login to [iface: default, target:, portal:,3260]: successful

... or by restarting the initiator:

/etc/init.d/open-iscsi restart

(If you want to log out, you can run

iscsiadm -m node --targetname "" --portal "" --logout


In the output of

fdisk -l

you should now find a new hard drive (/dev/sdb in this example); that's our iSCSI storage device:

server1:~# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00031334

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3749    30113811   83  Linux
/dev/sda2            3750        3916     1341427+   5  Extended
/dev/sda5            3750        3916     1341396   82  Linux swap / Solaris

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Share this page:

6 Comment(s)

Add comment


From: Axel Werner at: 2009-04-17 09:38:28

Hi again!

Sorry for my last comment. it somehow fucked up using this ugly what-you-see-will-look-like-even-more-worse-after Editor on your Website. editor is perfect.

Finaly I found  the Problem with my configuration. Its the two small numbers at the end of the lines located within the /etc/fstab. In my Version i entered "0 2" which means recording the man fstab pages that this partition/disk is supposed to be filechecked on boottime after the rootfs and other more important filesystems.

While in Your Manual you used "0 0" which recording to the "man fstab" means "do not fscheck this partition at boot time".

I dont know why Debian Lenny cannot fscheck those iSCSI Drives at this time, but fact is, i have to use "0 0" for those iSCSI Entries in /etc/fstab to make it boot properly.

maybe one of you guys can explain why this 0 2 wont work. Since i think its a good idea to have all FS checked sometimes at boottime.

Thanks again for Manual/Howto!


From: Anonymous at: 2009-06-14 16:15:58

The reason for this is in your logfiles you posted:

At the time that fsck runs, you have not yet mounted the drive.  This is due to the connection being fired AFTER the devices are mounted.  More than likely you could alter this by changing various boot scripts, but another (less trouble; easier to diagnose problems; and overall just a better answer) is to fsck yourself in your local init script.

That's what the local init script is for: things that you are doing to your local box, at boot, that aren't in another script.  Local customization if you like.

It's in /etc/rc.local, and by default, as it says, it does nothing.

Just be sure when you do the fsck that you have the output sent somewhere, and that you block the login from finishing until it is done.  (i.e. don't background the fsck, or the local init script itself.)

The reason for sending the output somewhere is I am not sure you will be able to trigger a 'must reboot!' or similar from the rc.local script.  (You could, of course, reboot without intervention; so I suppose you can script something here.)

Overall you can make this as complex as you like, just remember that if you make it TOO complex, later if the system doesn't work properly, you have to figure out what the heck your scripts are doing.  That's not something you want to do under pressure (like your boss screaming at you that he can't get his mail and the internetz are down.)

From: Axel Werner at: 2009-04-14 15:25:55

Hi! First of all THANKS for this Great Manual. 

But i got one single thing remaining that i was not able to solve yet.

My Debian Lenny stops the boot process at some point, telling me that he was not able to find the iSCSI Devices under /dev/disk/by-path/<some iSCSI Target Adress here> - ill have to press CONTROLL+D to continue. After i do a CTRL+D i find my linux box all bootet up and working. Even those iSCSI Targets i wanted to mount automaticly at boot time are mounted and fully accessable.

 I searched the net n stuff for any similar problems and i found some. but all those problems "should" been solved meanwhile through debian/ubuntu updates. however it still gots me.

After a interupted boot i can see and use this:

hostname:/dev/disk/by-path# ls -la
total 0
drwxr-xr-x 2 root root 180 2009-04-14 17:10 .
drwxr-xr-x 5 root root 100 2009-04-14 17:01 ..
lrwxrwxrwx 1 root root   9 2009-04-14 17:10 ip-                                               -> ../../sdb
lrwxrwxrwx 1 root root   9 2009-04-14 17:10 ip-                                               -> ../../sdc


my fstab looks like this

# iSCSI Eintraege (manuell)
/dev/disk/by-path/ /home           ext3    defaults,_netdev0 2
/dev/disk/by-path/ /zksfs-data1    ext3    defaults,_netdev0 2

 now.. Why is yours working and mine stops at boot time? :-P

best regards





From: Anonymous at: 2009-04-07 20:46:29

just wanted to say that this helped me alot

works perfect

 thank you so much

From: Francis at: 2009-09-16 14:20:07

Great tutorial, it works perfectly.

 Do you know if it's possible do dynamicaly resize vulumes?

Also is it possible to access the same volume from 2 clients at the same time?

From: yannick at: 2009-11-11 22:56:02

Thank you for this very good howto

In my case I have multiples iscsi target to mount. Unfortunetly , I did not find a mean to map a target to a device. And ... at boot time the system does not map the device in the correct order, As a consequence, I end up with target mounted on the wrong mount point.

To sort it out,

1. label the device with e2label (ext2,ext3) or xfs_admin (xfs)


>xfs_admin -L mysql1 /dev/sdb1


2. Edit the fstab and use the label instead of the device


>vi /etc/fstab

#device         mount point     FS      Options   Backup  fsck
LABEL=mysql2     /mysql2        xfs     _netdev   0       0
LABEL=mysql1     /mysql1        xfs     _netdev   0       0

It works well for me.

 (references : and )