WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / How to control maximum number of VMware snapshots

How to control maximum number of VMware snapshots

10.31.2010 by William Lam // 21 Comments

There are currently no methods of controlling the number of VMware snapshots using vCenter or ESX(i) permissions today, you either provide the snapshot privilege or you deny it all together. I recently discovered an undocumented .vmx entry that allows you to control the maximum number of VMware snapshots for a given virtual machine. By default, a virtual machine can have a snapshot tree depth of 31, in the worse case scenario supporting up to a maximum of 496 snapshots.

Here is what a VM looks like with 496 snapshots (unexpanded):

 

Note: If you are interested in what this looks like fully expanded, take a look at the screenshot at the very bottom of this post.

If you like to prevent the above or at least control the maximum number of snapshots for a given virtual machine, you can add the following into a VM's .vmx configuration file. Ideally, this is deployed using vSphere API as there is no need to directly edit the VMX's file and this can also be applied to a live running VM (another benefit of using the vSphere API).

Here is an example using PowerCLI:

$vm = Get-VM -Name TestVM
New-AdvancedSetting -Name snapshot.maxSnapshots -Value 1 -Entity $vm

For those that prefer using another vSphere SDK, you just need to use the ReconfigVM_Task() to add the VM Advanced Setting. Please take a look at this sample for here for how to add/update VM Advanced Settings.

snapshot.maxSnapshots = "n"

where n = max number of snapshots and n <= 496

Here is a screenshot of adding this .vmx parameter using the vSphere Client:

The virtual machine above already has one snapshot and per the configuration change, we should not be able to take any additional snapshots:

Next, we will try to take a second snapshot:

As you can see, an error is thrown that we have reached the maximum number of permitted snapshots. If you would like to disable snapshots all together, you can set the value to be 0 and this will prevent anyone from taking snapshots, including administrators.

Here is a an screenshot of the expanded view of a VM with 496 snapshots:

Note: These snapshots were created with a VM running in an vESXi host and script to exhaust the maximum snapshot depth of 31. Each snapshot level was also exhausted with the maximum number of snapshots. Starting from level-1: it was the maximum depth minus 1, level-2: it was maximum depth minus 2, and so fourth. This was just a test to see what the system could handle, you should not try this a home or on a production VM 😉 Use at your own risk

More from my site

  • VM snapshot retention-based removal in vSphere 8.0 Update 3
  • Preserving VM snapshot hierarchy across vCenter Servers
  • Managing VM snapshot retention policies using the VMware Event Broker Appliance (VEBA)
  • New Parameter in vim-cmd snapshot.remove for ESX(i) 4.1 Update 2
  • vSphere ESX 4.0 - Crash VM Bug?

Categories // Automation, vSphere Tags // snapshot

Comments

  1. *protectedProteus says

    01/11/2011 at 2:46 pm

    Does it work on vSphere (esxi) 4.0?
    When i enter the parameter "snapshot.maxSnaphots 1" in a .vmx file it doesn't limit snapshot in any way.

    Is there anything i might have overlooked?

    Reply
    • *protectedRobert says

      03/15/2012 at 12:49 am

      One of my students tried it today in class and found something strange, or at least I thought so.

      He entered
      snapshot.maxSnaphots = 3
      in the vmx file, saved the change and restarted the VM. It did not work. Then he tried
      snapshot.maxSnaphots = "3"
      in the vmx file, saved it, restarted the VM, and it worked.
      Why the quotes around the number mattered I don't know. Following the normal syntax since there were no spaces or and other such strangeness, I did not think the quotes were necessary. Oh well, it worked.

      Reply
  2. *protectedvinay chilakamarri says

    02/09/2012 at 10:34 pm

    a very useful tip. tested it for esxi 5 and it works. thank you!

    Reply
  3. *protectedAnonymous says

    06/02/2012 at 3:11 am

    hi, can you please explain to me where the 496 maximum value comes from? I see that you said "By default, a virtual machine can have a snapshot tree depth of 31, in the worse case scenario supporting up to a maximum of 496 snapshots."

    I know the the maximum tree depth is 31, but I don't understand how you determined that this makes the maximum total number of snapshots be 496.

    Reply
    • *protectedWilliam says

      06/02/2012 at 4:19 am

      Take a look at the very last paragraph which explains how the 496 snapshots were created for a single VM

      Reply
    • *protectedAnonymous says

      06/02/2012 at 3:12 pm

      OK, I see that, but I still don't understand why you say that 496 is the limit.

      I don't see any limit to the width of a tree. So, I believe that you can create much more than 496 snapshots.

      Let's say that you do the following;
      1 - create a clean VM
      2 - take a snapshot of that VM and call this snapshot "root"
      3 - take another snapshot and call it "1". Now you have a tree with "root" as the parent and "1" as the child.
      4 - create a snapshot tree with 20 snapshots in it under "1".

      now, in a loop:
      1 - revert to "root"
      2 - create a snapshot with a number "2", "3", etc.
      3 - create a snapshot tree with 20 snapshots in it under the snapshot that was created in step 2.

      repeat this loop 100 times. Now you will have 2000 snapshots, which is, of course, more than 496.

      Reply
    • *protectedWilliam says

      06/02/2012 at 3:42 pm

      That's exactly what I did. The maximum depth for a given tree is 31, so I created a script which would max out the depth which is 31, then revert back and the next level the max will be 30 and so fourth ... if you do the math on 31+30+29....1 you get 496. If you can get more, would love to see it, but afaik, this is the max

      Reply
    • *protectedAnonymous says

      06/02/2012 at 10:37 pm

      Yeah, I understand what you did, but I don't think that you are seeing what I was suggesting.

      Let's try a simpler script:
      1 - start with clean VM
      2 - take a snapshot, call it "root"
      3 - in a loop
      a - revert to "root"
      b - take a snapshot

      continue this until "root" has 497 or more children.

      I don't see why this wouldn't work or why it wouldn't create more than 496 snapshots.

      Reply
    • *protectedWilliam says

      06/02/2012 at 10:54 pm

      Yea I'm sorry, I don't quite follow what you're saying. Perhaps a diagram or better yet, you could write the script and show > 496 snapshots.

      Reply
  4. *protectedAnonymous says

    06/03/2012 at 2:35 pm

    I have a diagram, but I'm not sure how to post images here.

    Here's C# code that uses PowerCLI to create 600 snapshots. It can be used to create as many as you want by changing the max value on the outer for loop.

    private void createSnapshots()
    {
    VimClient client = new VimClient();
    client.Connect("https://vSphereServer/sdk");
    client.Login("username", "passsword");
    NameValueCollection filter = new NameValueCollection();
    filter.Add("name", "VMname");

    VirtualMachine vm = (VirtualMachine)client.FindEntityView(typeof(VirtualMachine), null, filter, null);
    if (vm != null)
    {
    MessageBox.Show("got a vm : " + vm.Name + " " + vm.Config.Uuid);

    VirtualMachineSnapshotTree snapTree = vm.Snapshot.RootSnapshotList[0];

    if (snapTree.Name == "root")
    {
    ManagedObjectReference firstSnapMOref = snapTree.Snapshot;

    VirtualMachineSnapshot firstSnap = (VirtualMachineSnapshot)client.GetView(firstSnapMOref, null);

    int i = 0, j = 0, snapCount = 1;
    for (j = 0; j < 200; j++)
    {
    firstSnap.RevertToSnapshot(null, null);

    for (i = 1; i < 31; i++)
    {
    vm.CreateSnapshot("snap-" + snapCount++.ToString(), null, false, false);
    }
    }

    MessageBox.Show("made " + snapCount + " snapshots");
    }
    }
    }

    Reply
    • *protectedWilliam says

      06/03/2012 at 2:41 pm

      You can probably just link to the image. Have you tried to create >496 snapshots?

      Reply
    • *protectedAnonymous says

      06/03/2012 at 5:06 pm

      I don't have anywhere to host the image at the moment.

      Yes, after posting that script, I ran it. I now have a VM with over 875 snapshots.

      Reply
  5. *protectedbrumer0 says

    07/31/2012 at 9:00 pm

    This didnt work in ESXi5Update1: snapshot.maxSnapshots = 3

    This DID work: snapshot.MaxSnapshots = 3

    Notice the M uppercase in Max. Case matters.

    Reply
    • *protectedWilliam says

      07/31/2012 at 9:04 pm

      @brumer0,

      Interesting, usually these settings are not case-sensitive and should work in general. Thanks for sharing.

      Reply
  6. *protectedSteveinMA says

    08/03/2012 at 3:33 pm

    I have found that on ESX 4.1 at least, you can set
    snapshot.maxSnapshots="2"
    in the .vmx file for a VM, and it will prevent you from taking a 3rd snapshot.

    BUT

    1. the value will be reset if there are already more than 2 snapshots (it'll be reset to the number of current snapshots).

    and even worse...

    2. If you rename the machine in vSphere/vCenter, the maxSnapshots line will be removed, thus removing any limit to number of snapshots.

    Reply
  7. *protectedVaibhav says

    12/03/2015 at 10:58 pm

    Is there a work around via which I disable the snapshot for a VM (putting the snapshot number as 0) without having to power it off. Can I do this on the fly

    Reply

Trackbacks

  1. 1200+ nieudokumentowanych parametrów .vmx | inleo – wirtualizacja, cloud computing, storage, serwery, it says:
    01/08/2015 at 8:27 am

    […] http://www.virtuallyghetto.com/2010/10/how-to-control-maximum-number-of-vmware.html snapshot.maxSnapshots = sterowanie maksymalną liczbę snapshotów VMware […]

    Reply
  2. How to control maximum number of VMware snapshots w/PowerCLi – ps1code.com says:
    05/24/2017 at 1:01 am

    […] years ago, the VMware guru William Lam wrote this excellent article. Today we will automate his solution with […]

    Reply
  3. Snapshot – VMWARE4U says:
    12/21/2017 at 1:55 am

    […] the maximum number of snapshot per virtual machine. There is an undocumented VMX entry as per William Lam’s article, which can control the maximum number of snapshots per virtual […]

    Reply
  4. Mastering VMware Snapshots – ITninja says:
    02/27/2018 at 6:06 pm

    […] the maximum number of snapshot per virtual machine. There is an undocumented VMX entry as per William Lam’s article, which can control the maximum number of snapshots per virtual […]

    Reply
  5. Kan ikke slette snapshot på Vmware maskine – harddrive says:
    07/04/2020 at 12:02 am

    […] Læs evt mere her […]

    Reply

Leave a Reply to ProteusCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025