How to setup iSCSI


iSCSI target

apt-get install network-iscsi-target

iSCSI initiator

apt-get install network-iscsi-initiator

enable services

enable services
# svcadm enable stmf
# svcadm enable iscsi/target

reboot host 
# reboot

create new pool
# zpool create pool01 c2t1d0

create new volume
# zfs create -V 100m pool01/iscsi

create LUN on volume
# stmfadm create-lu /dev/zvol/rdsk/pool01/iscsi

show LUN
# stmfadm list-lu

add view to newly created LUN
# stmfadm add-view 600144F03431771000005A8ADFD40001

show view properties
# stmfadm list-view -l 600144F03431771000005A8ADFD40001

create iSCSI target
# itadm create-target

show all targets
# itadm list-target -v

--- access restrisction ---
remove unnecessary views for specific LUN
# stmfadm remove-view -l 600144F03431771000005A8ADFD40001 -a

create target portal group (TPG) - set addresses and ports for iSCSI target service listner
# itadm create-tpg iscsi01

create target group
# stmfadm create-tg iscsi-tg01

add target to group, one target can be only one group member
# svcadm disable stmf:default
# stmfadm add-tg-member -g iscsi-tg01
# svcadm enable stmf:default

create host group(HG) and add members - clients list, who can see LUNs
# stmfadm create-hg iscsi-hg01
# stmfadm add-hg-member -g iscsi-hg01

list created objects
# stmfadm list-lu -v
# sbdadm list-lu
# stmfadm list-tg
# stmfadm list-hg

create new view
# stmfadm add-view -t iscsi-tg01 -h iscsi-hg01 600144f03431771000005a8adfd40001
# stmfadm list-view -l 600144f03431771000005a8adfd40001
View Entry: 0
Host group : iscsi-hg01
Target group : iscsi-tg01
LUN : 0

--- add LUN to target ---
# zfs create -V 2g tank/zvol2
# stmfadm create-lu /dev/zvol/rdsk/tank/zvol2
# stmfadm list-lu -v
# sbdadm list-lu
# stmfadm add-view -t iscsi-tg01 -h iscsi-hg01 600144F03431771000005A8AF67B0002

--- expand LUN (dataset) ---
# zfs get volsize pool01/iscsi
pool01/iscsi volsize 100M local

# zfs set volsize=150m pool01/iscsi

# stmfadm list-lu -v
LU Name: 600144F03431771000005A8ADFD40001
Operational Status: Online
Provider Name : sbd
Alias : /dev/zvol/rdsk/pool01/iscsi
View Entry Count : 1
Data File : /dev/zvol/rdsk/pool01/iscsi
Meta File : not set
Size : 104857600
Block Size : 512
Management URL : not set
Vendor ID : SUN
Product ID : COMSTAR
Serial Num : not set
Write Protect : Disabled
Writeback Cache : Disabled
Access State : Active

# sbdadm modify-lu -s 150m 600144F03431771000005A8ADFD40001

--- using CHAP (unidirectional) ---
enable CHAP authentication for specific target
# itadm modify-target -a chap

set CHAP secret
# itadm create-initiator -s

set CHAP username
# itadm modify-initiator -u mmm

# itadm list-initiator -v