WS2012 Storage - iSCSI Target Server - Create an iSCSI target using PowerShell
For my Virtual Machines needs, some LUNS are presented to my VMware vSphere 5.1 Servers and until now,my labstorage was handle byFreeNas using iSCSI. For tests purposes, I replaced this FreeNas by Windows Server 2012 to take care of that part.
Note: Before writing this post, I grouped my physical disks together into a container called storage poolsto manage those disks as a single storage space. Afterwards, in these storage pools, I created virtual disks (aka LUN)on which I specify a layout, … which is simply a raid level.
Overview
In the following post I will talk about the following points:
-
Quick iSCSI Terminology
-
Quick look at iSCSI Target Management (GUI and PowerShell iSCSI Modules)
-
Installing the Windows Feature iSCSI Server Target (PowerShell)
-
Creating a iSCSI Virtual Disk (aka LUN) (PowerShell)
-
Creating a iSCSI Target and assigning it to one or more initiator(s) (PowerShell)
-
Finding the iSCSI Qualified Name (IQN)</b> (vSphere Client and PowerCLI)
-
Assigning a iSCSI Virtual Disk (LUN) to a iSCSI Target (PowerShell)
Terminology
Note: The iSCSI protocol is fully documented by the RFC 3720and RFC 3721 iSCSI:iSCSI stands forInternet Small Computer System Interface. It’s an Internet Protocol (IP)-based storage networking standard for linking data storage facilities. iSCSI is used to facilitate data transfers over a network (LAN, WAN or Internet) and transferring data by carrying SCSI commands over IP networks. iSCSI leverages the Ethernet network and does not require any specialized hardware
source:[http://blogs.technet.com/b/filecab/](http://blogs.technet.com/b/filecab/) |
iSCSI Target Server: is the server that shares the storage, it runs the iSCSI Target. The server (machine) consumes the storage is called iSCSI initiator.
iSCSI Initiator:Typically, it is an application server. For example, iSCSI Target provides storage to a SQL server, the SQL server will be the iSCSI initiator in this deployment.
Target: It is an object which allows the iSCSI initiator to make a connection. The Target keeps track of the initiators which are allowed to be connected to it. The Target also keeps track of the iSCSI virtual disks which are associated with it. Once the initiator establishes the connection to the Target, all the iSCSI virtual disks associated with the Target will be accessible by the initiator.
iSCSI Virtual Disk: It also referred to as iSCSI LUN. It is the object which can be mounted by the iSCSI initiator. On Windows Server 2012, the iSCSI virtual disk is backed by the VHD file.
iSCSI Connection: iSCSI initiator makes a connection to the iSCSI Target Server by logging on to a Target. There could be multiple Targets on the iSCSI Target Server, each Target can be accessed by a defined list of initiators. Multiple initiators can make connections to the same Target. However, this type of configuration is only supported with clustering. Because when multiple initiators connects to the same Target, all the initiators can read/write to the same set of iSCSI virtual disks, if there is no clustering (or equivalent process) to govern the disk access, corruption will occur. With Clustering, only one machine is allowed to access the iSCSI virtual disk at one time.
IQN:iSCSI Qualified Name. It is a unique identifier of the Target or Initiator. The Target IQN is shown when it is created on the Server. The initiator IQN can be found by typing a simple “iscsicli” cmd in the command window or using Get-InitiatorPort in PowerShell
Using iscsicli |
Using PowerShell (module iSCSI) with the Cmdlet Get-InitiatorPort</td></tr></tbody></table>
Briefly, the fields are:
* The string "iqn.", used to distinguish these names from "eui." formatted names.
* A date code, in yyyy-mm format that the naming authority took ownership of the domain
* The reversed domain name of the naming authority (person or organization) creating this iSCSI name. (com.lazywinadmin, com.example, com.google)
* An optional, colon (:) prefixing a storage target name specified by the owner of the domain name deems appropriate.
Information from the RFC:
Loopback: There are cases where you want to run the initiator and Target on the same machine; it is referred as "loopback". In Windows Server 2012, it is a supported configuration. In loopback configuration, you can provide the local machine name to the initiator for discovery, and it will list all the Targets which the initiator can connect to. Once connected, the iSCSI virtual disk will be presented to the local machine as a new disk mounted. There will be performance impact to the IO, since it will travel through the iSCSI initiator and Target software stack when comparing to other local IOs. One use case of this configuration is to have initiators writing data to the iSCSI virtual disk, then mount those disks on the Target server (using loopback) to check the data in read mode.
### Quick look at iSCSI Target Management
PowerShell Cmdlets
Windows Server 2012 comes with a complete set of PowerShell cmdlets for iSCSI. By combining the iSCSI target, iSCSI initiator, and storage cmdlets, you can automate pretty much all management tasks.Here is the list of Cmdlets available to you:
The moduleiSCSIis used for all iSCSIInitiator-specific Cmdletsand theiSCSITargetfor all iSCSItarget service-specific cmdlets.
More Info:
iSCSI Cmdlets in Windows PowerShelliSCSI Target Cmdlets in Windows PowerShell
### Installation of iSCSI Target Server
In order to be able to use the Storage Features related to iSCSI, you will need to install the iSCSI Target Server Feature. This can be perform via the Server Manager Console but here I will only focus on PowerShell. You can find the UI procedurehere
```
# Import the ServerManager PowerShell Module
Import-Module-Name ServerManager
```
```
```
```
# Add the Windows Feature iSCSI Target Server
Add-WindowsFeature-Name FS-iSCSITarget-Server
```
```
```
Optionally
You might also want to install the iSCSITarget-VSS-VDS WindowsFeature too to be able to manage older application(s) that need VDS (Virtual Disk Service) and VSS (Volume Snapshot Service) to create volume shadow copies of data on iSCSI virtual disks. VSS is also used by some backup solutions. (more info)
```
# Add the Windows Feature iSCSI VDS/VSS
Add-WindowsFeature-Name FS-iSCSITarget-VSS-VDS
```
###
###
### Configuration of iSCSI Target Server
Again, here I'll use only PowerShell Cmdlets. You can find the UI procedure here
Overview
*
* Load the PowerShell iSCSI Module
* Create a iSCSI LUN (aka iSCSI Virtual Disk, a VHD file)
* Create a Target
* Assign the iSCSI LUN to the Target.
2 - Create iSCSI LUN
Here we create a new iSCSI virtual hard disk (VHD) object with the specified file Path and Size.
```
# Create a 1GB iSCSI Virtual Disk
New-IscsiVirtualDisk -Path c:\test\LUN1.vhd -Size 1GB
```
Finding the IQN of your iSCSI Initator
UsingVMware vSphere Client:You can find the IQN in the properties of your iSCSI Software Adapter.
Using PowerCli
I found two ways to get this information with PowerCli ...
1 - WithGet-View(Call to the NET Framework)
```
((Get-view (Get-view -Id ((Get-VMhost lab1vh02.fx.lab).id)).config
manager.storagesystem).StorageDeviceInfo.HostBusAdapter).iscsiName
```
2 - WithGet-EsxCli
```
(Get-EsxCli -VMHost lab1vh02.fx.lab).iscsi.adapter.list()
```
```
```
```
```
|
No output will be generated. There is no Passthru parameter either :-(</td></tr></tbody></table> Optionally:You can specify the Logical Unit Number (LUN) associated with the virtual disk. By default, the lowest available LUN number will be assigned. ``` # Assigning the virtual disk to the iSCSI Target Add-IscsiVirtualDiskTargetMapping -TargetName TestTarget1 -Path C:\test\Lun1.vhd -Lun 25 ``` Once a virtual disk has been assigned to a target, and after the iSCSi initiator connects to that target, the iSCSI initiator can access the virtual disk. All of the virtual disks assigned to the same iSCSI target will be accessible by the connected iSCSI initiator. In my next post I will explain how to configure the iSCSI Initiator on VMware vSphere using PowerCli ### ### References * iSCSI Cmdlets in Windows PowerShell * iSCSI Target Cmdlets in Windows PowerShell * PowerCLI - Using Get-ESXCLI * PowerShell Cmdlets for iSCSI Target * Introduction of iSCSI Target in Windows Server 2012 * Managing iSCSI Initiator connections with Windows PowerShell on Windows Server 2012 * Setting up windows server 2012 storage virtualization. A software RAID solution or more * Configure Windows Server 2012 as a ISCSI Storage Server * Six Uses for the Microsoft iSCSI Software Target |
Leave a comment