Prerequisites

 

  • XCP/Xenserver
  • Access to Internet

 

Update: June 2nd, 2014 - I changed most of the tgtadm long format options to short format due to my not being able to remember the long format. For some reason --lld didn't seem like a valid option. I did however keep --lun and --backing-store.

Creating an iSCSI target on Xen Cloud Platform 1.1

Premise: I have two pools – The first has one host in it that acts as a router, firewall and Host for a couple of special VMs for (DNS, DHCP, NFS, Web) the hosts in a second pool. I've added iSCSI SAN to it's lists of jobs using a software iSCSI target in the 8 steps below.

 

1. Install tgt from CentOS repos

yum --enablerepo=base install scsi-target-utils

2. Start the tgt service

service tgtd start

chkconfig tgtd on

3. Preparing for LVM

 

I'm using a separate hard drive - /dev/sdb and creating one partition which will be used as my LVM Physical Volume. We'll then add it to the Volume Group and carve it up into Logical Volumes. This way I can just add another hard drive to the Volume Group when we want more capacity and the rest of the tutorial stays the same. The bold letters are what I input, I accepted the defaults everywhere else.

 

[root@cloud0 ~]# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 240.0 GB, 240057409536 bytes

255 heads, 63 sectors/track, 29185 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

Device Boot Start End Blocks Id System

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-29185, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-29185, default 29185):

Using default value 29185

Command (m for help): t

Selected partition 1

Hex code (type L to list codes): 8e

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdb: 240.0 GB, 240057409536 bytes

255 heads, 63 sectors/track, 29185 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdb1 1 29185 234428481 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

This gives me a new partition - /dev/sdb1. Now lets create the Logical Volumes to be shared out via iSCSI.

 

pvcreate /dev/sdb1

vgcreate VG_iSCSI /dev/sdb1

vgs

VG #PV #LV #SN Attr VSize VFree

VG_XenStorage-19756537-a3bc-5c1f-edfc-01bc47ddf5d8 1 8 0 wz--n- 923.50G 354.21G

VG_iSCSI 1 0 0 wz--n- 223.57G 223.57G

4. Creating a Logical Volume

lvcreate -L 223G –name iSCSI_disk1 VG_iSCSI

lvs

LV VG Attr LSize Origin Snap% Move Log Copy% Convert

MGT VG_XenStorage-19756537-a3bc-5c1f-edfc-01bc47ddf5d8 -wi-a- 4.00M

iSCSI_disk1 VG_iSCSI -wi-a- 223.00G

 

5. List active targets

tgtadm -L iscsi -m target -o show

 

6. Create a new target device

tgtadm -L iscsi -m target -o new -t 1 -T iqn.2012-09.edu.edcc:disk1

 

7. Add a logical unit (LUN)

 

tgtadm -L iscsi -m logicalunit -o new -t 1 --lun=1 --backing-store=/dev/VG_iSCSI/iSCSI_disk1 

To add more units repeat step 4 by incrementing the LV --name (iSCSI-disk1) and step 6 by changing the --lun number and --backing-store parameter to add more LUNs.

For example:

 

lvcreate -L 10G --name iSCSI-disk2 VG_iSCSI

tgtadm -L iscsi -m logicalunit -o new -t 1 --lun=2 --backing-store=/dev/VG_iSCSI/iSCSI_disk2

 

 

In case you mess it up and want to delete the LUN and Target

 

 

tgtadm -L iscsi -m logicalunit -o delete -t 1 --lun=1

tgtadm -L iscsi -m target -o delete –t 1 

 

 

 

8. Setting up Access Control

We're going to allow all iSCSI initators to connect. This is not very secure so if you want to limit this you'll want to do it here. You can limit by IP address range or network. You can also set up CHAP authentication.

tgtadm -L iscsi -m target -o bind -t 1 -I ALL

 

9. Creating the Software iSCSI Storage Repository

Log into your Pool Master using ssh and run xsconsole. Choose Disks and Storage Repositories then Create New Storage Repository. When prompted type in the root users name and password then select Software iSCSI. You can name it anything you want and provide a description too. The only field you really need is the Hostname or iSCSI Target field. Put in the IP or Hostname of your iSCSI Target and hit enter to let it probe the iSCSI target. It will show you a list of LUNs, choose the one you want and press F-8. This will create the storage repository. It may also make it default which you may not want.

 

10. Change the default storage repository

In my case I wanted to use the new iSCSI SAN as additional drives and not my default SR. When you use xsconsole to create the Storage Repository it also makes it default. To make a different SR default follow these instructions. If you want the iSCSI SR to be default skip this step.

Get the pool UUID, get the SR UUID then set it default.

 

[root@cloud1 ~]# xe pool-list

uuid ( RO) : a8cff715-6ff7-a01f-b7a3-7ad3b158df71

name-label ( RW):

name-description ( RW):

master ( RO): 47c0e22c-eac9-444d-a4b1-d958f0ab60cf

default-SR ( RW): 36bf480a-5df9-4453-50f0-2bac4a86cb42

 

 

[root@cloud1 ~]# xe sr-list

uuid ( RO) : 36bf480a-5df9-4453-50f0-2bac4a86cb42

name-label ( RW): Local storage

name-description ( RW):

host ( RO): cloud1.acs.edcc.edu

type ( RO): lvm

content-type ( RO): user

 

xe pool-param-set default-SR=36bf480a-5df9-4453-50f0-2bac4a86cb42 uuid=a8cff715-6ff7-a01f-b7a3-7ad3b158df71

 

Now you a software iSCSI Target on XCP 1.1, a disk that's shared out via iSCSI and a Software Repository that uses it.