As it turns out, it’s not very difficult! The FreeNAS web GUI makes it easy to enable iSCSI and set up a storage volume as an iSCSI target, and you can connect it via the ESXi web GUI using software iSCSI.
Keep reading to found out how to set up iSCSi for ESXi on FreeNAS. Leave a comment and let me know if it helped you out!
Step 1 – Enabling the iSCSI service in FreeNAS
First, connect to the FreeNAS Web GUI and log in. To enable the iSCSI service, navigate to Services and enable iSCSI, Start Automatically.
Step 2 – Creating a new storage volume to share
Navigate to Storage > Pools and click the … button next to the pool you want create the storage volume in. Take a note of how much space you have available, then select Add Zvol.
Then fill in the following:
- zvol name – the name of the volume you want to create.
- Comments – a description of what the volume will contain or be used for.
- Size for this zvol – How big a volume you want to create. (In KiB, MiB, GiB or TiB)
- Compression level – I recommend lz4 for a balance between speed and compression ratio.
- ZFS Deduplication – I recommend leaving this off because the cost/benefit is too low for home use.
Now click SAVE to create the new Zvol. After a short moment you should be returned to the Storage / Pools page and see the new Zvol has been created:
Step 3 – Setting up iSCSI to share the new volume
First we will create an iSCSI portal so ESXi has something to connect to. Navigate to the Sharing > Block (iSCSI) > Portals tab. Then click the ADD button.
Fill in the following:
- Comment – a description of the which network the portal is on or what it will be used for.
- IP Address – Enter the IP of an existing network interface that you want the portal to exist on. If you click the box it should expand to show you the currently available IPs.
- Port – The TCP port used to access the iSCSI target. The default is 3260.
Now click SAVE to create the portal. You should be returned to the Portals tab and your new portal should be listed and have a numerical Portal Group ID.
Next up, we need to create an Initiator to attach to the portal so it can initiate requests to and receive responses from iSCSI target(s). Navigate to the Initiators tab.
We want to define an initiator for our ESXi server, so click the ADD button, then fill in the following:
- Initiators – by default this is set to ALL, which will allow any host to connect to the iSCSI service. We’ll leave it set to ALL for initial setup, but for maximum security we will fill in the initiator node name (IQN) of the ESXi server later on.
- Authorized Networks – by default this is set to ALL, which allows any IP to connect to the iSCSI service. Leave it set to ALL for now and we will configure this later on.
- Comment – a description of what the initiator is for.
Now click SAVE to create the initiator. You should be returned to the Initiators tab and your new initiator should be listed and have a numerical Group ID.
Next up we need to create an iSCSI target using the portal and initiator we set up. Navigate to the Targets tab and click ADD.
- Target Name – a name for your target. You can use lowercase characters, dot, dash and colon.
- Target Alias – a user-friendly name
- Portal Group ID – Click to select the ID of portal group we created earlier.
- Initiator Group ID – Click to select the ID of the initiator group we created earlier.
Now click SAVE to create the target. You should be returned to the Targets tab and your new target should be listed.
Next we need to create an Extent connecting the Zvol to the iSCSI service. Click the Extents tab and click ADD.
Fill out the following fields:
- Extent name – The name of the extent. I called mine the same as the Zvol to avoid confusion.
- Extent type – Select Device to treat the whole Zvol as a disk / block device.
- Device – Click here to select the Zvol we created earlier.
Now click SAVE to create the extent. You should be returned to the Extents tab and your new extent should be listed and have been assigned a serial and an NAA.
Whew! Next we will associate the extent with the iSCSI target we created. Click the Associated Targets tab and click ADD.
Fill in the following fields:
- Target – Click here and select the target we created earlier.
- LUN ID – Enter a number between 0 and 1023. This is my first and only target, so I entered 0.
- Extent – Click to select the extent we just created.
Click SAVE to associate the extent with the target. You should be returned to the Associated Targets tab and see the newly available target.
Step 4 – Setting up an iSCSI adapter on the ESXi host
Log into the ESXi web GUI and select Storage > Adapters.
If you don’t have an existing iSCSI adapter set up, click Software iSCSI and set to Enabled. After a short while, the dialog should populate with iSCSI settings. Note your IQN next to Name & Alias.
By default, CHAP authentication is disabled. To keep things simple, I will not be covering it in this tutorial.
Beside Network Port Bindings click Add port binding and select an interface that will access your FreeNAS iSCSI portal.
Beside Dynamic targets. Click Add dynamic target and type in the IP and Port of the iSCSI target you set up in Freenas.
Finally click Save configuration.
If all went well, you should see a new iSCSI Software Adapter in the Adapters list. Select it and click Configure iSCSI to re-open the configuration dialog.
Beside Static targets you should now see the name of the target you created earlier:
Step 5 – Creating a new VMFS datastore on the iSCSI volume
Click the Datastores tab and click New datastore to open the wizard.
Select Create new VMFS datastore and click Next
Type a name for the new datastore and select the FreeNAS iSCSI Disk you connected. Then click Next.
Select the partitioning options you would like. In my case I am using the full disk (Zvol) I set up. Then click Next.
Review the summary then click Finish.
You will receive a warning that ESXi will erase and replace the disk. This is safe because we set up a brand new Zvol. Click Yes.
If all went well, you should see the new datastore is now available for your ESXi server to use.
Congratulations! You have successfully set up iSCSi on FreeNAS and connected your ESXi host to it. You can start uploading some disk images, set up some virtual machines, or back everything up! But first, why don’t we make things more secure?
Step 6 – Making the iSCSI target more secure
To make things more secure, head back into the FreeNAS web GUI and navigate to the Sharing > Block (iSCSI) > Initiators tab. Click … > Edit next to the iSCSI initiator we created earlier.
Under Initiators replace ALL with the IQN of the ESXi host’s iSCSI adapter.
Under Authorized Networks replace ALL with the IP of the ESXi host’s iSCSI interface.
Click SAVE to return to the Initiators page. You should see it has been updated.
Finally, return to ESXi and and try to create a new folder via the Datastore Browser to verify that you didn’t bork the connection.
Caveat – Normal, Degraded device status
I haven’t figured out why yet, but the iSCSI Disk shows as Normal, Degraded under the Devices tab. If anyone knows why, please leave a comment!
If you have only set up a single path to the iSCSI target, it will show as Normal, Degraded status in ESXi. The solution is to set up a second VMkernel NIC and vSwitch to provide a redundant path. More info here: https://www.ixsystems.com/community/threads/esxi-6-5-iscsi-zvol-share-immediately-shows-normal-degraded-in-vsphere.55068/