VMware Cloud Community
chris_jansen
Contributor
Contributor

Swapfile location

I want to be able to specify that most of my VM's in my cluster store their swapfile with the rest of their files, but allow some to store their swapfile where the host speicifies, in this case local storage.

It would appear that there is no option in the cluster for this, as all VMs are either told to store their swapfile with the rest of their files or where the host specifies.

Therefore I will have to go round every VM and set the option manually (either store with the virtual machine or in the host's specific datastore). Seeing as I have 200+ VM's in my cluster I don't want to do this by hand,so I am trying to use the vmware-cmd command on an ESX to set this option.

The command below seems to execute OK, however nothing changes in the vmx:

\# vmware-cmd /vmfs/volumes/Management/jopr15-1/jopr15-1.vmx setconfig sched.swap.hostLocal enabled

setconfig(sched.swap.hostLocal enabled) = 1

On trying to read the config variable using vmware-cmd I get the following error:

\# vmware-cmd /vmfs/volumes/Management/jopr15-1/jopr15-1.vmx getconfig sched.swap.hostLocal

VMControl error -10: The specified property or variable is invalid or undefined

I know that sched.swap.hostLocal is the variable I must change, becuase when I set it in the GUI it appears in the vmx. Is there an updated vmware-cmd that I can use, or an aleternative method that I can use which can be scripted?

Thanks in advance.

Tags (2)
0 Kudos
4 Replies
conyards
Expert
Expert

I cannot seem to find a way to successfully edit the sched.swap.hostLocal setting contained within the VMX via Powershell. I thought that it might be possible having read the following blog entry;

http://blogs.vmware.com/vipowershell/2008/09/changing-vmx-fi.html

By following the requirements and there are a few, it should be possible to set using the command;

get-vm -Name "VMname or wildcard for a group of VMs" | set-tkevmx -key sched.swap.hostLocal -value disabled (or indeed enabled).

I can only assume that there is something wrong with the above or indeed the setting cannot be edited.

You could get around it by using the possibally devalued sched.swap.dir, this appears to ignore the setting as specified by sched.swap.hostLocal, although I guess this wouldn't be as neat. I'd also recommend checking that it isn't devalued and if you use it the estate would still be supported.

If you choose to play with it the powershell would be;

get-vm -Name "N*" | set-tkevmx -key sched.swap.dir -value /vmfs/volumes/LHN_ESX

This sent the vswp files for every server starting with N*wildcard in my test estate to the VMFS volume LHN_ESX.

get-vm -Name "A*" | set-tkevmx -key sched.swap.dir -value /vmfs/volumes/Storage1

Above sent everything starting with A*Wildcard to the VMFS volume Storage1

To see the change take effect the VMs need to be restarted, the change should appear in the VMX after the script is run.

Maybe someone has a suggestion about how to change the above scripts to store the vswp files a little neater, or could perhaps comment on if sched.swap.localHost can be edited, or indeed is sched.swap.dir is devalued.

I would add that I was playing in my test environment, think very carefully before making any of the above changes in production.

Thanks

Simon

https://virtual-simon.co.uk/
timparkinsonShe
Enthusiast
Enthusiast

For info: I use the following powershell snippet to set the sched.swap.dir on my guests. A power off-power on is required to activate (and it breaks vmotion until this is done), rather than a straight reboot. You may find that you can do the hostLocal setting in this way (although I've never tried it).

function Set-Sched

{

param($vmname, $sched="")

$gvm = get-vm $vmname

$vm = get-view $gvm.Id

$newConfig = New-Object VMware.Vim.VirtualMachineConfigSpec

$newConfig.extraconfig += New-Object VMware.Vim.optionvalue

$newConfig.extraconfig[0].Key = "sched.swap.dir"

$newConfig.extraconfig[0].Value = $sched

$vm.ReconfigVM($newConfig)

}

chris_jansen
Contributor
Contributor

Thank you both for the info, I'll give it a go with the powershell and see how it goes.

Thanks again

Chris

0 Kudos
chris_jansen
Contributor
Contributor

Solved - powershell is the way to go, but onyx was the key:

function Set-Sched

{

param($vmname, $sched="")

$gvm = get-vm $vmname

$vm = get-view $gvm.Id

$newConfig = New-Object VMware.Vim.VirtualMachineConfigSpec

$newConfig.swapPlacement = "vmDirectory"

$vm.ReconfigVM($newConfig)

}

This will allow me to set every VM to use the VM directory for swap storage, and then on the few I want to use host storage I can specify manually by hand.

Thanks again

Chris,

0 Kudos