iSCSI Target on SmartOS

As a home user of SmartOS, I often time find myself using the operating system in ways not officially documented or endorsed by Joyent.

One such use involved a project investigating the feasibility of using ZFS ZVOLs hosted on a SmartOS global zone to back the system volume of my Windows 7 desktop. The initial configuration made use of Sun COMSTAR (that is thankfully still in SmartOS) to present an iSCSI target to my desktop over gigabit ethernet. Having never really used iSCSI before, this was a learning experience. I often times find myself neck deep in the Oracle Solaris 11 documentation, and that just makes me want to take a shower. There is also some excellent community documentation available as well, but here is a simple recipe to get Sun COMSTAR (COmmon Multiprotocol Scsi TARget) hosting iSCSI targets in a SmartOS global zone.

Note: There is no facility to maintain the COMSTAR state within a SmartOS global zone, so everything detailed here will need to be re-created after each reboot. Just an FYI for now...

First, create one or more ZVOLs that will be backing your exported LUNs.

[root@gz ~]# zfs create -sV 2T -b 4096 zones/volumes/example

The block size should ideally be the native block size of your underlying drives, either 512 byte or 4096 byte, to ensure good read and write performance. iSCSI will default to 512 byte blocks. Since we're using modern disks, we'll be using 4K blocks in our example.

Optionally snapshot the ZVOL in it's empty state to get it back here easily if you need to.

[root@gz ~]# zfs snapshot zones/volumes/example@empty

Enable STMF and iSCSI targets in the global zone

[root@gz ~]# svcadm enable stmf
[root@gz ~]# svcadm enable iscsi/target

Create a logical unit using stmfadm. Note that if you specify a block size of 4096 bytes, you will need an operating system that can use that (Windows 7 is not such an operating system).

[root@gz ~]# stmfadm create-lu -p blk=4096 /dev/zvol/rdsk/zones/volumes/example
Logical unit created: <GUID>

Add a view using the previously specified GUID.

[root@gz ~]# stmfadm add-view <GUID>

Create a target portal group and assign an identifier name. This name represents the portal group, and not necessarily an individual iSCSI target. This is likely not necessary, but may be sensible to ensure consistent target accessibility.

[root@gz ~]# itadm create-tpg <PORTAL GROUP NAME> <IP ADDRESS>

Create a target in this group

[root@gz ~]# itadm create-target -t <PORTAL GROUP NAME> -n <TARGET NAME>

Where target name should be in the form of iqn.YYYY-MM.org.illumos:NN:SSSSSSS

  • YYYY = 4 digit year
  • MM = 2 digit month
  • NN = 2+ digit 0 padded integer
  • SSSSSSS = variable length name

If no target portal group was created, this last command can instead be issues omitting the portal group name, and even omitting the target name if access consistency isn't a requirement.

This recipe is rough, and is subject to modification. The plan is to move on to see how well ibsrp/target works. I also need to figure out how to get Windows 10 to install to/boot from iSCSI, as it didn't for me out of the box.