Skip to content

Instantly share code, notes, and snippets.

@mattconnolly
Created May 19, 2014 12:10
Show Gist options
  • Save mattconnolly/e188fdb1049872ec428d to your computer and use it in GitHub Desktop.
Save mattconnolly/e188fdb1049872ec428d to your computer and use it in GitHub Desktop.
setup iscsi share on smartos
#!/bin/bash -x
# based on: http://superuser.com/questions/386506/hosting-iscsi-on-smartos
GROUPNAME=iscsi-1
TARGETNAME=iqn.2010-08.org.illumos:02:$GROUPNAME
LOCAL_ADDRESS=192.168.1.2
svcadm enable stmf
svcadm enable -r svc:/network/iscsi/target:default
sbdadm create-lu /dev/zvol/rdsk/zones/iscsi-1
GUID=$(sbdadm list-lu | tail -n 1 | cut -f1 -d' ')
stmfadm add-view $GUID
itadm create-tpg "$GROUPNAME" $LOCAL_ADDRESS
itadm create-target -t "$GROUPNAME" -n $TARGETNAME
@mattconnolly
Copy link
Author

I haven't yet found a way for this to run automatically on a system boot...

@tonykempton
Copy link

Hi matt.
Did you eventually solve the iscsi startup, as I have been struggling with this.
Regards tony

@paladine-raistlin
Copy link

cat /opt/custom/share/svc/smartos_setup.sh

!/bin/bash

Simple Ad Hoc SmartOS Setup Service

set -o xtrace
. /lib/svc/share/smf_include.sh
cd /
PATH=/usr/sbin:/usr/bin:/opt/custom/bin:/opt/custom/sbin; export PATH
case "$1" in
'start')
#### Insert code to execute on startup here.
cp /opt/custom/init /etc/default/init
hostname "store" && hostname > /etc/nodename
rtc -z US/Eastern
GROUPNAME=store
TARGETNAME=iqn.2010-08.org.illumos:02:$GROUPNAME
LOCAL_ADDRESS=192.168.0.90
svcadm enable stmf
svcadm enable -r svc:/network/iscsi/target:default
sbdadm create-lu /dev/zvol/rdsk/zones/iscsi
GUID=$(sbdadm list-lu | tail -n 1 | cut -f1 -d' ')
stmfadm add-view $GUID
itadm create-tpg "$GROUPNAME" $LOCAL_ADDRESS
itadm create-target -t "$GROUPNAME" -n $TARGETNAME
;;
'stop')
### Insert code to execute on shutdown here.
;;
*)
echo "Usage: $0 { start | stop }"
exit $SMF_EXIT_ERR_FATAL
;;
esac
exit $SMF_EXIT_OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment