Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 293210

How can I automate creating a scratch partition for a large number of hosts?

$
0
0

I would like some help with scripting the following steps to cerate a scratch partition on all hosts that do not have one and then reprot back to me which hosts had to have one created.

 

all of my ESXi hosts have a boot LUN with space, all the boot LUNs are named with the same naming conveiton i.e. "hostname-localstorage"

 

I'd like to come up with a script that will check each host in a cluster for a scaratch partition, if it does not have one create the folder ".locker-hostname" on local storrage and then set the scratch partition to the new location. Then report back to me which hosts already had a scratch partition and which ones it had to create a scratch parition for so I can then plan a good time to put the hosts with newly created scratch partitions into mainenance mode and reboot them.

 

I pasted the manual way to do this below. I'd appreciate any help anyone can give and it willbe much appreciated. I am trying to avoid doing the below 1000 times. Thanks in advance...

 

 

 

Note: Before proceeding, ensure that /tmp/scratch exists. If it does not exist, create it using the command #mkdir /tmp/scratch.
  1. Open a command prompt where the PowerCLI is installed.
  2. Connect to the ESXi host using the command:

    connect-viserver ESXHostnameOrIP

  3. Obtain a list of datastores reachable from this ESXi host using the command:

    Get-Datastore

  4. Mount a datastore read/write as a PSDrive using the command:

    New-PSDrive -Name "mounteddatastore" -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore "DatastoreName")

  5. Access the new PSDrive using the command:

    Set-Location mounteddatastore:

  6. Create a uniquely-named directory for this ESXi host using the command:

    New-Item "DirectoryName" -ItemType directory

    For example:

    New-Item ".locker-ESXHostname" -ItemType directory

  7. Check the current value of the ScratchConfig.ConfiguredScratchLocation configuration option using the command:

    Get-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation"

  8. Change the ScratchConfig.ConfiguredScratchLocation configuration option, specifying the full path to the directory created in Step 6, using the command:

    Set-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/DatastoreName/DirectoryName"

    For example:

    Set-VMHostAdvancedConfiguration  -Name "ScratchConfig.ConfiguredScratchLocation" -Value  "/vmfs/volumes/Datastore1/.locker-ESXHostname"

  9. Put the ESXi host in maintenance mode and reboot for the configuration change to take effect.

 

 

 

 

Mike P


Viewing all articles
Browse latest Browse all 293210

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>