How to change Swap file Location of Virtual Machines


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”.

Image

 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.

Image

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.

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Vmware. Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s