There are situations when you need to store the virtual machine swap file from default location to some other location for e.g. on local datastore instead of LUN. One such situation can be when you are using Storage Array based replication for DR.

Let’s look at what we need to do and consider to perform the relocation of the Swap files to a shared datastore. You can keep it on a local datastore as well, however this will increase the time taken to vMotion a Virtual Machine from one host to another since a full copy of the swap file would happen.

To change the location of the SWAP files of all the virtual machines in the virtual infrastructure follow the steps below:-

 1)      Connect directly to your host or to your vCenter Server using the VMware Infrastructure/vSphere Client.

 2)      Configure the setting on the Cluster level first by Right Clicking on the cluster in question and click on Edit      Settings, select the Swapfile Location and select the option “Store Swapfile in the datastore specified by host”.


 The next step would be to set it up on each and every host in the cluster

 3)      Click the Configuration tab for the ESX host.

 4)      Click Virtual Machine Swapfile Location and click Edit.


5)      Specify the datastore where you want to store the virtual machine swap files.

6) After restarting your virtual machines, ensure the swap file is located on the specified host datastore.

An important point to note is that you would have to redo this setting on a host every time the HOST   is removed from the cluster or else the Swapfile location will default to with “Virtual Machine Files”.

Please ensure that we size this datastore appropriately for performance and Space. The space should be greater than or equal to the total vRAM assigned to the all the Virtual Machines in the Environment.

The performance of this datastore is important as the SWAP files help a VM swap out memory pages when the host is memory constrained, hence this datastore should be backed up by disks which have good performance characteristics. With vSphere 5.1 you can actually select the datastore for storing the swapfiles as a SSD based location which will improve the performance drastically.

 To change the swap file location for a single virtual machine:

  1. Power off the virtual machine.
  2. Unregister the virtual machine. Right-click the virtual machine in the Inventory and choose Remove from Inventory.
  3. Connect to the host using SSH client.
  4. Change directory to the folder where the virtual machine resides:
    cd /vmfs/volumes/datastore_name/virtual_machine_folder
  5. Edit the virtual machines configuration file with a text editor.
  6. Add this line:
    sched.swap.dir = /vmfs/volumes/datastore/ 
  7. Register the virtual machine again.
Posted in: Vmware.
Last Modified: April 3, 2014

Leave a reply