31 Ağustos 2011 Çarşamba

Ubuntu Linux Set Iscsi Initiator

SCSI 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:
  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
Sample outputs:,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 --login
Sample outputs:
Logging in to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal:,3260]
Login to [iface: default, target: iqn.2004-04.com.qnap:ts-559:iscsi.vm0.c43030, portal:,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)
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,

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