≡ Menu

Ubuntu Linux Set Iscsi Initiator

ISCSI is a network protocol standard that allows the use of the SCSI protocol over TCP/IP networks. How do I setup Iscsi Initiator under Ubuntu Linux? How do I format and connect to an iSCSI volume under Ubuntu Linux? How do I store VMware or Virtualbox virtual machine images using iscsi storage?

You need to install the following packages under Ubuntu Linux:

  • open-iscsi - Main package for setting up an iSCSI volume.
  • open-iscsi-utils - iSCSI initiatior administrative utility.

Install Required Software

Type the following command:
$ sudo apt-get update
$ sudo apt-get install open-iscsi open-iscsi-utils

Open-iSCSI Configuration

The default configuration directory located at /etc/iscsi/ and configuration file is /etc/iscsi/iscsid.conf:

Our Sample Setup

  1. iSCSI server IP: 192.168.1.1
  2. iSCSI Username: vivek
  3. iSCSI password: yHni3Oq9wYzamS

Setup iScsi Username And Password

Edit /etc/iscsi/iscsid.conf, enter:
$ sudo vi /etc/iscsi/iscsid.conf
Uncomment as set it as follows:

 
node.session.auth.username = vivek
node.session.auth.password = yHni3Oq9wYzamS
discovery.sendtargets.auth.username = vivek
discovery.sendtargets.auth.password = yHni3Oq9wYzamS
 

Save and close the file. Start / restart service, enter:
$ sudo service open-iscsi restart

Running Discovery

To run a discovery against the iscsi target host, enter:
$ sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.1
Sample outputs:

192.168.1.1:3260,1 iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030

Note down the above output and use it as follows:
$ sudo iscsiadm --mode node --targetname iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030 --portal 192.168.1.1:3260 --login
Sample outputs:

Logging in to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal: 192.168.1.1,3260]
Login to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal: 192.168.1.1,3260]: successful

You can see the following in your /var/log/messages (note down disk name):
$ tail -f /var/log/messages
Sample outputs:

Jul  2 12:54:04 vivek-laptop kernel: [ 4418.610787] scsi6 : iSCSI Initiator over TCP/IP
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.649208] scsi 6:0:0:0: Direct-Access     QNAP     iSCSI Storage    3.1  PQ: 0 ANSI: 5
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.649670] sd 6:0:0:0: Attached scsi generic sg3 type 0
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.650531] sd 6:0:0:0: [sdc] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.651889] sd 6:0:0:0: [sdc] Write Protect is off
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.652643] sd 6:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.654620]  sdc: unknown partition table
Jul  2 12:54:05 vivek-laptop kernel: [ 4419.692364] sd 6:0:0:0: [sdc] Attached SCSI disk

/dev/sdc is new block level device.

How Do I Format /dev/sdc?

Use the fdisk command
$ sudo fdisk /dev/sdc
Sample session:

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xe7b08c12.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): p
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
64 heads, 32 sectors/track, 20480 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe7b08c12
   Device Boot      Start         End      Blocks   Id  System
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-20480, default 1): Press [Enter] Key
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-20480, default 20480): Press [Enter] Key
Using default value 20480
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Format As ext3 Filesystem

Type the following command:
$ sudo mkfs.ext3 /dev/sdc1

Format As ext4 Filesystem

Type the following command:
$ sudo mkfs.ext4 /dev/sdc1
Sample outputs:

mke2fs 1.41.11 (14-Mar-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242876 blocks
262143 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
	4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Mount /dev/sdc1

Create a mount point:
$ sudo mkdir /data
$ sudo mount /dev/sdc1 /data
$ df -H

Find Out Your Disk I/O Speed

A quick way is to run dd command as follows:
$ cd /data
$ dd if=/dev/zero of=output.img bs=8k count=256k

Sample outputs:

262144+0 records in
262144+0 records out
2147483648 bytes (2.1 GB) copied, 25.57 s, 84.0 MB/s

84.0 MB/s is speed which is not bad for SOHO iscsi server.

Store VM using Vmware

You can now use new storage to store data or virtual machines. Just create a new VM and setup Location to /data/VMName:

Fig.01: VMware Iscsi Storage

Fig.01: VMware Iscsi Storage


The above is VMWare workstation 7.x vm setup. The VMWare ESX server offers data store option.

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 7 comments… add one }

  • Philippe Petrinko July 2, 2010, 11:32 am

    Useful comprehensive topic to me,
    Thanks Vivek
    :-O Wow! 80MB/s impressive high-speed.
    :-/ It seems I have to tune my local ATA-HD! (but this is another topic on which you already wrote)
    What are average effective output rate of common storage today on your systems?
    local : IDE, ATA, USB-Key, CD, DVD, Blue-Ray?

    • TryThis July 4, 2010, 2:08 pm

      Linux raid1 SAS 74GB x 2 @ 15k :D
      dd if=/dev/zero of=output2.img bs=8k count=256k
      262144+0 records in
      262144+0 records out
      2147483648 bytes (2.1 GB) copied, 5.41068 seconds, 397 MB/s

  • c.p July 2, 2010, 12:03 pm

    Is it following this structure?
    server 192.168.1.1 : provide a empty hard drive
    client : setup iSCSI to mount server hard drive and run vmware

  • Cr0t July 3, 2010, 8:52 pm

    …a little bit in more detail. I tested this some time ago.

    –BEGIN—
    FIREWALL RULES:

           LANIP=192.168.1.0/24
           IFACE=bond0
           iptables -A INPUT -p tcp -m state -i $IFACE --state NEW -s LANIP -d $LANIP --dport 3260 -j ACCEPT -v
    

    SERVER (192.168.1.86):

    vi /etc/ietd.conf
     Target iqn.2009-03.local.bigboy:openiscsi-storage
     Lun 0 Path=/dev/hda,Type=fileio
    vi /etc/conf.d/ietd.conf
     ADDRESS="192.168.1.86"
    /etc/init.d/ietd start
    

    CLIENT (192.168.1.2):

    vi /etc/iscsi/initiatorname.iscsi
     InitiatorName=iqn.2009-03.local.amy:openiscsi-storage
    /etc/init.d/iscsid start
    iscsiadm -m discovery -t st -p 192.168.1.86
    iscsiadm -m discovery
    iscsiadm -m node
    iscsiadm -m node -l
    # to mount
    iscsiadm -m node -u
    # to disconnect
    21:24:21^root@amy:/etc/iscsi > iscsiadm -m discovery -t st -p 192.168.1.86
    192.168.1.86:3260,1 iqn.2009-03.local.bigboy:openiscsi-storage
    21:25:14^root@amy:/etc/iscsi > iscsiadm -m discovery
    192.168.1.86:3260 via sendtargets
    21:25:14^root@amy:/etc/iscsi > iscsiadm -m node
    192.168.1.86:3260,1 iqn.2009-03.local.bigboy:openiscsi-storage
    21:25:14^root@amy:/etc/iscsi > iscsiadm -m node -l
    Logging in to [iface: default, target:
    iqn.2009-03.local.bigboy:openiscsi-storage, portal: 192.168.1.86,3260]
    Login to [iface: default, target:
    iqn.2009-03.local.bigboy:openiscsi-storage, portal: 192.168.1.86,3260]:
    successful
    21:27:23^root@amy:/etc/iscsi > iscsiadm -m session
    tcp: [2] 192.168.1.86:3260,1 iqn.2009-03.local.bigboy:openiscsi-storage
    21:28:10^root@amy:/etc/iscsi > iscsiadm -m discovery -t st -p
    192.168.1.86 -P 1
       Target: iqn.2009-03.local.bigboy:openiscsi-storage
           Portal: 192.168.1.86:3260,1
              Iface Name: default
    Mar 21 21:24:21 amy Loading iSCSI transport class v2.0-870.
    Mar 21 21:24:21 amy iscsi: registered transport (tcp)
    Mar 21 21:24:21 amy iscsid: iSCSI logger with pid=5052 started!
    Mar 21 21:24:22 amy iscsid: transport class version 2.0-870. iscsid
    version 2.0-870
    Mar 21 21:24:22 amy iscsid: iSCSI daemon with pid=5053 started!
    Mar 21 21:25:16 amy scsi15 : iSCSI Initiator over TCP/IP
    Mar 21 21:25:17 amy scsi 15:0:0:0: Direct-Access     IET
    VIRTUAL-DISK     0    PQ: 0 ANSI: 4
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] 20005650 512-byte hardware
    sectors: (10.2 GB/9.53 GiB)
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Write Protect is off
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Mode Sense: 77 00 00 08
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Write cache: disabled, read
    cache: enabled, doesn't support DPO or FUA
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] 20005650 512-byte hardware
    sectors: (10.2 GB/9.53 GiB)
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Write Protect is off
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Mode Sense: 77 00 00 08
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Write cache: disabled, read
    cache: enabled, doesn't support DPO or FUA
    Mar 21 21:25:17 amy sdg: sdg1 sdg2 sdg3
    Mar 21 21:25:17 amy sd 15:0:0:0: [sdg] Attached SCSI disk
    Mar 21 21:25:17 amy sd 15:0:0:0: Attached scsi generic sg6 type 0
    Mar 21 21:25:17 amy iscsid: connection1:0 is operational now
    ---END---
    
  • Tapas Mallick July 4, 2010, 2:30 pm

    How do we configure Ubuntu/RHEL/CentOS to create persistent/same device node(e.g,/dev/sdc) every time on reboot for a particular iSCSI iqn exported from an iSCSI target ?

  • Jürgen Depicker February 22, 2011, 7:34 pm

    Persistent mounting on same path:

    Create a mount point for the new file-system.
    mkdir -p /mnt/iscsi

    Update fstab to automatically mount the new filesystem at boot. Modern distros prefer to use the disk’s UUID for mounting in fstab, referring to the device by its “old school” nomenclature still works as well.

    Determine the UUID of your new iSCSI disk and add it to /etc/fstab with:

    echo $(blkid /dev/sdc1 | cut -d’ ‘ -f2 | sed s/\”//g)

    Example output:
    UUID=e227bd05-f102-4c08-ae4f-3dbfade128aa

    Safety backup:
    cp /etc/fstab /etc/fstab.old

    Add this UUID to fstab:
    printf “$(blkid /dev/sdc1 | cut -d’ ‘ -f2 | sed s/\”//g)\t/mnt/iscsi\text4\tnoatime\t0\t0\n” >> /etc/fstab

    Check:
    cat /etc/fstab

    Mount the new iSCSI block device.
    mount /mnt/iscsi

  • Chuck February 18, 2014, 6:22 pm

    I am not getting any output from the sendtargets line. How do I troubleshoot?

Leave a Comment