How to Add iSCSI Storage Under Linux

Internet Small Computer System Interface (iSCSI) is a network protocol s that allows you to use of the SCSI protocol over TCP/IP networks. It is good alternative to Fibre Channel-based SANs. You can easily manage, mount and format iSCSI Volume under Solaris and Linux. It allows access to SAN storage over Ethernet.

Step1 - Add iSCSI storage under Linux
iscsi-initiator-utils - The iscsi package provides the server daemon for the iSCSI protocol, as well as the utility programs used to manage it. This package is available under Redhat Enterprise Linux , CentOS and Fedora Linux and can be installed using yum command:

Check if iscsi-initiator-utils packages is already installed
[root@labsrv ~]# rpm -qa iscsi-initiator-utils

If not installed then install it using the following command
[root@labsrv ~]# yum install iscsi-initiator-utils

If you are using Debian / Ubuntu Linux install open-iscsi package using the following command:

[root@labsrv ~]$ sudo apt-get install open-iscsi

Step2 - Configure iSCSI CHAP authentication

If your using chap authentications then configure it otherwise leave this section and move to Step3

[root@labsrv ~]# vi /etc/iscsi/iscsid.conf

node.session.auth.username = My_ISCSI_USR_NAME
node.session.auth.password = MyPassword
discovery.sendtargets.auth.username = My_ISCSI_USR_NAME
discovery.sendtargets.auth.password = MyPassword

Save and close the file

  • node.session.* is used to set a CHAP username and password for initiator authentication by the target(s).
  • discovery.sendtargets.* is used to set a discovery session CHAP username and password for the initiator authentication by the target(s)
Now start the iscsi service:
[root@labsrv ~]# service iscsi start

Step3 - Discover Targets

Now use iscsiadm command, which is a command-line tool allowing discovery and login to iSCSI targets, as well as access and management of the open-iscsi database. If your storage server IP address is, then enter the following command:

[root@labsrv ~]# iscsiadm -m discovery -t sendtargets -p
Starting iscsid:                                           [  OK  ],1

[root@labsrv ~]# service iscsi restart
Stopping iscsi:                                            [  OK  ]
Starting iscsi:                                            [  OK  ]

Now there should be a block device under /dev directory. To obtain new device name, type:

[root@labsrv ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000177ed

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/sdb: 10.2 GB, 10234101760 bytes
64 heads, 32 sectors/track, 9760 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: 0x00000000

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

/dev/sdb is my iSCSI disk

Step4 - Format and Mount iSCSI Volume

You can now partition and create a filesystem on the target using usual fdisk and mkfs.ext3 commands:

[root@labsrv ~]# fdisk /dev/sdb

[root@labsrv ~]# mkfs.ext3 /dev/sdb1

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
624624 inodes, 2498304 blocks
124915 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2558525440
77 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Mount new partition:

[root@labsrv ~]# mkdir /iscsi_disk
[root@labsrv ~]# mount /dev/sdb1 /iscsi_disk/

[root@labsrv ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
                       18G  3.3G   14G  20% /
tmpfs                 504M  100K  504M   1% /dev/shm
/dev/sda1             485M   29M  431M   7% /boot
/dev/sdb1             9.4G  150M  8.8G   2% /iscsi_disk

Step5 - Mount iSCSI drive automatically at boot time
First make sure iscsi service turned on at boot time:

[root@labsrv ~]# chkconfig iscsi on

Open /etc/fstab file and append config directive:

/dev/sdb1 /iscsi_disk ext3 _netdev 0 0

Save and close the file.

Delete iSCSI storage from linux machine
iscsiadm -m node -T -p -u
iscsiadm -m node -o delete -T -p

Powered by Blogger.