François-Xavier Cat

I recently switched the backend storage of my VMware vSphere 5.1 Home Lab from FreeNas (OS based on UNIX) to iSCSI (Windows Server 2012 Storage Feature). The reason is that I wanted to play with the PowerShell iSCSI modules and do some tests with SMB v3.0.

LUN:A Logical Unit Number (LUN) is a unique identifier used to designate individual or collections of hard disk devices for address by a protocol associated with a SCSI, iSCSI, Fibre Channel (FC) or similar interface. LUNs are central to the management of block storage arrays shared over a storage area network (SAN).
VMFS:VMwareÂ® vStorageVirtualMachineFileSystem (VMFS) is a high-performance cluster file system that provides storage virtualization optimized for virtual machines.It is a prerequisite when you wish build your virtual infrastructure using vmware, as default storing system for virtual machine files on shared storage as Fibre Channel and iSCSI SAN disks and partitions. The current version of VMFS is VMFS 5.

Using POWERCLI

Configuring the iSCSI Initiator on VMware vSphere 5.1 (PowerCli)

Pre-requisites
In order to work with the PowerCli cmdlets, you will need to load the PowerShell Snapin VMware.VimAutomation.Core.
```
# Load PowerCli Cmdlets
Add-PSSnapin VMware.VimAutomation.Core
# Connect to my VMware vCenter or your VMware host
# I will get prompted for Credential
Connect-VIServer lab1vh02.fx.lab -Credential (Get-Credential)
```
```

Turn On the iSCSI Initiator
To be able to connect to the iSCSI Target Server and see the target, you will need to enable the iSCSI Software Adapter on each of your host
```
```
# Turn on the iSCSI Initiator on my VMware vSphere host (lab1vh02.fx.lab)
Get-VMHostStorage -VMHost lab1vh02.fx.lab | Set-VMHostStorage -SoftwareIScsiEnabled $True
```
```
```
```
```
```

Refresh HBA / Rescan Datastore
Finally you will need to rescan the HBA and VMFS volumes in order to be able to add the new datastore(s).
```
```
# Performs a Rescan on all HBAs and VMFS volumes
Get-VMHostStorage -VMHost lab1vh02.fx.lab -RescanAllHba
Get-VMHostStorage -VMHost lab1vh02.fx.lab -RescanVmfs
```
### Creating a new Datastore on the presented iSCSI LUN (PowerCli)

Find the Lun Canonical Name
```
To create a datastore using the New-Datastore cmdlet you will need to get the CanonicalName property from the Lun you want to use.
```
```
```
```
# Get the iSCSI LUN presented to this server where Microsoft is the vendor
Get-ScsiLun | Where-Object Vendor -like "MSFT"
```
```
# Get only the Lun and store it in the $lun variable
$lun = Get-ScsiLun | Where-Object {(($_.Vendor -like "MSFT") -and ($_.CapacityGB -eq 10))}
```
```
```
```

Create the new Datastore
# Finally create the datastore using the Lun
```
```
New-Datastore -Vmfs -Path $lun.CanonicalName -Name Lun1
```
Note: Using the GUI you cannot create datastore smaller than 1.3 GB (You'll see the error a bit later in this post). However with PowerCli YOU CAN !!!Anyway it's kind of useless to have a datastore as small as 1GB...
### Using the GUI/VMware vSphere Client
### Configuring the iSCSI Initiator on VMware vSphere 5.1

1 - On your VMware Host, select the tab Configuration, Storage Adapters and click on Add...
2 - Here leave the "Add Software iSCSI Adapter" option and click OK3 - A warning message will show, click OK :
"A new software iSCSI adapter will be added to the Storage Adapters list. After it had been added, select the software iSCSI adapter in the list and click on Properties to complete the configuration."

You'll see the following message while the Software iSCSI Adapter is being added...

Once added, you'll see the iSCSI Software Adapter with the iSCSI IQN of this server

4 - Right click on it and select Properties5 - You'll see the message "A rescan of the host bus adapter is recommended for this configuration change. Rescan the adapter?". Click Yes

You'll see the above activities in the vsphere client activities window.

In the detail window, you will see the LUN we created on Windows Server 2012.

Note: When we created the Virtual Disk/LUN, we could specify a LUN ID, this would show here.

### Creating a new Datastore on the presented iSCSI LUN
In my previous post I created a 1GB Lun which was too small for the following procedure.
If you do, you'll get the following error message on the final step. Towork-around this problem, use PowerCli ! Refer to "Creating a new datastore" above in this post.

Error: The Capacity value must be at least 1.3 GB. Enter another value.
So I used a 10GB LUN for the following steps...
1 - In the Configuration tab of your VMware host, select Storage and Click on Add Storage
2 - In the Add Storage Wizard, select Disk/Lun and click Next
3 - Select a Disk/LUN to create a datastore, here I select my 10GB lun. Click Next.
4 - Specify the version of the VMFS for the datastore. Select VMFS-5 and click Next.
Note: The table below depicts the most significant architectural changes for VMFS-5 in comparison to VMFS-3.