Saturday, April 28, 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

[root@test.com /]# 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:6.2.0.872-7.fc13 set to be installed
Finished Dependency Resolution
...
Installed:
  iscsi-initiator-utils.i686 0:6.2.0.872-7.fc13                                

Complete!

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


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

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



Step 3: Start Discovery Process

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


[root@test.com /]# iscsiadm -m node
169.254.1.2:3260,0 iqn.2010-10.test-iscsi:newvirtualdisk.1
192.168.0.227:3260,0 iqn.2010-10.test-iscsi:newvirtualdisk.1

Step 4: Log onto a iSCSI Target

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

Step 5: Partition, format and mount the iSCSI Target

[root@test.com /]# 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

[root@test.com /]# 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)
p
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.


[root@test.com /]# 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.


[root@test.com /]# mount /dev/sdb1 /mnt/iscsi
[root@test.com /]# cd /mnt/iscsi
[root@test.com 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

[root@test.com mnt]# cd /
[root@test.com /]# umount /mnt

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

[root@test.com /]# iscsiadm -m discovery --portal "192.168.0.227:3260" --op=delete

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

4 comments: