ESXi 6.0 – Switching from persistent scratch to transient scratch

KB article 1033696 is very helpful when you want to configure persistent scratch on your USB/SDCard/PXE booted ESXi host, however when you want to go the other way, things can be slightly complicated.

Consider the following situation. You have installed ESXi onto a local USB stick, and have temporarily retasked a drive from what will become your VSAN array, to be used to run up VCenter and a PSC.
On the next reboot, ESXi will see the persistent local storage, and automatically choose to run scratch on it.
From that point onwards, how do you switch back and release the disk for use by VSAN?

You can’t set the advanced configuration "ScratchConfig.ConfiguredScratchLocation" to  blank (eg “”), that was the first thing I tried. It accepts the command, but the setting remains pointed at the VMFS location.

You can’t just unmount or delete the VMFS filesystem, it’s in use

You can’t set the advanced configuration "ScratchConfig.ConfiguredScratchLocation" to  /tmp/scratch, it accepts the value, but on reboot, it’s discovered the VMFS filesystem again.

Other combinations of advanced configuration settings, and editing or removing the /etc/vmware/locker.conf also failed to stop it from loading the scratch onto the VMFS filesystem at boot.

In the end, I was able to get around this, by using storcli to offline the disk. The server could then be rebooted without mounting the VMFS filesystem, so scratch was then running from /tmp/scratch (on the ramdisk). The disk could then be brought online again, and the VMFS filesystem destroyed. I guess an alternative approach would be to point the scratch location at an NFS location, which should take precedence over a “discovered” local persistent VMFS filesystem, and allow the VMFS filesystem to be deleted.

I hope that helps someone else, as I spent far more time than I should have going round in a loop, steadily losing my marbles, because there didn’t seem to be any information around about how to do it.

Advertisements

7 thoughts on “ESXi 6.0 – Switching from persistent scratch to transient scratch

  1. I’ve found a way to work around this even with local storage (so no storcli available) and no physical access to the server (no pulling disks)…

    How to get rid of scratch (.locker) on a local VMFS if you need to repartition the disk (use for vSAN in this case)
    ===================================================================================================================
    Issue:
    ——
    If you only have 1 local VMFS and no HW access to a server it’s not really possible to get rid of scratch even after reconfiguration and rebooting the ESXi.

    Resolution:
    ———–
    1. Migrate all VMs out of the datastore/disk you want to repartition and put the host into Maintenance Mode (this is a MUST if you already have vSAN enabled!) – I’d consider evacuating everything just in case

    2. Create a new scratch directory structure (could be on a different local storage, NFS, in /tmp or whatsoever), lets assume we want to move back to ramdisk: /tmp/scratch
    – SSH to ESXi as root
    – run:

    export NEWSCRATCH=”/tmp/scratch”
    mkdir -p ${NEWSCRATCH}/{core,var/tmp,log}

    ## OPTIONAL:
    ## Store old scratch location in an evironment variable to check later
    OLDSCRATCH=”$(readlink -f /scratch)”

    3. Change the scratch location to a different location using either of these depending on availability:
    a) host-client (https:///ui – Host – Manage – System – Advanced Settings – ScratchConfig.ConfiguredScratchLocation – Edit)
    b) web-client (https:///vsphere-client – Home – Hosts and Clusters – / – Configure – System/Advanced System Settings – Edit – ScratchConfig.ConfiguredScratchLocation)
    c) h5-client (https:///ui – …)
    d) vsphere-client (Old C# – …)
    e) SSH to ESXi as root and run: vim-cmd hostsvc/advopt/update ScratchConfig.ConfiguredScratchLocation string “/tmp/scratch”

    4. Check that location has changed (using SSH):
    – run:

    cat /etc/vmware/locker.conf; echo
    # This should show “/tmp/scratch 0”

    vim-cmd hostsvc/advopt/view ScratchConfig.ConfiguredScratchLocation
    # value should contain “/tmp/scratch”

    5. Repoint current scratch to a new location (still SSH):
    – run:

    ln -sfnv “${NEWSCRATCH}” “/scratch”

    6. Restart _all_ running services (still SSH) – this may take a lot of time
    – run:

    ( for s in /etc/init.d/*; do echo $s; $s status && $s restart; done )

    7. Check that new location is used (using SSH):
    – run:

    vim-cmd hostsvc/advopt/view ScratchConfig.CurrentScratchLocation
    # value should contain “/tmp/scratch”

    ## OPTIONAL:
    ## You can also check new files are created by vmsyslog and epd
    ls -ltr ${NEWSCRATCH}/log/
    ## You should see log files with current date/time
    ls -ltr ${OLDSCRATCH}/log/
    ## You should see log files with slightly older date/time (before restarting the services)
    ## You can repeat with other files and directories inside scratch, OLDSCRATCH should not contain any new/modified files after the restart of the services

    8. Unmount the datastore and clear the partition using GUI – it should not be “in-use” anymore

    9. When done with the disk I’d recommend rebooting the ESXi before exiting Maintenance Mode

  2. Thanks million.
    Basically I wanted to remove scratch from Persistent storage to local server.
    I did connect with SSH then ran following commands –
    1) ls – To check if tmp dir exist
    2) cd tmp
    3) ls – to check if scratch dir exist
    4) mkdir scratch
    5) vim-cmd hostsvc/advopt/update ScratchConfig.ConfiguredScratchLocation string /tmp/scratch
    6) cat /etc/vmware/locker.conf; echo

  3. A simple working guide:

    1) Put your ESXi host in “Maintenance mode”.

    2) Connect to the shell (SSH) and execute:
    $ mkdir /tmp/scratch
    $ vim-cmd hostsvc/advopt/update ScratchConfig.ConfiguredScratchLocation string /tmp/scratch
    $ ln -sfnv /tmp/scratch /scratch
    $ ( for s in /etc/init.d/*; do echo $s; $s status && $s restart; done )

    3) Connect to the UI and umount the datastore. Then remove it.

    4) Reboot

    That’s all! Remember to disable the Maintenance mode.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s