Debian / Ubuntu Linux Connect to an iSCSI Volume

by on November 15, 2007 · 37 comments· LAST UPDATED December 12, 2008

in , ,

Q. How do I format and connect to an iSCSI Volume under Debian / Ubuntu Linux?

A. You need to install open-iscsi package for high performance, transport independent iSCSI implementation under Debian / Ubuntu Linux. This package is also known as the Linux Open-iSCSI Initiator. You need Linux operating system with kernel version 2.6.16, or later. See REHL 5 / CentOS 5 / Fedora Linux specific instructions here.

Install Open-iSCSI Initiator

Type the following command at a shell prompt:
$ sudo apt-get install open-iscsi

Open-iSCSI default configuration

You need to soft-link (path fix) few two files to autologin work i.e. fix file paths for iscsiadm, enter:
ln -s /etc/{iscsid.conf,initiatorname.iscsi} /etc/iscsi/
Default configuration file could be located at /etc/iscsi/iscsid.conf or ~/.iscsid.conf. Open /etc/iscsi/iscsid.conf file:
# vi /etc/iscsi/iscsid.conf
Set node.session.auth.username, node.session.auth.password and other parameter as follows:
node.startup = automatic
node.session.auth.username = MY-ISCSI-USER
node.session.auth.password = MY-ISCSI-PASSWORD
discovery.sendtargets.auth.username = MY-ISCSI-USER
discovery.sendtargets.auth.password = MY-ISCSI-PASSWORD
node.session.timeo.replacement_timeout = 120
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.noop_out_interval = 10
node.conn[0].timeo.noop_out_timeout = 15
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.conn[0].iscsi.MaxRecvDataSegmentLength = 65536

Save and close the file. Restart open-iscsi service:
# /etc/init.d/open-iscsi restart
Now you need to run a discovery against the iscsi target host:
# iscsiadm -m discovery -t sendtargets -p ISCSI-SERVER-IP-ADDRESS
If 192.168.1.60 is iSCSI server IP address, enter:
# iscsiadm -m discovery -t sendtargets -p 192.168.1.60
OR
# iscsiadm --mode discovery --type sendtargets --portal 192.168.1.60
Note down the record id (such as iqn.2001-05.com.doe:test) found by the discovery. You need the same for login. Login, must use a node record id found by the discovery:
# iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.60:3260 --login
Finally restart the service again:
# /etc/init.d/open-iscsi restart

Format iSCSI Volume

Now you should see an additional drive on the system such as /dev/sdc. Use /var/log/messages file to find out device name:
# tail -f /var/log/messages
If your device name is /dev/sdc, enter the following command to create a partition:
# fdisk /dev/sdc
Next format partition:
# mkfs.ext3 /dev/sdc1
Mount file system:
# mkdir /iscsi
# mount /dev/sdc1 /iscsi

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 37 comments… read them below or add one }

1 Alan July 9, 2008 at 5:26 pm

Doesnt work for me mate,

All the commands are entered without error but no device is found in /var/log/messages or dmesg.

fdisk -l does not show it either.

This is what I get (etch amd64)

# iscsiadm -m discovery -t sendtargets -p 10.0.0.53
10.0.0.53:3260,1 iqn.1986-03.com.hp:storage.msa2012i.0821d58403.a
10.0.0.54:3260,2 iqn.1986-03.com.hp:storage.msa2012i.0821d58403.a

but no drive found , any suggestions ?

Thanks

Alan

Reply

2 Josef July 14, 2008 at 10:53 pm

I think these instructions leave out a step. Particularly the logging in or mounting of the drive. Theoretically the “node.startup = automatic” and then iscsid restart should log into the drive for you. For whatever reason, though, the init.d file doesn’t read the config file, so any edits to that (at least for me) were useless. You can manually log into the drives with the following command:

iscsiadm -m node -T iqn.1986-03.com.hp:storage.msa2012i.0821d58403.a -p 10.0.0.53:3260 -l

also since it doesn’t read the config file you would need to manually edit any other settings for the target such as authmethod or login credentials.

iscsiadm -m node -T iqn.1986-03.com.hp:storage.msa2012i.0821d58403.a -p 10.0.0.53:3260

alone can be used to show the config and

iscsiadm -m node -T iqn.1986-03.com.hp:storage.msa2012i.0821d58403.a -p 10.0.0.53:3260 -o update -n node.session.auth.authmethod -v CHAP

can be used to edit those settings.

Reply

3 nixCraft July 15, 2008 at 9:29 am

Josef,

I just reconfigured my Debian box using same info posted here without a problem. There is a small debian only fix, for file paths, enter:
ln -s /etc/{iscsid.conf,initiatorname.iscsi} /etc/iscsi/

Hope this solves problem for both of you. Let me know…

Reply

4 debel July 25, 2008 at 1:45 pm

should i change the “initiatorname.iscsi” to something else and if yes where do i get the initiotor name?

Reply

5 nixCraft July 25, 2008 at 2:12 pm

Noop,

initiatorname.iscsi is file name and it need to copy in /etc/iscsi directory.

HTH

Reply

6 tuxim September 3, 2008 at 5:29 pm

Thanks a lot for this “as simple than usefull” tutorial.

Reply

7 TP October 5, 2008 at 11:55 pm

I am experiencing the same issue, not able to find a newly generated device after loging into the target. Os is fedora on vmware workstation.
Any suggestions? cat /proc/partitions only show sda, sda1, sda2 and dm1, dm2.
Nothing in the var/log/messages file either.
Any help would greatly be appreciated!
TP

Reply

8 rgr October 29, 2008 at 1:30 pm

amd64 doesn’t work with iscsi on debian. use another kernel (686 or so) and it should work.

Reply

9 Mr Zog December 12, 2008 at 9:31 pm

No offense, but you don’t really -explain- anything.

For example, is node.session.auth.username a user on the initiator or the target?

Maybe we should assume that this user/password must exist on both initiator and target.

And should the discovery.sendtargets.auth.password be the same as the
node.session.auth.password ?

What is session versus discovery?

Reply

10 nixCraft December 12, 2008 at 10:02 pm

This article is about iSCSI initiator client configuration and not about setting up target. So username and password mentioned here are about iSCSI initiator client configuration.

> Maybe we should assume that this user/password must exist on both initiator and target.
Username / password must exits on target. In /etc/iscsi/iscsid.conf you setup login information for target.

> And should the discovery.sendtargets.auth.password be the same as the
node.session.auth.password ?

It can be or can not be… It depends upon your local configuration. Ask your storage admin about passwords.

node.session.* => used to set a CHAP username and password for initiator authentication by the target(s).

discovery.sendtargets.* => used to set a discovery session CHAP username and password for the initiator authentication by the target(s).

Reply

11 Chris Kehayias January 15, 2009 at 9:13 pm

Thanks so much this worked for me right out of the gate. I have connect my Ubuntu Server VM to an OpenFiler SAN on another machine… Worked like a champ!

Reply

12 Martijn March 2, 2009 at 12:07 pm

Worked like a dream, hooked up my OpenFiler iSCSI target without a problem and attached 2 Ubuntu installations to it for backup purposses. Thank you!

Reply

13 Chris Kehayias March 19, 2009 at 12:11 pm

I am having issues after every restart where the open-iscsi isn’t starting up correctly. It is fixable by issuing /etc/init.d/open-iscsi restart, but that really isn’t a great solution. Any suggestions?

Reply

14 EE April 21, 2009 at 1:11 pm

iscsi works perfectly with amd64 on debian. rgr’s message above caused me a couple of hours of wasted time!

Reply

15 Jon May 29, 2009 at 4:11 pm

A nice guide. Thanks. :)

Reply

16 D.Sain June 1, 2009 at 9:31 pm

One step I’ve noticed with the Ubuntu machines I’ve setup is that the target isn’t connected automatically on restart of the service. To correct this I’ve edited the target’s defaults file (/etc/iscsi/nodes/iqn*.sometargetname/ipaddress,node,1/default). In here I’ve changed node.conn[0].startup to automatic.

This can also be setup with:
./iscsiadm -m node -T iqn.2005-03.com.max -p 192.168.0.4:3260 \
-o update -n node.conn[0].startup -v automatic
however sometimes I get an error (-5) with this although it in the docs at open-iscsi.org. Sometimes it works. If not, edit the file.

Reply

17 D.Sain June 1, 2009 at 9:35 pm

I should say, however this is the document I always go to for my Deb setups. Kudos to the author for saving us hours of work.

Reply

18 Ilia umudumov August 31, 2009 at 12:04 pm

I do olready everything end it’s work fine I have some problems with isci enterprise tool but what is my #1 problem after restart I lost my partitions how I can correct this problem?

Reply

19 Scott September 3, 2009 at 2:46 pm

This worked like a charm for me. Thank you very much.
Ubuntu 9.04, 2.6.28-11-server

Reply

20 shixer September 25, 2009 at 3:40 am

Just what I needed, , thanks!

Reply

21 Mr. Scary December 14, 2009 at 3:23 pm

Dr. Sain, thanks for that change (-o update -n node.conn[0].startup -v automatic)! I was blocked by that in the past. Now trying again and found your comment. This is such a hack. Shouldn’t that be covered by the line ‘node.startup = automatic’ in /etc/iscsi/iscsid.conf?

Reply

22 omidm January 30, 2010 at 10:50 pm

I am having problem to mount my iscsi targets. I already have two internal disks /dev/sda and /dev/sdb, and the iscsi is being supplied by qnap-ts459. I have following all that is in this article, but I still cannot see any additional disks either via fdisk -l or in /var/adm/emssages. When checking the provider/targets on qnap, I can see there is a connection to that target, but I cannot see it on my ubuntu 9.10. Also when I initially start iscsid (via /etc/init.d/open-iscsi), I get ln: /bin/init/rw/sendsigs.omit.d: no such a directory. I have to create this directory manually to get rid of this message. Any help wold be appreciated.

Omid.

Reply

23 Horn September 30, 2010 at 2:25 pm

I have similar problem with “sendsigs.omit.d” file. this message disappears after manually creating this file but after reboot I need to do it once again. I am newbie in Linux and need your suggestion, should I add this file creation by my hands (is it typically for Linux world?) or it is issue which could be solved by correct service settings?

Reply

24 Romulus May 24, 2010 at 3:54 am

Thanks for this. Works great!

Except…my target changes between /dev/sdc1 and /dev/sdd1 between reboots and is appears to be a random choice.

Is there anyway to “lock” the target to the same /dev node so I can put it in my fstab to mount on boot up?

Cheers!

Romulus

Reply

25 Tmp August 28, 2010 at 1:47 am

Use UUIDs in place of absolute device paths.

pbarker@eccles:~$ sudo blkid /dev/sda1
/dev/sda1: UUID=”1abd1d95-8926-49f6-817b-482f02f6c6cc” SEC_TYPE=”ext2″ TYPE=”ext3″
pbarker@eccles:~$ grep 1abd1d95-8926-49f6-817b-482f02f6c6cc /etc/fstab
UUID=1abd1d95-8926-49f6-817b-482f02f6c6cc / ext3 relatime,errors=remount-ro 0 1
pbarker@eccles:~$

Reply

26 patchy May 26, 2010 at 5:08 pm

hi
Just what I needed, , thanks!

Reply

27 Dalsim August 11, 2010 at 1:13 pm

Hi, this looks good.

I am trying to get my Networked DVD drive which is part of my NAS to work with my Ubuntu setup using an iscsi initiator. I have it working on Windows XP and Windows 7, now I am trying to get it working on Ubuntu. I will then have all computers on my network using one DVD drive.

I tried the instructions above but when I try to save the iscsid.conf file I get the message:

[ Error writing /etc/iscsi/iscsid.conf: Permission denied ]

Is there a way around this? Or does anyone know how to get iscsi to work with a networked DVD drive?

Any help would be appreciated.

Reply

28 Dalsim August 12, 2010 at 10:10 am

Hello,

Well I managed to get a step further, but now I get the error below when I try to restart the iscsi service:

* Starting iSCSI initiator service iscsid grep: /etc/iscsi/initiatorname.iscsi: Permission denied
* Error: /etc/iscsi/initiatorname.iscsi does not contain a valid InitiatorName.
* The iSCSI driver has not been correctly installed and cannot start.

Has anyone encountered this or know how to configure it correctly?

Thanks

Reply

29 matt February 17, 2011 at 6:35 pm

I know this is old, but it may help someone else looking. I had this issue and simply forgot to run as sudo user.

Reply

30 EricStJean April 22, 2011 at 8:59 am

It helped me…
Thanks

Reply

31 Nik Southworth November 18, 2010 at 8:50 am

Hi,

I have three targets setup on my device but I only want my (debian) client to connect to one of them, when I restart the service however it attempts to login into all three and takes ages because the credentials are wrong for two of them.

How do I specify which target to login to?

Reply

32 Tom April 14, 2011 at 5:21 pm

I am having the same issue. Can anyone help!?

There are 8 targets on my device, only want to connect to 1, but it is trying to connect to all 8, how can I tell it which target to log into?

Reply

33 Tony Miranda December 2, 2010 at 6:45 pm

HI,

Is there anyway to load in the Initiator the new LUNs recently created in the Target ?
The ‘open-iscsi restart’ doest the job, but not perfectly. When I restart the ‘open-iscsi’ I lost access to the the others LUNs that i was using before.

Can’t I just reload/update without loosing access to the LUNs already in use ?

Thanks.

Reply

34 vigilon December 29, 2010 at 7:48 pm

That is a very applicable info to our current project.

Reply

35 witek February 1, 2011 at 8:19 am

Works like a charm. Thanks.

restarting iscsi wasn’t naccassary.

Not tested reboot yet, but i see some configuration files automagically appeared in /etc/iscsi/nodes/ so I guess it should work. Eventually I will need to change node.startup = manual to node.startup = automatic, and of course put something into /etc/fstab :)

IPv6 works without problem.

PS. Generally you do not need to partition disk. One can create filesystem directly on disk, or put there other things (luks encryption, LVM, raid between multiple iscsi targets, etc) . It is even recomended sometimes i.e for btrfs, or zfs, or when sector aligment can be problematic. It is also not needed if exported block device is already a partition of some block device. Partitioning in such situations is possible of course, but not needed.

Reply

36 Chris "OneSeventeen" Adams March 8, 2011 at 10:01 pm

These instructions helped a TON!

Quick WARNING:
setting node.startup = automatic will make it automatically connect to ALL DISCOVERED TARGETS on the portal!

For me, this was all 10 targets that were in production use! eeek!

Here’s what the manual says: (via http://www.open-iscsi.org/docs/README)
To automate login to a node, use the following with the record ID
(record ID is the targetname and portal) of the node discovered in the
discovery above:
iscsiadm -m node -T targetname -p ip:port –op update -n node.conn[0].startup -v automatic

Reply

37 duonghanu August 26, 2012 at 2:54 pm

perfect. thanks.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: