VMware Cloud Community
Mallik7
Enthusiast
Enthusiast
Jump to solution

Is there a script available to determine LUN / datastore GPT corruption?

The backup jobs are getting failed due to GPT corruption (primary partition table) on the datastores.

Ran a command to check the status. However, we would like to check our entire environment to know how many datastores has similar issue.

so, is there a PowerCLI script available to determine LUN / datastore GPT corruption - Cluster wise or whole vCenter ? Could you please help here....!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this.
It assumes that all your ESXi nodes use the same credentials.
It will start (and stop) the SSH service when it is not running on an ESXi node.

$user = 'root'

$pswd = 'VMware1!'

$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd


Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

   $service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |

     Start-VMHostService -Confirm:$false


   $session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

   Get-Datastore -RelatedObject $esx -PipelineVariable ds |

     where { $_.Type -eq 'VMFS' } |

   ForEach-Object -Process {

     $ds.ExtensionData.Info.Vmfs.Extent |

     ForEach-Object -Process {

       Write-Host -ForegroundColor Yellow "ESXI $($esx.Name)  DS $($ds.Name)  Extent $($_.DiskName)"

       $dev = $_.DiskName

       $cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"

       $result = Invoke-SSHCommand -SSHSession $session -Command $cmd

       $result.OutPut

     }

   }

   Remove-SSHSession -SSHSession $session | Out-Null


   if ($service)

   {

     Stop-VMHostService -HostService $service -Confirm:$false | Out-Null

   }

}

---------------------------------------------------------------------------------------------------------

 

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
48 Replies
LucD
Leadership
Leadership
Jump to solution

Which command did you run?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

Here is the command that I ran to determine by using each LUN naa id -

I ran this command by logging into one of the ESXi host via SSH

partedUtil getptbl /vmfs/devices/disks/naa.ID

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Is SSH enabled on your ESXi nodes?
Or can it be started temporarily?
If yes, you could use the Posh-SSH module (see my Use Posh-SSH instead of PuTTY post), to run that command on each ESXi nodes for each datastore.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

when ever needed, we will start the SSH service, otherwise, it will be in stopped state.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this.
It assumes that all your ESXi nodes use the same credentials.
It will start (and stop) the SSH service when it is not running on an ESXi node.

$user = 'root'

$pswd = 'VMware1!'

$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd


Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

   $service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |

     Start-VMHostService -Confirm:$false


   $session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

   Get-Datastore -RelatedObject $esx -PipelineVariable ds |

     where { $_.Type -eq 'VMFS' } |

   ForEach-Object -Process {

     $ds.ExtensionData.Info.Vmfs.Extent |

     ForEach-Object -Process {

       Write-Host -ForegroundColor Yellow "ESXI $($esx.Name)  DS $($ds.Name)  Extent $($_.DiskName)"

       $dev = $_.DiskName

       $cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"

       $result = Invoke-SSHCommand -SSHSession $session -Command $cmd

       $result.OutPut

     }

   }

   Remove-SSHSession -SSHSession $session | Out-Null


   if ($service)

   {

     Stop-VMHostService -HostService $service -Confirm:$false | Out-Null

   }

}

---------------------------------------------------------------------------------------------------------

 

Was it helpful? Let us know by completing this short survey here.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

excellent, that is working the way I expected. Thank you so much.

However, can the output be captured in a tabular format like below in a spread sheet please:

vCenter name, ESXi host name, datastore name, naa.id, GPT status

TIA

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And what do you consider to be the 'GPT status' in the output of the command?
Or how would you derive that?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

One way I could think of is to check if the partition table is at least present.
If not, the command will only return the top 2 lines.
Would that cover your case?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

this is how the output is showing up when I run the script -

ESXI esxhost1.com  DS NR_122_ha_v6  Extent naa.600507680c808602e8000000000000b5

gpt

133674 255 63 2147483648

1 2048 2147483614 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

in the fist line, listing the ESXi host name with datastore name along with naa ID number

under GPT status, script should be able to capture the data apart from the first line.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sorry, not following.
Could you perhaps show me an example of the output as you would like to see it?

Remember, a partition can consist of multiple lines.

How would you display those?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

output attached

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is what it currently shows.
My question is, what, and how, do you want it to show?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

I would like to capture from "gpt to vmfs 0" (between what ever the text), under "GPT status" column.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, try like this

$user = 'root'

$pswd = 'VMware1!'

$secPswd = ConvertTo-SecureString $pswd -AsPlainText -Force

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, $secPswd


Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

   $service = Get-VMHostService -VMHost $esx | where { $_.Key -eq 'TSM-SSH' -and -not $_.Running } |

   Start-VMHostService -Confirm:$false


   $session = New-SSHSession -ComputerName $esx.Name -Credential $cred –AcceptKey

   Get-Datastore -RelatedObject $esx -PipelineVariable ds |

   where { $_.Type -eq 'VMFS' } |

   ForEach-Object -Process {

   $ds.ExtensionData.Info.Vmfs.Extent |

   ForEach-Object -Process {

   $dev = $_.DiskName

   $cmd = "partedUtil getptbl /vmfs/devices/disks/$dev"

   $result = Invoke-SSHCommand -SSHSession $session -Command $cmd

   New-Object -TypeName PSObject -Property ([ordered]@{

   vCenter = ([uri]$esx.ExtensionData.Client.ServiceUrl).Host

   VMHost = $esx.Name

   Datastore = $ds.Name

   DiskName = $dev

   'GPT Status' = $result.Output -join ' '

   })

   }

   }

   Remove-SSHSession -SSHSession $session | Out-Null


   if ($service)

   {

   Stop-VMHostService -HostService $service -Confirm:$false | Out-Null

   }

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Mallik7
Enthusiast
Enthusiast
Jump to solution

thanks, it is displaying on the screen, but, the output is not saving in the .csv format

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Add the following at the end

| Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

yes, I've already tried adding the below, but, it not working -

Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you add the vertical bar (pipeline symbol)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Mallik7
Enthusiast
Enthusiast
Jump to solution

thanks much for your time. its a great help.

Reply
0 Kudos