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.
[[email protected] ~]# 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 bytes or 4096 bytes, 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 its empty state to get it back here easily if you need to.
[[email protected] ~]# zfs snapshot zones/volumes/[email protected]
Enable STMF and iSCSI targets in the global zone
[[email protected] ~]# svcadm enable stmf [[email protected] ~]# 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).
[[email protected] ~]# stmfadm create-lu -p blk=4096 /dev/zvol/rdsk/zones/volumes/example Logical unit created: <GUID>
Add a view using the previously specified GUID.
[[email protected] ~]# 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.
[[email protected] ~]# itadm create-tpg <PORTAL GROUP NAME> <IP ADDRESS>
Create a target in this group
[[email protected] ~]# itadm create-target -t <PORTAL GROUP NAME> -n <TARGET NAME>
Where target name should be in the form of
- 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 issued 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.