CentOS / Red Hat Linux: Install and manage iSCSI Volume

Internet SCSI (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 Linux. It allows access to SAN storage over Ethernet.

Advertisement

Open-iSCSI Project

Open-iSCSI project is a high-performance, transport independent, multi-platform implementation of iSCSI. Open-iSCSI is partitioned into user and kernel parts.

Instructions are tested on:
[a] RHEL 5
[b] CentOS 5
Fedora 7
[d] Debian / Ubuntu Linux

Install Required Package

iscsi-initiator-utils RPM package – The iscsi package provides the server daemon for the iSCSI protocol, as well as the utility programs used to manage it. iSCSI is a protocol for distributed disk access using SCSI commands sent over Internet Protocol networks. This package is available under Redhat Enterprise Linux / CentOS / Fedora Linux and can be installed using yum command:
# yum install iscsi-initiator-utils

A note about Debian / Ubuntu Linux

If you are using Debian / Ubuntu Linux install open-iscsi package, enter:
$ sudo apt-get install open-iscsi

iSCSI Configuration

There are three steps needed to set up a system to use iSCSI storage:

  1. iSCSI startup using the init script or manual startup. You need to edit and configure iSCSI via /etc/iscsi/iscsid.conf file
  2. Discover targets.
  3. Automate target logins for future system reboots.
  4. You also need to obtain iSCSI username, password and storage server IP address (target host)

Step # 1: Configure iSCSI

Open /etc/iscsi/iscsid.conf with vi text editor:
# vi /etc/iscsi/iscsid.conf
Setup username and password:
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

Where,

  • 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)

You may also need to tweak and set other options. Refer to man page for more information. Now start the iscsi service:
# /etc/init.d/iscsi start

Step # 2: 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 192.168.1.5, enter:
# iscsiadm -m discovery -t sendtargets -p 192.168.1.5
# /etc/init.d/iscsi restart

Now there should be a block device under /dev directory. To obtain new device name, type:
# fdisk -l
or
# tail -f /var/log/messages
Output:

Oct 10 12:42:20 ora9is2 kernel:   Vendor: EQLOGIC   Model: 100E-00           Rev: 3.2
Oct 10 12:42:20 ora9is2 kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: 41963520 512-byte hdwr sectors (21485 MB)
Oct 10 12:42:20 ora9is2 kernel: sdd: Write Protect is off
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: drive cache: write through
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: 41963520 512-byte hdwr sectors (21485 MB)
Oct 10 12:42:20 ora9is2 kernel: sdd: Write Protect is off
Oct 10 12:42:20 ora9is2 kernel: SCSI device sdd: drive cache: write through
Oct 10 12:42:20 ora9is2 kernel:  sdd: unknown partition table
Oct 10 12:42:20 ora9is2 kernel: sd 3:0:0:0: Attached scsi disk sdd
Oct 10 12:42:20 ora9is2 kernel: sd 3:0:0:0: Attached scsi generic sg3 type 0
Oct 10 12:42:20 ora9is2 kernel: rtc: lost some interrupts at 2048Hz.
Oct 10 12:42:20 ora9is2 iscsid: connection0:0 is operational now

/dev/sdd is my new block device.

Step # 3: Format and Mount iSCSI Volume

You can now partition and create a filesystem on the target using usual fdisk and mkfs.ext3 commands:
# fdisk /dev/sdd
# mke2fs -j -m 0 -O dir_index /dev/sdd1

OR
# mkfs.ext3 /dev/sdd1

Tip: If your volume is large size like 1TB, run mkfs.ext3 in background using nohup:
# nohup mkfs.ext3 /dev/sdd1 &

Mount new partition:
# mkdir /mnt/iscsi
# mount /dev/sdd1 /mnt/iscsi

Step #4: Mount iSCSI drive automatically at boot time

First make sure iscsi service turned on at boot time:
# chkconfig iscsi on
Open /etc/fstab file and append config directive:
/dev/sdd1 /mnt/iscsi ext3 _netdev 0 0
Save and close the file.

Further readings:

๐Ÿฅบ Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! ๐Ÿค 
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

57 comments… add one
  • Maheswaran Aug 25, 2011 @ 17:49

    Thanks a lot. It works in Centos 6 and Fedora 14.

  • Hariz Jul 25, 2012 @ 10:08

    Hi, I do no what is iscsi configuration in rhel6 and could anyone help me…please

  • Bish Sep 20, 2012 @ 15:35

    The debian section is extraneous, if you believe the title (OR the URL, which doesn’t match in content).

  • Butch Jan 16, 2013 @ 15:27

    If you want to create and mount a volume larger than 2 TB use parted or gparted. Don’t use fdisk. Fdisk and the old style disk lables it creates can’t handle volumes larger than 2 TB.

    2TB and larger volumes have to be created with GPT (GUID Partition Table) labels. In trying to setup a 9TB storage volume with CentOS 6 this bit me pretty hard, as I wasn’t aware of that limitation in fdisk.

    Hope this helps someone out there.

  • Venkat Mar 3, 2013 @ 15:31

    How to add another iSCSI LUN ” Secondary iSCSI LUN” without restarting iSCSI Service.

  • Venkat Mar 3, 2013 @ 15:35

    How to add another iSCSI LUN รขโ‚ฌย Secondary iSCSI LUNรขโ‚ฌย without restarting iSCSI Service.

    If i restart the iscsi service with” service iscsi restart” to detect new lun the existing luns are getting unmounted and effecting running applications on the node.

    Please let me know if there is any process to resolve the issue.

    Thank you,
    Venkat

    • Whatisthis Sep 5, 2013 @ 12:16

      You need multipath in that case. Then restarting iscsi will not affect the mounts.

      This document is over 5 years old and is extremely badly written. I strongly suggest anyone not follow this or you will run into problems.

  • Habitual Jun 5, 2014 @ 19:32

    I can’t tell you how many times your site has saved my bacon in the last 5 years.

    Good Job and Well done.

  • karthikkumar Aug 2, 2016 @ 8:02

    i have assgin one lun for particular server and i used fdisk -l command but i view the 2 lun in the server thats is problem and then i have umount the lun and deleted the storage but i used fdisk -l command umount lun available in the same server.
    i added a new lun 100gb from storage dell md 3200i but customer need to 130gb so i used increase the option and extra 30 gb in particular lun but he take 4 hours.what is the solutions.

  • srikanth Sep 25, 2016 @ 11:26

    Yeah it’s good info tq… for the info
    But i have small query server shared a drive to client and client want to access but he don’t know the server name and ip in such cases how can we access that drive.

    Thanks advanced.

  • oscar Jun 10, 2017 @ 12:13

    Simple question:
    I have a iscsi correctly mounted on the PC 1, I would umont, logout and delete this target from PC1 (#log-out target iscsiadm –m node -T –portal 192.168.1.31:3260 -u #delete iscsiadm -m node –op delete –targetname ) and mount on other PC 2…. How do I do?
    If I follow your steps I have to format the iscsi (mkfs.ext3 /dev/sdb), but I wouldn’t, I would mount directly iscsi to PC 2 without format iscsi…
    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.