Debian / Ubuntu Linux Connect to an iSCSI Volume

last updated in Categories , , , , , , ,

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 is iSCSI server IP address, enter:
# iscsiadm -m discovery -t sendtargets -p
# iscsiadm --mode discovery --type sendtargets --portal
Note down the record id (such as 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 --portal --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


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

38 comment

  1. 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,1,2

    but no drive found , any suggestions ?



  2. 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 -p -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 -p

    alone can be used to show the config and

    iscsiadm -m node -T -p -o update -n node.session.auth.authmethod -v CHAP

    can be used to edit those settings.

  3. 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…

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

  5. 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!

  6. 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?

  7. 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).

  8. 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!

  9. 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!

  10. 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?

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

  12. 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 -p \
    -o update -n node.conn[0].startup -v automatic
    however sometimes I get an error (-5) with this although it in the docs at Sometimes it works. If not, edit the file.

  13. 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.

  14. 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?

  15. 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?

  16. 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.


    1. 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?

  17. 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?



    1. 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

  18. 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.

    1. 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?


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

  19. 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?

    1. 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?

  20. 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 ?


  21. 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.

  22. 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
    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

  23. I am able to successfully setup the iscsi initiator on Debian distribution, however after login to session, ” fdisk -l ” shows all the partitions of target without creating them.
    And after performing mkfs.ext4(formatting) on those partition and mounting, i didn’t get respective data in mounted volume.

    Any help will be appreciated.

    Still, have a question? Get help on our forum!