How to setup iSCSI

reference: https://docs.oracle.com/cd/E23824_01/html/821-1459/fnnop.html#scrolltoc

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 192.168.216.128:3260

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 iqn.2010-08.org.illumos:02:4dd30d2c-dcab-62a2-f3f0-9357ff44a618
# 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 iqn.1991-05.com.microsoft:lp

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
NAME PROPERTY VALUE SOURCE
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 iqn.2010-08.org.illumos:02:4dd30d2c-dcab-62a2-f3f0-9357ff44a618

set CHAP secret
# itadm create-initiator -s iqn.1991-05.com.microsoft:lp

set CHAP username
# itadm modify-initiator -u mmm iqn.1991-05.com.microsoft:lp

# itadm list-initiator -v