VMware Drive Type Changer
July 7, 2014There are a ton of features now that VMware has that may require either an SSD or a Non-SSD to be available in your ESXi host. Host Caching requires an SSD and Partner products like PernixData also require an SSD to be available on the host. VMware’s Virtual SAN (VSAN) currently require both an SSD and a Non-SSD to be available.
I’ve seen that many people want to try out these products in a lab environment, but don’t want to go out and buy another disk just to familiarize themselves with the product. In these cases, you can fool ESXi into thinking there is a device of the type you want. This can be done by using the esxcli commands on the host as documented here on VMware’s site.
I found these commands to be a bit tedious since you need to start the ssh service, grab your favorite ssh client, and then run a series of commands that I could never remember off the top of my head. So I chose to create a powerCLI script to do this for me, as well as do it from a GUI.
The script found below does the following things.
- Connects to your vCenter Server
- Displays your ESXi hosts and asks which one we’re going to modify a disk on
- Displays a list of disks you can modify
- Asks whether you want to convert the selected disk to an SSD or a Non-SSD
- Checks to see if your host is in maintenance mode, and if not puts it into Maintenance Mode
- Changes the drive type
- Reclaims the disk
As you can see, I’ve run the script on one of my hosts and it modified the drive type for me.
You can see my disks before I run the script. vmhba1:C0:T1:L0 is a Non-SSD.
Run the script and it will ask you for which host we’re looking for a disk on.
Select the disk we’re going to convert.
Choose the type of disk to convert it to.
Disk will show up in ESXi as the selected drive type.
[code language=powershell]
#######################################################################################
## Author: Eric Shanks
## Site: theITHollow.com
## Use Cases: Flip the Device type of a disk between SSD and Non-SSD
## Disclaimer: This Script is free for use but should be reviewed andor modified
## before use. Not responsible for problems encountered while using
## this script. Good Luck
## Current Version 1.0
## Change Log:
## Version 1.0 – Initial Release
#######################################################################################
##connect to the vCenter
Add-PSSnapin vmware.vimautomation.core
##Ask for vCenter Address and connect
$vcenter = Read-Host -Prompt “Please Enter the FQDN or IP Address of your vCenter Server”
Connect-VIServer $vcenter
#get the host and disk that you want to convert
$disk = Get-VMHost | Sort-Object | Out-GridView -PassThru | get-scsilun | Sort-object | Out-GridView -PassThru
$Selectedhost = $disk.VMHost.Name
$state = (Get-VMHost $Selectedhost).connectionstate
##Determine if the host is in maintenance mode and if not allow user to put it in Maintenance
If ($state -eq “Connected”)
{
$caption1 = “Choose Action”;
$message = “It is highly recommended to put the host into Maintenance Mode first. Would you like to do that now?”;
$MaintYes = new-Object System.Management.Automation.Host.ChoiceDescription “&Yes”,”Yes”;
$MaintNo = new-Object System.Management.Automation.Host.ChoiceDescription “&No”,”No”;
$Maintchoices = [System.Management.Automation.Host.ChoiceDescription[]]($MaintYes,$MaintNo);
$Maintanswer = $host.ui.PromptForChoice($caption1,$message,$Maintchoices,0)
switch ($Maintanswer){
0 {“You entered Yes”; break}
1 {“You entered NO”; break}
}
}
##put Host into maintenance mode
If ($Maintanswer -eq 0)
{
Set-VMHost $Selectedhost -State Maintenance
}
##Find the Canonical Name of the disk to be converted.
$canonical = $Disk.CanonicalName
##Get the ESXCLI commands from the selectedhost
$esxcli = Get-EsxCli -VMHost $selectedHost
##Get the Storage Array Type Plugin of the disk to be converted
$SATP = ($esxcli.storage.nmp.device.list() | where {$_.Device -eq $canonical }).StorageArrayType
##Find out if we’re converting from SSD to Spinning disk, or vice-versa
$caption = “Choose Action”;
$message = “Make the disk look like an SSD, or a Non-SSD?”;
$SSD = new-Object System.Management.Automation.Host.ChoiceDescription “&SSD”,”SSD”;
$NonSSD = new-Object System.Management.Automation.Host.ChoiceDescription “&NonSSD”,”NonSSD”;
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($SSD,$NonSSD);
$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
switch ($answer){
0 {“You entered SSD”; break}
1 {“You entered NONSSD”; break}
}
##Convert the disk
If ($answer -eq 0){
$esxcli.storage.nmp.satp.rule.add($null,$null,$null,$disk.CanonicalName,$null,$null,$null,”enable_ssd”,$null,$null,$satp,$null,$null,$null)
}
Else{
$esxcli.storage.nmp.satp.rule.remove($null,$null,$null,$disk.CanonicalName,$null,$null,”enable_ssd”,$null,$null,$satp,$null,$null,$null)
}
##Reclaim the disk
$esxcli.storage.core.claiming.reclaim($Disk.CanonicalName)
[/code]
Summary
I hope that you find this tool useful. It has saved me a lot of time in my home lab. As always, this should be tested thoroughly in a lab environment before using in a production site. I am not a powershell guru and make no guarantees that this script will work for all environments. I would love to hear your feedback in the comments. If you have any suggestions, please add them to the comments as I would like to build on this script in the future.
Script defiantly saves some time, but 3 small issues. 1 (the smallest) the GUI window for the choosing SSD or NonSSD does not open. All I get for it is the command line. 2. after changing 1 drive the script quits. 3. while it does allow me to choose several hosts, then several disks, it then quits with errors when trying to convert all selected to SSD.
Thanks Steve, I’ll look into this as I find time. The original goal was to only change one host at a time. It would be cool to do multiple hosts and I’ll see if I can add that into an updated version.
Very informative blog you have. I’ve also tried that script and command. I would also want to do multiple host, i hope so.