Sunday, April 29, 2012

Mounting iSCSI Luns on Linux Hosts

Adding iSCSI Storage to a Linux Computer
This article describes mounting iSCSI luns from SAN iSCSI targets to Linux hosts. Please make sure that an iSCSI Target has been created and ready for use in theSAN / NAS targets. 

Step 1: Install the iSCSI Initiator Software

[ /]# yum install iscsi-initiator-utils
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
Running transaction check
Package iscsi-initiator-utils.i686 0: set to be installed
Finished Dependency Resolution
  iscsi-initiator-utils.i686 0:                                


Things you need to have before setting up the iSCSI mounts.
  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 2: Edit the iscsi.conf file

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

  • 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)
Make sure iscsi.conf 'node' parameter is set for Automatic
[ /]# vi /etc/iscsi/iscsid.conf
node.startup = automatic

Now start the iscsi service:
# /etc/init.d/iscsi start

Step 3: Start Discovery Process

[ /]# iscsiadm -m discovery -t st -p
Starting iscsid:                                           [  OK  ],0 iqn.2010-10.test-iscsi:newvirtualdisk.1,0 iqn.2010-10.test-iscsi:newvirtualdisk.1

[ /]# iscsiadm -m node,0 iqn.2010-10.test-iscsi:newvirtualdisk.1,0 iqn.2010-10.test-iscsi:newvirtualdisk.1

Step 4: Log onto a iSCSI Target

[ /]# iscsiadm -m node --targetname "iqn.2010-10.test-iscsi:newvirtualdisk.1" --portal "" --login
Logging in to [iface: default, target: iqn.2010-10.test-iscsi:newvirtualdisk.1, portal:,3260]
Login to [iface: default, target: iqn.2010-10.test-iscsi:newvirtualdisk.1,
portal:,3260] successful.

Step 5: Partition, format and mount the iSCSI Target

[ /]# fdisk -l

Disk /dev/sdb: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 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 doesn't contain a valid partition table

[ /]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6eae1b66.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-19581, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-19581, default 19581):
Using default value 19581

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[ /]# mkfs.ext3 /dev/sdb1
mke2fs 1.41.10 (10-Feb-2009)
Filesystem label=
OS type: Linux
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

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

[ /]# mount /dev/sdb1 /mnt/iscsi
[ /]# cd /mnt/iscsi
[ iscsi]# ls -l
total 16
drwx------. 2 root root 16384 Oct 29 12:16 lost+found

Step 5 : Automatically mount the iSCSI drive 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

How to unmount the iSCSI Target and stop iSCSI discovery of the iSCSI Targets/Luns

[ mnt]# cd /
[ /]# umount /mnt

[ /]# iscsiadm -m node --targetname" "iqn.2010-10.test-iscsi:newvirtualdisk.1" --portal" "" --logout
Logging out of session [sid: 1, target: iqn.2010-10.test-iscsi:newvirtualdisk.1, portal:,3260]
Logout of [sid: 1, target: iqn.2010-10.test-iscsi:newvirtualdisk.1, portal:,3260] successful.

[ /]# iscsiadm -m discovery --portal "" --op=delete

Hope this helps. We shall see how to create simple iSCSI Targets in Linux Boxes itself in next post.