Archive for Linux

How to configure an iSCSI target that supports the SCSI-3 Persistent Reservation

Posted in Do it yourself with tags , , , , , , , , , , , , on June 7, 2012 by smurariu

Why in God’s Green Earth might I want to do that?

Well, a very good question. The reason you might consider configuring an iScsi-3 target is because that’s the only way you will be able to configure a Failover Cluster and Cluster Shared Volumes. This is a prerequisite if you want to be able to run virtual machines using Hyper-V and take advantage of the Live Migration feature.

The Live Migration feature basically allows you to have a number of nodes (read separate servers) running virtual machines and transparently move the execution of a virtual machine between these nodes without loosing as much as a single ping. Yep, you read that correctly, the wonders of modern technology, eh?

You may want to do that for any number of reasons including powering off a server for upgrades or maintenance, adding more servers to meet rising demands in your organization, etc. I’m sure you can think of many more.

Will it involve using Linux?

Yes it will. Either that, or blowing a fortune on a SAN device that knows how to do this, SAN device that most likely will run… Linux.

Will it hurt?

It could but if you follow this guide all should go smoothly.

Setting it up

You need a server that will act as your iScsi-3 target. The hardware requirements of this server are your call, given that they need to meet the specific speed and redundancy requirements of your particular situation. I personally recommend using CentOS because it is as close to an Enterprise Linux as you can ever be.

Let’s assume that your Linux box is up and running, your kernel is at least @ version 2.6.38, and that your raid controller is now showing up as /dev/sdb

All the commands you’ll need are the following:

/etc/init.d/target start
tcm_node –block iblock_0/my_iblock0 /dev/sdb
lio_node –addlun iscsi-test 1 1 lun_my_block iblock_0/my_iblock0
lio_node –addnp iscsi-test 1 10.0.0.1:3260
lio_node –disableauth iscsi-test 1
lio_node –enableaclmode iscsi-test 1
lio_node –addlunacl iscsi-test 1 iqn.1998-01.com.vmware:vlvstest02-4b466a50 1 1
lio_node –enabletpg iscsi-test 1
tcm_dump –t 2011-09-22_BASE
lio_dump –t 2011-09-22_BASE
tcm_dump –o

In red you have the points that might require changing to match your particular setup but otherwise, it does not get much easier than this, trust me. Even so, there are a number of things that need to be understood about the commands above so let’s go through them one by one:

/etc/init.d/target start

It’s clear that this one just starts the service up. This is a service that does not support chkconfig so don’t try setting it up as a startup service in this way. Instead you should chkconfig lio-target on.

tcm_node –block iblock_0/my_iblock0 /dev/sdb

This step just creates a block device (there are other kinds of devices available, flat file is one of them). Note the /dev/sdb that is the device you want to be using for block storage. If you’re using a different one, update this value.

We will now proceed to add a iSCSI Target Logical Unit (LUN) to this block and name it lun_my_block. Of course you can name it whatever you like but the name of the block needs to be the one you set in the previous command (iblock_0/my_iblock0 in our case).

lio_node –addlun iscsi-test 1 1 lun_my_block iblock_0/my_iblock0

Once we have the lun, we need to configure the network portal where it will be exposed:

lio_node –addnp iscsi-test 1 10.0.0.1:3260

It is recommended that you have a separate network card that’s to be reserved entirely for iSCSI operations. If you do than use the ip address of this card. If not, the ip of eth0 will do as well.

The following commands disable the CHAP authentication and enable ACLs as security mechanism:

lio_node –disableauth iscsi-test 1
lio_node –enableaclmode iscsi-test 1

Once that is in place we need to specify what specific iSCSI Initiators are allowed to connect to our precious LUN:

lio_node –addlunacl iscsi-test 1 iqn.1998-01.com.vmware:vlvstest02-4b466a50 1 1

In this command the [iqn.1998-01.com.vmware:vlvstest02-4b466a50] part is the iSCSI Initiator Name. What is this and where do you get one? This is command actually says that only the machine with this initiator name will have access to our iScsi target. You can add multiple ACLs, one for each machine that you want to allow to access the resource. The iSCSI Initiator name can be found on the Windows machines by opening up the iSCSI Initiator dialog, going to the Configuration tab (the last one)  and copying the value you find in the Initiator Name text box.

In the case of Windows machines this is by default set to “iqn.1991-05.com.microsoft:ComputerName“. If your computer name is HyperV-Node1 the default iSCSI Initiator name would be iqn.1991-05.com.microsoft:HyperV-Node1.

If you need to have 4 nodes accessing this storage device you would have the following list of commands:

lio_node –addlunacl iscsi-test 1 iqn.1991-05.com.microsoft:HyperV-Node1 1 1
lio_node –addlunacl iscsi-test 1 iqn.1991-05.com.microsoft:HyperV-Node2 1 1
lio_node –addlunacl iscsi-test 1 iqn.1991-05.com.microsoft:HyperV-Node3 1 1
lio_node –addlunacl iscsi-test 1 iqn.1991-05.com.microsoft:HyperV-Node4 1 1

All that out of the way, your 4 HyperV nodes will be able to access the iSCSI target and do Live Migration between them.

Wrapping things up we have to enable TPG (Target Portal Group) on the iSCSI target:

lio_node –enabletpg iscsi-test 1

Backup the config to /etc/target/backup:

tcm_dump –t 2011-09-22_BASE
lio_dump –t 2011-09-22_BASE

And set the current configuration as the startup one:

tcm_dump –o

That’s all folks!

You should now check your config by executing /etc/init.d/target status then rebooting the machine and making sure the configuration is loaded correctly at startup. Additionally you could check the /etc/target/lio_start.sh and /etc/target/tcm_start.sh files and see if the correct configuration information is present.

Credits go to Roberto La Verde for his indications and guidelines.