In our previous post, we have discsussed how to use our LVM partition as ISCSI LUN. Now we need to assign that lun to some server/initiator. Please follow below steps to attach the lun to the machine.
Client/Initiator:
Operating System: CentOS release 6.4
Hostname: client
IP Address: 192.168.1.6
Step 1: Install ISCSI initiator packages
[root@client ~]# yum install iscsi-initiator-utils.x86_64
Step 2: Initiator configuration setup
[root@client ~]# vi /etc/iscsi/iscsid.conf
#Uncomment and change this parameter
node.session.auth.authmethod = CHAP
node.session.auth.username = chapuser
node.session.auth.password = chappwd
Step 3: Discover the storage LUN
[root@client ~]# iscsiadm -m node -o show
# BEGIN RECORD 6.2.0-873.2.el6
node.name = iqn.2008-09.com.example:server.target1
node.tpgt = 1
node.startup = automatic
........
........
node.discovery_address = 192.168.1.5
node.discovery_port = 3260
node.discovery_type = send_targets
........
........
node.session.auth.authmethod = CHAP
node.session.auth.username = chapuser
node.session.auth.password = ********
........
........
node.conn[0].address = 192.168.1.5
node.conn[0].port = 3260
........
........
# END RECORD
[root@client ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.5 --discover
192.168.1.5:3260,1 iqn.2008-09.com.example:server.target1
Step 4: Add/Attach the LUN
[root@client ~]# iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2008-09.com.example:server.target1, portal: 192.168.1.5,3260] (multiple)
Login to [iface: default, target: iqn.2008-09.com.example:server.target1, portal: 192.168.1.5,3260] successful.
Now check your server, the new storage disk (/dev/sdb) is attached in the server.
[root@client ~]# fdisk -l | grep /dev
Disk /dev/sda: 8589 MB, 8589934592 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 1045 7875584 8e Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 3833 MB, 3833593856 bytes
Disk /dev/mapper/VolGroup-lv_swap: 4227 MB, 4227858432 bytes
Disk /dev/sdb: 104 MB, 104857600 bytes
Format and use the LUN
[root@client ~]# 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 0xb960394f.
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-1024, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1024, default 1024): +50M
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@client ~]# fdisk -l | grep /dev
Disk /dev/sda: 8589 MB, 8589934592 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 1045 7875584 8e Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 3833 MB, 3833593856 bytes
Disk /dev/mapper/VolGroup-lv_swap: 4227 MB, 4227858432 bytes
Disk /dev/sdb: 104 MB, 104857600 bytes
/dev/sdb1 1 513 51275 83 Linux
That’s all.. Cheers 🙂