Reader small image

You're reading from  Learning PowerCLI - Second Edition

Product typeBook
Published inFeb 2017
Publisher
ISBN-139781786468017
Edition2nd Edition
Right arrow
Author (1)
Robert van den Nieuwendijk
Robert van den Nieuwendijk
author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk

Right arrow

Chapter 7. Managing Storage

Your virtual machines need storage for their configuration files, disks, swap files, and snapshot files. These files can be placed on datastores that reside on a host's local storage, Network File System (NFS), Internet Small Computer System Interface (iSCSI), Fibre Channel (FC), Fibre Channel over Ethernet (FCoE), Storage Area Networks (SANs), or VMware vSAN. Datastores can be grouped into datastore clusters to create pools of datastores for storage aggregation, easy initial placement of disks, and load balancing using Storage Distributed Resource Scheduler (Storage DRS). vSphere storage policy-based management can be used to create virtual machines on storage that is compliant with a certain storage policy. In this chapter, we will discuss managing storage with PowerCLI.

The following topics will be covered in this chapter are:

  • Rescanning for new storage devices

  • Creating datastores

  • Retrieving datastores

  • Setting the multipathing policy

  • Configuring vmhba paths to a...

Rescanning for new storage devices


After creating LUN on your Fibre Channel storage system and presenting LUN to your ESXi servers, you have to rescan HBAs on the ESXi servers before you can create a datastore on LUN. An ESXi host will not see newly attached LUN before a rescan is performed. You can use the Get-VMHostStorage cmdlet to rescan the HBAs of a host. The Get-VMHostStorage cmdlet has the following syntax; the first parameter set is the default:

Get-VMHostStorage [-VMHost] <VMHost[]> [-Refresh] [-RescanAllHba]
    [-RescanVmfs] [-Server <VIServer[]>] [<CommonParameters>]

The second parameter set is for retrieving host storage by ID:

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

The -VMHost and -Id parameters are required.

In the following example, we will rescan all the HBAs of the hosts of cluster Cluster01:

PowerCLI C:\> Get-Cluster -Name Cluster01 |
>> Get-VMHost | Get-VMHostStorage -RescanAllHba...

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...

Retrieving datastores


You can use the Get-Datastore cmdlet to retrieve a specific datastore or a list of all of your datastores. The syntax of the Get-Datastore cmdlet is as follows. The first parameter set is the default:

Get-Datastore [-Server <VIServer[]>] [[-Name] <String[]>]
    [-Location <VIObject[]>] [-RelatedObject
    <DatastoreRelatedObjectBase[]>] [-Refresh] [-Tag <Tag[]>]
    [<CommonParameters>]

The second parameter set is for retrieving datastores by ID:

Get-Datastore [-Server <VIServer[]>] -Id <String[]>
    [-Refresh] [<CommonParameters>]

The -Id parameter is required.

In the following example, we will retrieve the datastore with name Cluster01_Vmfs01:

PowerCLI C:\> Get-Datastore -Name Cluster01_Vmfs01


    Name                               FreeSpaceGB      CapacityGB
----                               -----------      ----------
Cluster01_Vmfs01                       248.801        ...

Setting the multipathing policy


If you use Fibre Channel or iSCSI storage devices, it is highly recommended to have multiple paths between your hosts and SAN and to use multipathing. Depending on the recommendations made by your storage vendor, you have to set the multipathing policy to either Fixed, Most Recently Used (MRU), or Round Robin (RR).

Note

More information about multipathing policies can be found in VMware Knowledge Base article 1011340: Multipathing policies in ESXi 5.x and ESXi/ESX 4.x, http://kb.vmware.com/kb/1011340 .

You can use the Get-ScsiLun cmdlet to retrieve the current multipathing policy for your LUNs:

PowerCLI C:\> Get-VMHost -Name 192.168.0.133 | Get-ScsiLun |
>> Where-Object {$_.LunType -eq 'disk'} |
>> Select-Object -Property CanonicalName,LunType,MultipathPolicy


    CanonicalName                        LunType  MultipathPolicy
-------------                        -------  ---------------
naa.600a0b80001111550000f35b93e19350 disk   ...

Configuring vmhba paths to an SCSI device


For each vmhba path to a storage device, you can indicate that the path is active or not active and you can also indicate that the path is the preferred path to the SCSI device.

Retrieving vmhba paths to an SCSI device

You can use the Get-ScsiLunPath to retrieve the list of vmhba paths to a specified SCSI device. The syntax of the Get-ScsiLunPath cmdlet is as follows:

Get-ScsiLunPath [[-Name] <String[]>] [-ScsiLun] <ScsiLun[]> 
    [<CommonParameters>]

The -ScsiLun parameter is required, and it accepts input from the pipeline.

In the following example, we will retrieve the vmhba paths of the LUN with Canonical Namenaa.600a0b80001111550000f35b93e19350 from the host 192.168.0.133:

PowerCLI C:\> Get-VMHost -Name 192.168.0.133 | Get-ScsiLun |
>> Where-Object {$_.CanonicalName -eq 
    'naa.600a0b80001111550000f35b93e19350'} |
>> Get-ScsiLunPath


    Name       SanID                                 State...

Working with Raw Device Mappings


A Raw Device Mapping (RDM) is a storage device that is presented directly to a virtual machine. RDMs are available in two compatibility modes: physical and virtual. The most important difference is that virtual compatibility mode RDMs can be a part of a VMware vSphere snapshot. Snapshots of a physical compatibility mode RDM can only be taken on the storage array.

There are some use cases for RDMs. The most common use case is the quorum disk in a Microsoft Windows cluster. A quorum disk must be in physical compatibility mode.

Note

For more information about using Microsoft Windows Clusters on VMware vSphere, you should read the Setup for Failover Clustering and Microsoft Cluster Service guide. You can find this guide on https://www.vmware.com/support/pubs/ . VMware Knowledge base article 1037959: Guidelines for Microsoft Clustering on vSphere can be found at http://kb.vmware.com/kb/1037959 .

To add RDM to a virtual machine, you can use the New-Harddisk cmdlet...

Configuring storage I/O control


Storage I/O Control (SIOC) is a feature of VMware vSphere Enterprise Plus that provides I/O prioritization of virtual machines running on a group of VMware vSphere hosts that have access to the same datastore. If the latencies of a datastore come above a certain threshold, Storage I/O Control will throttle the I/O bandwidth of the virtual machines that use this datastore according to their respective share value. The default value for the latency threshold is 30 milliseconds. You are better keeping this default value unless you have a good reason to change it. One good reason can be the use of SSDs where a latency threshold of 10-15 milliseconds is recommended.

You can enable or disable Storage I/O Control using the Set-Datastore cmdlet -StorageIOControlEnabled parameter. You can also specify a value for the threshold with the -CongestionThresholdMillisecond parameter. The syntax of the Set-datastore cmdlet is as follows. The first parameter set is for updating...

Configuring Storage DRS


vSphere Storage Distributed Resource Scheduler is a VMware vSphere Enterprise Plus feature first introduced in vSphere 5.0. It gives you the possibility to combine datastores in a datastore cluster. You can then manage the datastore cluster instead of the individual datastores. When you create a new virtual machine and put the disks on a datastore cluster, Storage DRS will place the disks on the optimal datastore based on utilized disk space and datastore performance. Storage DRS can also migrate disks to another datastore in the same datastore cluster when the utilized disk space or latency of a datastore becomes too high. You can also make affinity rules to separate disks and virtual machines over multiple datastores or keep them together on the same datastore. If you put a datastore in Datastore Maintenance Mode, Storage DRS will move all the disks on this datastore to other datastores in the same datastore cluster.

The first thing that you have to do, if you want...

Upgrading datastores to VMFS-5


With vSphere 5, VMware upgraded the VMFS file system to version 5. VMFS-5 came with the following new features:

  • Unified 1 MB file block size

  • Large single extent volumes of 64 TB

  • Smaller 8 KB sub-block

  • Small file support

  • Increased file count limit greater than 120,000

  • VMware vSphere Storage APIs for Array Integration (VAAI)

  • Primitive Atomic Test & Set (ATS)

  • Enhancement for file locking

  • GUID Partition Table (GPT)

  • A new starting sector of 2048

If you upgraded your vSphere environment from version 4 or earlier to version 5 or 6, your datastores are probably still on VMFS-3. There are two options for going to VMFS-5. The first option is to create new VMFS-5 datastores and move your virtual machines to the new datastores. When your old VMFS-3 datastores are empty, you can remove them. The advantage of this method is that the new datastores will have all of the new VMFS-5 features. However, it is a lot of work, and you need enough free space on your storage system to create...

Removing datastores


To remove a datastore, you can use the Remove-Datastore cmdlet. The syntax of this cmdlet is:

Remove-Datastore [-Datastore] <Datastore[]> [-VMHost] <VMHost>
    [-Server <VIServer[]>] [-RunAsync] [-WhatIf] [-Confirm]
    [<CommonParameters>]

The required parameters of the Remove-Datastore cmdlet are -Datastore and -VMHost.

In the following example, we will remove the Cluster01_Vmfs01 datastore we created in the section,  Creating VMFS datastores :

PowerCLI C:\> Remove-Datastore -Datastore Cluster01_Vmfs01
    -VMHost 192.168.0.133 -Confirm:$false

The preceding command does not return any output.

If you try to remove a datastore, it is possible that you get an error message similar to:

Remove-Datastore : 1/31/2017 2:05:48 PM    Remove-Datastore
    The resource 'Cluster01_Vmfs01' is in use.

Before you can remove a datastore, there are some requirements that must be fulfilled:

  • There must be no virtual machines residing on the...

Using VMware vSAN


VMware vSAN is a shared storage solution for Hyper-Converged Infrastructure (HCI) that uses local disks in ESXi servers as the media. A vSAN cluster consists of two or more ESXi hosts. Although two hosts is the minimum number required, VMware recommends using at least four hosts in a vSAN cluster. The local disks in an ESXi server can be combined into disk groups that can be all-flash or a combination of magnetic disks and flash devices, also named solid state drives or SSDs. There can be a maximum of seven disks per disk group. There is also a maximum of five disk groups on a host. At least one disk in a disk group must be SSD. SSDs will be used for read-and-write cache. Magnetic disks will be used for capacity storage. In an all-flash disk group, the SSDs in the cache tier are only used for write caching. The disk groups in a cluster are combined into a vSAN datastore named vsanDatastore. Also, hosts without a disk group can participate in a vSAN cluster. For vSAN communication...

Using vSphere storage policy-based management


Storage policy-based management (SPBM) is the control plane of VMware's management layer for Software-Defined Storage (SDS). SPBM can use the vSphere Storage APIs for Storage Awareness (VASA) providers to expose storage topologies, capabilities, and state information to vCenter Server. You can also manually define storage capabilities by using tags. For example, you can create tags for replicated and nonreplicated storage. These tags will be assigned to datastores. From the capabilities or tags, you can create SPBM rules, rule sets, and storage policies. These storage policies can be used to create virtual machines on storage that is compliant with a certain storage policy. Storage policies can be exported to XML files, which can be imported later.

Tip

All the SPBM-related cmdlets will only work with vCenter Server 5.5 or higher.

Retrieving storage capabilities

If your storage has a VASA provider, you can use the Get-SpbmCapability cmdlet to retrieve...

Summary


In this chapter, we covered managing storage. We showed you how to create and remove datastores, configure software iSCSI initiators, work with Raw Device Mappings, configure Storage I/O Control, create and remove datastore clusters, add datastores to a datastore cluster, upgrade your datastores to VMFS-5, use VMware vSAN, and use vSphere storage policy-based management.

In the next chapter, you will learn all about managing high availability and clustering with PowerCLI.

lock icon
The rest of the chapter is locked

Unlock this book and the full library FREE for 7 days

Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
You have been reading a chapter from
Learning PowerCLI - Second Edition
Published in: Feb 2017Publisher: ISBN-13: 9781786468017
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime

Author (1)

author image
Robert van den Nieuwendijk

Robert van den Nieuwendijk is an IT veteran from the Netherlands with over thirty years of experience in Information Technology. He holds a bachelor degree in software engineering. After working a few years as a programmer of air traffic control and vessel traffic management systems, he started his own company Van den Nieuwendijk Informatica in 1988. Since then he has worked as a freelance systems administrator of OpenVMS, Windows Server, Linux, and VMware vSphere systems, for Dutch governmental organizations and cloud providers. During winter he is also a ski and snowboard instructor at an indoor ski school. With his background as a programmer, he always tries to make his job easier by writing programs or scripts to perform repeating tasks. In the past, he used the C programming language, OpenVMS DCL, Visual Basic Script and KiXtart to do this. Now, he uses Microsoft PowerShell and VMware PowerCLI for all of his scripting work. Robert is a frequent contributor and moderator at the VMware VMTN Communities. Since 2012 VMware awarded him the vExpert title for his significant contributions to the community and a willingness to share his expertise with others. He has a blog at&nbsp;http://rvdnieuwendijk.com where he writes mainly about VMware PowerCLI, Microsoft PowerShell, and VMware vSphere. If you want to get in touch with Robert, then you can find him on Twitter. His username is @rvdnieuwendijk. Robert is also the author of Learning PowerCLI, Packt Publishing.
Read more about Robert van den Nieuwendijk