Oracle 8i | Oracle 9i | Oracle 10g | Oracle 11g | Oracle 12c | Miscellaneous | PL/SQL | SQL | Oracle RAC | Oracle Apps | Linux

Linux iSCSI Targets and Initiators

This article provides an overview of configuring iSCSI targets and initiators on Linux, with specific reference to the information needed for the RHCE EX300 certification exam.

Remember, the exams are hands-on, so it doesn't matter which method you use to achieve the result, so long as the end product is correct.

Related articles.

iSCSI Targets

Configuration of iSCSI targets is not part of the exam, but you are going to need some to test the iSCSI intiator configuration.

Install the necessary package to support the creation of iSCSI targets.

# yum install scsi-target-utils

Turn on the service and make sure it starts automatically after reboot.

# service tgtd start
# chkconfig tgtd on

I have a virtual machine called "rhce2.localdomain" with an additional virtual hard drive called "/dev/sdb". If you want to make permanent iSCSI targets, you need to add modify the "/etc/tgt/targets.conf" file. The following entry will create an iSCSI target for this disk device.

<target rhce2:drive1>
    backing-store /dev/sdb
</target>

After amending the "/etc/tgt/targets.conf" file you need to restart the tgtd service.

# service tgtd restart

The target will now be visible using the following command.

# tgtadm --lld iscsi --mode target --op show
Target 1: rhce2:drive1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 12885 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
    Account information:
    ACL information:
        ALL
#

If you are using the Linux firewall you will need to make sure the TCP port 3260 is open on the server. Assuming you are using a firewall setup file, as described here, you can include the following addition to the INPUT chain.

# Open port for iSCSI.
iptables -A INPUT -p udp --dport 3260 -j ACCEPT

This is the simplest way to create iSCSI targets. Some resources suggest you use the tgtadm command. The example below describes how that works, but it is quite long-winded in comparison to amending the "/etc/tgt/targets.conf" file and the targets are not permanent.

The man page for the tgtadm command includes examples of creating an iSCSI target. The example in the man page looks like this.

# Create a target
tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2007-03:virtual-dvd:‘hostname‘

I have a virtual machine called "rhce2.localdomain" with an additional virtual hard drive called "/dev/sdb". First we must create and empty target.

# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname rhce2:drive1

Add a LUN to this target.

# tgtadm --lld iscsi --mode logicalunit --op new --tid=1 --lun=1 --device-type disk --backing-store=/dev/sdb

Allow the target to accept intitiators.

# tgtadm --lld iscsi --mode target --op bind --tid=1 --initiator-address=ALL

Show the iSCSI targets that are available.

# tgtadm --lld iscsi --mode target --op show
Target 1: rhce2:drive1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 12885 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
    Account information:
    ACL information:
        ALL
#

iSCSI Initiators

This section is the only part of the article that is actually relevant for the RHCE EX300 certification exam.

Install the necessary software to support iSCSI initiators.

# yum install iscsi-initiator-utils

Turn on the service and make sure it starts automatically after a reboot.

# service iscsi start
# chkconfig iscsi on

Check for iSCSI targets on the server presenting them. I configured the target on a machine called "rhce2.localdomain".

# iscsiadm --mode discoverydb --type sendtargets --portal rhce2.localdomain:3260 --discover
Starting iscsid:                                           [  OK  ]
192.168.0.191:3260,1 rhce2:drive1
#

Restart the iSCSI service.

# service iscsi restart
Stopping iscsi:                                            [  OK  ]
Starting iscsi:                                            [  OK  ]
#

The iSCSI device is now visible using the fdisk -l command.

# 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: 0x000819e0

   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/mapper/vg_rhce1-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 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: 0x00000000


Disk /dev/mapper/vg_rhce1-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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: 0x00000000


Disk /dev/sdb: 12.9 GB, 12884901888 bytes
64 heads, 32 sectors/track, 12288 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

#

Partition it and build a filesystem on it, as shown here and here. In this case I used the following commands.

# fdisk /dev/sdb
# mkfs.ext4 /dev/sdb1

Check the UUID of the new partition.

# blkid /dev/sdb1
/dev/sdb1: UUID="eac38663-e202-4920-b046-93b798db18b1" TYPE="ext4"
#

This UUID should be used for mounting the device, thus preventing problems if device names change. Create a new mount point.

# mkdir /rhce2_drive1

Add the following entry into the "/etc/fstab" file.

UUID="eac38663-e202-4920-b046-93b798db18b1"    /rhce2_drive1    ext4    defaults    0 0

Mount the device.

# mount /rhce2_drive1

The drive is now mounted and will be available on reboot.

For more information see:

Hope this helps. Regards Tim...

Back to the Top.