Creating datastores

You can use the New-Datastore cmdlet to create a new datastore. The syntax of the New-Datastore cmdlet is as follows. The first parameter set is to create NFS datastores:

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name]
    <String> -Path <String> [-Nfs] -NfsHost <String[]> [-ReadOnly]
    [-Kerberos] [-FileSystemVersion <String>] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The second parameter set is to create VMFS datastores:

New-Datastore [-Server <VIServer[]>] [-VMHost] <VMHost[]> [-Name]
    <String> -Path <String> [-Vmfs] [-BlockSizeMB <Int32>]
    [- FileSystemVersion <String>] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The -VMHost, -Name, -Path, and -NfsHost parameters are required.

Creating NFS datastores

In the first example, we will create an NFS datastore. To indicate that we want to create an NFS datastore, we have to use the -Nfs parameter. The datastore will be created on host 192.168.0.133 with name Cluster01_Nfs01. The IP address of the NFS server is 192.168.0.157, and the remote path of the NFS mount point is /mnt/Cluster01_Nfs01:

PowerCLI C:> New-Datastore -Nfs -VMHost 192.168.0.133
    -Name Cluster01_Nfs01 -NfsHost 192.168.0.157 -Path /mnt/Cluster01_Nfs01
WARNING: Parameter 'VMHost' is obsolete. This parameter no longer
    accepts multiple values.


    Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
Cluster01_Nfs01                        249.314         249.314

Getting SCSI LUNs

Before we can create a VMFS datastore, we need to know the canonical name of the SCSI logical unit that will contain the new VMFS datastore.

The Get-ScsiLun cmdlet retrieves the SCSI devices available on the vCenter Server system and their canonical names. The syntax of the Get-ScsiLun cmdlet is as follows. The first parameter set is for retrieving SCSI LUNs by a host:

Get-ScsiLun [[-CanonicalName] <String[]>] [-VmHost] <VMHost[]>
    [-Key <String[]>] [-LunType <String[]>] [-Server <VIServer[]>]
    [<CommonParameters>]

The second parameter set is for retrieving SCSI LUNs by ID:

Get-ScsiLun -Id <String[]> [-Server <VIServer[]>]
    [<CommonParameters>]

The third parameter set is for retrieving SCSI LUNs by datastore:

Get-ScsiLun [[-CanonicalName] <String[]>] [-Datastore]
    <Datastore[]> [-Key <String[]>] [-LunType <String[]>]
    [-Server <VIServer[]>] [<CommonParameters>]

The fourth parameter set is for retrieving SCSI LUNs by a host bus adapter (HBA):

Get-ScsiLun [[-CanonicalName] <String[]>] [-Hba] <Hba[]>
    [-Key <String[]>] [-LunType <String[]>] [-Server <VIServer[]>]
    [<CommonParameters>]

The -VmHost, -Id, -Datastore, and -Hba parameters are required.

In the following example, we will get all of the SCSI LUNs of host 192.168.0.133 and select the RuntimeName and CanonicalName properties:

PowerCLI C:> Get-VMHost -Name 192.168.0.133 | Get-ScsiLun |
>> Select-Object -Property RuntimeName,CanonicalName


    RuntimeName     CanonicalName
-----------     -------------
3PARdata VV      vmhba0:C0:T3:L54 naa.60002ac000000000000002f400004ca6
HP       HSVX700 vmhba0:C0:T0:L10 naa.600a0b80001111550000f4f44041944d
HP       HSVX700 vmhba0:C0:T0:L2  naa.600a0b8000111155000025315052494d
HP       HSVX700 vmhba0:C0:T0:L25 naa.600a0b8000111155000059ba3f0d204e
3PARdata VV      vmhba0:C0:T2:L51 naa.60002ac0000000000000035000004bee

Creating VMFS datastores

To create a VMFS datastore, we have to use the New-datastore -Vmfs parameter to indicate that we want to create a VMFS datastore. We have to specify a name for the datastore and a host on which we want to create the datastore. Finally, we have to specify the canonical name of the SCSI logical unit that will contain the new VMFS datastore:

PowerCLI C:> New-Datastore -Vmfs -VMHost 192.168.0.133
    -Name Cluster01_Vmfs01 -Path naa.60002ac0000000000000035000004bee


    Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
Cluster01_Vmfs01                       248.801         249.750

If you create the VMFS datastore on a host that is part of a cluster, the new datastore will be mounted on all hosts of the cluster.

Creating software iSCSI VMFS datastores

To create a datastore on iSCSI SAN, you can use hardware iSCSI initiators or software iSCSI initiators. Hardware iSCSI initiators are similar to Fibre Channel HBAs. In this section, we will discuss how to create VMFS datastores using software iSCSI initiators. Before you can connect your ESXi hosts to an iSCSI LUN, your storage administrators will have to create such LUN and expose it to your ESXi servers. To set up software iSCSI initiators, you have to enable software iSCSI on your hosts using the Set-VMHostStorage cmdlet. The syntax of this cmdlet is as follows:

Set-VMHostStorage -VMHostStorage <VMHostStorageInfo[]>
    -SoftwareIScsiEnabled [<Boolean>] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The -VMHostStorage and -SoftwareIScsiEnable parameters are required.

Then, you can create an iSCSI HBA target. First, you have to find iSCSI HBA using the Get-VMHostHba cmdlet. This cmdlet has the following syntax:

Get-VMHostHba [[-VMHost] <VMHost[]>] [[-Device] <String[]>]
    [-Type <HbaType[]>] [-Server <VIServer[]>] [<CommonParameters>]

This cmdlet has no required parameters.

To create the iSCSI HBA target, you can use the New-IScsiHbaTarget cmdlet. The syntax for the New-IScsiHbaTarget cmdlet is as follows:

New-IScsiHbaTarget -IScsiHba <IScsiHba[]> [-Address] <String[]>
    [[-Port] <Int32>] [-Type <IScsiHbaTargetType>] [[-IScsiName]
    <String>] [-ChapType <ChapType>] [-ChapName <String>] [-ChapPassword
    <String>] [-MutualChapEnabled [<Boolean>]] [-MutualChapName
    <String>] [-MutualChapPassword <String>] [-InheritChap
    [<Boolean>]] [-InheritMutualChap [<Boolean>]] [-Server <VIServer[]>]
    [-WhatIf] [-Confirm] [<CommonParameters>]

The -IScsiHba and -Address parameters are required.

After creating the iSCSI HBA target, we have to rescan HBAs.

iSCSI HBA has to be bound to a VMkernel port group. In the script given later, we will create a dedicated switch and VMkernel port group for iSCSI. There are no cmdlets to bind an iSCSI HBA to a VMkernel port group, so we have to fallback to the vSphere API IscsiManager BindVnic() method.

After the binding, we have iSCSI LUN that we can use to create a datastore.

The following script performs all of the necessary steps. The script first defines the variables we use and then it retrieves the VMHost object of the host on which the iSCSI datastore will be created. Software iSCSI will be enabled on this host. Then, an iSCSI target will be created, and a rescan of the HBAs will be performed on the host. A new virtual switch and a VMkernel port group will be created. The VMkernel port group will be bound to the iSCSI HBA. Finally, the new iSCSI datastore will be created.

First, we will define the variables we need for later use:

$HostName = '192.168.0.133' 
$iSCSITarget = '192.168.0.157' 
$VirtualSwitchName = 'vSwitch2' 
$NicName = 'vmnic3' 
$PortGroupName = 'iSCSI Port group 1' 
$ChapType = 'Preferred' 
$ChapUser = 'Cluster01User' 
$ChapPassword = ' Cluster01Pwd' 
$DatastoreName = 'Cluster01_iSCSI01' 

Then, we will retrieve the host to add the iSCSI datastore to and store it in the variable $VMHost:

$VMHost = Get-VMHost -Name $HostName 

We need to enable software iSCSI support on the host:

$VMHost | Get-VMHostStorage | Set-VMHostStorage -SoftwareIScsiEnabled:$true 

And we have to create an iSCSI target:

$VMHostHba = $VMHost | Get-VMHostHba -Type iSCSI 
$VMHostHba | 
New-IScsiHbaTarget -Address $iSCSITarget -ChapType $ChapType -ChapName $ChapUser -ChapPassword $ChapPassword 

Next, we have to rescan all HBAs:

$VMHost | Get-VMHostStorage -RescanAllHba 

We have to create a new virtual switch and a VMkernel port group on the host:

$vSwitch = New-VirtualSwitch -VMHost $VMHost -Name $VirtualSwitchName -Nic $NicName 
$NetworkAdapter = New-VMHostNetworkAdapter -VirtualSwitch $vSwitch -PortGroup $PortGroupName 

Now we bind the VMkernel port group to the iSCSI HBA:

$IscsiManager = Get-View -Id $vmhost.ExtensionData.Configmanager.IscsiManager 
$IscsiManager.BindVnic($VMHostHba.Device, $NetworkAdapter.Name) 

Finally, we can create the iSCSI datastore:

$ScsiLun = $VMHost | 
Get-ScsiLun | 
Where-Object {$_.Model -eq 'iSCSI Disk'} 
New-Datastore -Vmfs -VMHost $VMHost -Name $DatastoreName -Path $ScsiLun.CanonicalName  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.243.32