Wednesday 5 August 2015

Configuring the scratch partition

I am currently in the process of replacing a fleet of ESX hosts with HP DL360 G9 hardware. Unlike the servers that are being decommissioned these G9 do not have local disk and ESXi will boot from a local SD card. SD devices are sensitive to high amounts of I/O and when installing ESXi the scratch partition will not be located on the SD device. Instead, the installer first scans for a local 4GB vfat partition, if it doesn’t find one it will then scan for a local VMFS volume on which to create a scratch directory. If no local vfat partition or VMFS volume is found, as a last resort the installer will put the scratch partition in “/tmp/scratch” To identify your current scratch directory you can run this one liner

Get-VMHost Host1 | Get-AdvancedSetting -name ScratchConfig.CurrentScratchLocation | Select value

Let's assume the value returned is /tmp/scratch, as is the case with my new install, then you may want to relocate it. I have created a datastore and mounted it on every new ESX host. There is a good article by Duncan Epping that explains some of his thinking around sizing. You can find it here

I have written a script that will create all the required directories on my scratch volume and it will also set the advanced setting for you. Please note that you will have to reboot your hosts for the change to take effect.

function Set-ScratchDirectory {
<#
.SYNOPSIS
    Set a scratch directory for ESX hosts
.DESCRIPTION
    Set a scratch directory for ESX hosts on shared storage
.NOTES
    Author      : Guy Defryn
    Version     : 1.1
    Date        : 4/8/2015   
.PARAMETER Host
    Specify Host to create scratch directory for
.EXAMPLE
    Set-ScratchDirectory -Hostname ESX1
    Set scratch directory for specified host
.EXAMPLE
    Import-CSV .\scratchhosts.csv | Set-ScratchDirectory
    Set scratch directory for each host 
.LINKS
    http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1033696
.TODO
    Retrieve UUID instead of hard coding
#>
    [CmdletBinding()]
    param(
    [Parameter(Mandatory=$True, ValueFromPipelineByPropertyName=$True)][String] $Hostname

    )
    Begin{
        $Datastore = Get-datastore "scratch_vol1"
        New-PSDrive -Location $Datastore -Name ds -PSProvider VimDatastore -Root "\" | out-null
        Set-Location ds:\
    }
    Process{ 
        new-item ".locker-$Hostname" -type Directory | out-null
        Get-AdvancedSetting -Entity $Hostname -Name Scratchconfig.ConfiguredScratchLocation | Set-AdvancedSetting -Value "/vmfs/volumes/0174119b-06db5bc5/.locker-$hostname" 
        }
    End{
        Write-Host "Please reboot your host for changes to take effect" -ForegroundColor Red
    }
}

No comments:

Post a Comment