Linux iSCSI HowTo

From Nonecks Docs

Jump to: navigation, search

Contents

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
  • and for Debian/Ubuntu:
$ 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.
    1. You also need to obtain iSCSI username, password and storage server IP address (target host)

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

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 10.0.1.4, enter:
# iscsiadm -m discovery -t sendtargets -p 10.0.1.4
# /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:

Jul 14 17:46:02 pig kernel:   Vendor: FreeBSD   Model: iSCSI DISK        Rev: 0001
Jul 14 17:46:02 pig kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Jul 14 17:46:02 pig kernel: SCSI device sdb: 1465192448 512-byte hdwr sectors (750179 MB)
Jul 14 17:46:02 pig kernel: sdb: Write Protect is off
Jul 14 17:46:02 pig kernel: SCSI device sdb: drive cache: write back
Jul 14 17:46:02 pig kernel: SCSI device sdb: 1465192448 512-byte hdwr sectors (750179 MB)
Jul 14 17:46:02 pig kernel: sdb: Write Protect is off
Jul 14 17:46:02 pig kernel: SCSI device sdb: drive cache: write back
Jul 14 17:46:02 pig kernel:  sdb: unknown partition table
Jul 14 17:46:02 pig kernel: sd 5:0:0:0: Attached scsi disk sdb
Jul 14 17:46:02 pig kernel: sd 5:0:0:0: Attached scsi generic sg2 type 0
Jul 14 17:46:02 pig iscsid: transport class version 2.0-724. iscsid version 2.0-868
Jul 14 17:46:02 pig iscsid: iSCSI daemon with pid=20223 started!
Jul 14 17:46:02 pig iscsid: received iferror -38
Jul 14 17:46:02 pig last message repeated 2 times
Jul 14 17:46:02 pig iscsid: connection1:0 is operational now

/dev/sdb is my new block device.

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/sdb
# mke2fs -j -m 0 -O dir_index /dev/sdb1

OR

# mkfs.ext3 /dev/sdb1
  • Tip: If your volume is large size like 1TB, run mkfs.ext3 in background using nohup:
# nohup mkfs.ext3 /dev/sdb1 &
  • Mount new partition:
# mkdir /mnt/iscsi
# mount /dev/sdb1 /mnt/iscsi

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/sdb1 /mnt/iscsi ext3 _netdev 0 0
  • Save and close the file.