The Open-iSCSI project is a high performance, transport independent, multi-platform implementation of RFC3720 (The iSCSI specification). It consists of a minimal set of kernel modules combined with powerful userspace utilities. Once installed on a system, a daemon process iscsid can be controlled using the iscsiadm management utility. Open-iSCSI requires a Linux kernel of 2.6.16 or greater.

CentOS 5/6: Open-iSCSI can be installed using yum:

# sudo yum install iscsi-initiator-utils

Debian/Ubuntu: Open-iSCSI can be installed using apt:

# sudo apt-get install open-iscsi

Configure iSCSI Drivers and Utilities

Linux

Open /etc/iscsi/iscsid.conf with the text editor of your choice:

# sudo vi /etc/iscsi/iscsid.conf

Make the following edits to the configuration file. Set the values of username and password to the CHAP username/password provided to you when you purchased the block storage.

node.startup = automatic
node.session.auth.authmethod = CHAP
node.session.auth.username = 
node.session.auth.password = 
discovery.sendtargets.auth.authmethod = CHAP
discovery.sendtargets.auth.username = 
discovery.sendtargets.auth.password = 

Next, you must run the discovery command against the discovery IP for your block storage device. After the discovery command is run, you must restart the iscsi service.

CentOS 5/6:

# sudo iscsiadm -m discovery -t sendtargets -p <Discovery IP Address>
# sudo service iscsi restart


# sudo iscsiadm -m discovery -t sendtargets -p 192.168.1.106
192.168.1.106:3260,257 iqn.2005-10.org.freenas.ctl:vol1

Debian/Ubuntu:

# sudo service open-iscsi start
# sudo iscsiadm -m discovery -t sendtargets -p <Discovery IP Address>
# sudo service open-iscsi restart


Setup Storage Volumes

Linux

After successfully discovering your block storage disk, the volume should show as available to the fdisk command:

# fdisk -l

....output truncated....

        Disk /dev/sdb: 300.0 GB, 300000002048 bytes
        255 heads, 63 sectors/track, 36472 cylinders
        Units = cylinders of 16065 * 512 = 8225280 bytes
        Sector size (logical/physical): 512 bytes / 4096 bytes
        I/O size (minimum/optimal): 4096 bytes / 4096 bytes
        Disk identifier: 0x00000000

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

Or

# iscsiadm -m session
tcp: [1] 192.168.1.106:3260,257 iqn.2005-10.org.freenas.ctl:vol1 (non-flash)

At this point, you can create filesystems on the disk or configure it as a raw block device as desired:

    # parted /dev/sdb
    GNU Parted 2.2
    Using /dev/sda
    Welcome to GNU Parted&gt; ! Type 'help' to view a list of commands.
    (parted) mklabel gpt
    (parted) mkpart extended 0% 100%
    (parted) print
    Model: SolidFir SSD SAN (scsi)
    Disk /dev/sda: 300GB
    Sector size (logical/physical): 512B/4096B
    Partition Table: gpt

    Number  Start   End    Size   File system  Name      Flags
     1      1049kB  300GB  300GB               extended

     (parted) quit

Create the format the file system:

    # mkfs -t ext3 -L myBlockStorage /dev/sdb1
    mke2fs 1.41.11 (14-Mar-2010)
    Filesystem label=myBlockStorage
    .... output truncated ....

Create a mount point and mount the device

# mkdir /mnt/my_block_storage_volume
# mount /dev/sdb1 /mnt/my_block_storage_volume/

Get mount information:

# blkid
/dev/mapper/centos-root: UUID="198c20b5-d690-404b-8244-6e4ef8e66618" TYPE="xfs"
/dev/sda2: UUID="5d57ye-2YQD-vpoo-YV4w-VTUm-gtGA-kGTNzr" TYPE="LVM2_member"
/dev/sda1: UUID="bdf1787d-e27b-4cd0-bd47-0de6865c6858" TYPE="xfs"
/dev/mapper/centos-swap: UUID="33d91d50-a9f8-4d1e-94f4-63ab19dc34d1" TYPE="swap"
/dev/sdb1: LABEL="storage" UUID="362c5edb-6c68-4ec9-8745-576cba65133e" SEC_TYPE="ext2" TYPE="ext3" PARTLABEL="extended" PARTUUID="8689df9d-b059-4812-a5d4-e97fcb3b80c4"

Edit fstab to mount on boot:

# nano /etc/fstab 
#/dev/sdb1       /mnt/storage  ext3  defaults     0       0

Reboot system to ensure that the device is mounted on boot. If you receive the following error:

Edit fstab to include the following:

# /dev/sdb1 /mnt/storage ext3 _netdev 0 0

This works as well…


# /dev/sdb1       /mnt/storage  ext3  acl,user,nofail     0       0

Notes:

  1. Use the nofail option in /etc/fstab
  2. Make sure the dump field is set to 0 (zero) else the system will stop booting and prompt for the maintenance mode as the device is not available at this time in the boot process.
    The dump option is the fifth entry option in /etc/fstab, see man 5 fstab for more information.
  3. Make sure iscsi is enabled at boot – (CentOS 7 – systemctl enable iscsi.service).

Source: https://www.novell.com/support/kb/doc.php?id=7004427

NOTE: SAN disks can be slow to format due to the large number of small IOPs required by the formatting utility. To speed the formatting of your disk, you may wish to pass the ‘-E lazy_itable_init’ option to mkfs.

In order to automatically connect to your block storage disk on system startup, make the following changes to the /etc/iscsi/iscsi.conf file:


# nano /etc/iscsi/iscsid.conf
# To manually startup the session set to "manual". The default is automatic.
node.startup = automatic