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.

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

Category: Uncategorized Tags:

15 thoughts on “How to control maximum number of VMware snapshots

  1. 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?

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

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

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

    • 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

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

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

  3. 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.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”);

  4. This didnt work in ESXi5Update1: snapshot.maxSnapshots = 3

    This DID work: snapshot.MaxSnapshots = 3

    Notice the M uppercase in Max. Case matters.

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


    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.

Thanks for the comment!