Windows Server – Setting up iSCSI Target and Initiators v.1
Setting up an iSCSI Target and iSCSI Initiator via PowerShell or GUI in Windows Server.
Setting Up iSCSI Target via PowerShell
Log into the server that will be hosting our storage and open PowerShell. Once in PowerShell, run the following command to install the iSCSI Target Windows Feature:
Install-WindowsFeature FS-iSCSITarget-Server
You will need a target Partition already online and ready before we can create a new iSCSI Virtual Disk. On the device we are doing to use for iSCSI storage, run the following PowerShell cmdlet:
Get-Disk
Using the number of the disk that we are going to use add that to the initialize-disk PowerShell cmdlet.
Initialize-Disk –Number 1 –PartitionStyle GPT
Next we need to partition this new drive. Using Disk 1, we are going to assign it the drive letter of V and use the maximum drive size for our new partition. Use the following PowerShell cmdlet to accomplish this.
New-Partition –DiskNumber 1 –DriveLetter V -UseMaximumSize
Now we will format our volume V as NTFS. Use the following PowerShell cmdlet to complete this step:
Format-Volume –DriveLetter V –FileSystem NTFS –Confirm:$false
With the new partition created, we can now create the iSCSI Virtual Disk. We are going to put it on the V drive in the folder iSCSIVirtualDisks and give it a size of 20 GB.
New-IscsiVirtualDisk –Path V:\iSCSIVirtualDisks\LUN-2.vhdx -Size 20GB
Next, we are going to need to get some information from on our devices that is going to be using the iSCSI storage. On that device, log in and run the follow command in PowerShell:
(Get-InitiatorPort).NodeAddress
All three of them are the same in this example, so get down this information and log back into our iSCSI storage server.
Using that information, we will now target each of our devices that will be using the iSCSI storage. Using the name lun2 and the InititatorIDs that we gathered in the previous step, run the following PowerShell cmdlet
New-IscsiServerTarget lun2 –InitiatorIDs $InitIDs
Next we will need to map the Target Disk and the iSCSI Virtual Disk. Gathering together the Target Name of the LUN as well as the path used for the VHDX, running this PowerShell cmdlet
Add-IscsiVirtualDiskTargetMapping –TargetName lun2 –Path V:\iSCSIVirtualDisks\LUN-2.vhdx -Size 20GB
On our target server we have one last step. That is to map the VHDX to our iSCSI destination device. Ensure that you give the –Lun parameter a unique ID.
Setting up iSCSI Target via GUI
Log in to a Server you will be using to manage this process (with GUI and Server Manager). If you haven’t already, add the server we are going to use for storage.
You will then need to install the iSCSI Target Server feature on that server. Checking this box will also check the File Server feature box as well.
Once that is completed, reboot the target server.
You will need a target Partition already online and ready. Should you need to create one, please use Computer Management or Server Manager and set one up before proceeding on the target server.
When it is back online, Open Server Manager go to File and Storage Services > iSCSI.
Click on the Tasks drop down and select New iSCSI Virtual Disk.
Now select the volume to use. This is the volume that you may have setup as a previous step above.
Give it a name and a description. Note the path this will be stored on.
Give the new iSCSI Virtual Drive a size. In our case, we are going to use 200 GB of this space to create our iSCSI Virtual Disk and make it Dynamically expand based on usage.
Attach it to a LUN or create a new iSCSI Target. In this case we are going to attach it to a New iSCSI target.
Give the target name and a description.
Click Add under Specify access servers in order to Add our initiator server.
We have multiple ways we can input that information. In this event we will browse AD and select the system that way (or you can enter the FQDN of the device).
Repeat the process to add each server you want to add as a iSCSI initiator (device that will use this virtual disk). This may happen for something like a cluster shared volume, but isn’t always the case depending on your use case.
Skip to Confirmation and then confirm all of the listed settings and click Create.
The wizard will run through and then show a successfully completed message.
You can now go the device via Computer Management or Server Manager and setup the drive.
Setting up MPIO
Adding MPIO to the Devices that are going to use iSCSI storage allows a high quality and reliable storage service with failover and load balancing capability. This plus the ability for more performance makes this essential for our iSCSI storage.
On a device that will have iSCSI storage attached, login and type in mpiocpl.exe in the command line.
This will open MPIO Properties. We want to click on the Discover Multi-Paths tab, and then check the box to Add support for iSCSI devices and then click on Add. It will ask us to reboot for the changes to take affect.
After the system has restarted, check back on the MPIO Devices tab and you should now see MSFT2005iSCSIBusType 0x9 (or similar ID) listed under Devices.
This process will need to be repeated for each of the devices that will be using the iSCSI storage.
You may need to run these commands in order to set the proper MPIO defaults
Enable MSDSMAutomaticClaim –BusType iSCSI
Set-MSDSMGlobalDefaultLoadBalancePolicy –Policy RR
Setting up iSCSI Initiator via PowerShell
Log into a device that will be using the iSCSI storage.
In PowerShell, we will start the iSCSI by typing Start-Service msiscsi
And will need to set the service to Automatic
Now we will need to connect back to our iSCSI Storage server using it’s IP Address or FQDN using the following PowerShell cmdlet:
New-IscsiTargetPortal –TargetPortalAddress $Name
If you have simply added a new LUN to an existing connection, you can run this PowerShell cmdlet to refresh the Portal:
Get-IscsiTargetPortal | Update-IscsiTargetPortal
To check if it was mapped, run the Get-iSCSITarget cmdlet. You should see a node address come up with a status of False under IsConnected.
By default, the new iSCSI target will be offline or not connected. To resolve this, we are going to connect our iSCSI target as shown here. You would replace the Target and Portal Address lines below with the IPs of those devices.
Connect-IscsiTarget –NodeAddress $node –IsMultiPathEnabled $true –IsPersistent $true –TargetPortalAddress $iSCSIStorageServer –InitiatorPortalAddress $ServerConnectedtoStorage
Repeat the above command for any other connections that will need to be made.
Setting up iSCSI Initiator via GUI
On a device that will have iSCSI storage attached, login and type in iscsicpl.exe in the command line. Should you be running this for the first time, you will get a message that the service is not running and a restart will be needed in order to finish initializing the service.
Click Yes and restart the device.
Once the device has restarted, log back in and open the iSCSI Initiator. Click on the Discovery tab and then on Discover Portal.
Enter the name of the server that is hosting the iSCSI storage, then click on OK.
You should now see the newly added target showing under Target portals.
Click on the Targets tab. Depending on if you have created any iSCSI Virtual Disks, or how many you have created, you may see different amounts. Click on our target and then click on Connect.
Check the Add the connection to the list of Favorite Targets, Enable multi-path and then click on Advanced.
Select Microsoft iSCSI Initiator from the Local adapter drop down list. Then select an IP address from the Initiator IP drop down list (Usually device you are on). Finally Select an IP address from the Target portal IP drop down list (Usually device where iSCSI storage is setup). You will need to ensure that the Initiator IP and the Target portal IP are within the same subnet.
Click OK when you are done.
Under Discovered targets you should now see the status as Connected. We are now going to add the second connection for MPIO, so highlight our target and click on Properties.
In the Sessions tab, we should show one Identifier. To add the second, click on Add session.
Check the Add the connection to the list of Favorite Targets, Enable multi-path and then click on Advanced.
Select Microsoft iSCSI Initiator from the Local adapter drop down list. Then select an IP address from the Initiator IP drop down list (Usually device you are on). Finally Select an IP address from the Target portal IP drop down list (Usually device where iSCSI storage is setup). You will need to ensure that the Initiator IP and the Target portal IP are within the same subnet.
Click OK when you are done.
You will now see both connections listed under Identifier.
And also see two targets under Favorite targets.
#EndofLine