Accidentally delete VMware datastore files for a running VM?

In case you are curious or may have run into this question before as you are browing around in the datastore browser – Can you accidentally delete VMware datastore files for a running VM? Most may think, since the virtual machine is powered on, there would not be a way to delete critical files from the datastore since they would be in use. This is partially true for some of the important files that make up the layout of the files for a virtual machine. However, the short answer is “YES” it is possible to delete datastore files for a running VM and it can cause quite a bit of damage and problems for an administrator. Let’s take a look at a couple of tests and the behavior of each when intentionally trying to delete datastore files of a running virtual machine.

Accidentally deleting VMware datastore files for a running virtual machine

This was a fun little project I wanted to test as I had a couple of quick questions tossed out there about this concerning getting rid of unneeded files on a datastore.  In the following two scenarios, we take a look at what happens when you go to a datastore and select all files of a running virtual machine, and hit delete!  Does vSphere automatically save our bacon on this?  What happens?  We know there is a fail safe built into vSphere where you can’t right click and Remove from Inventory or Delete from disk a running virtual machine.  Let’s look at the datastore 🙂

You can’t delete a running virtual machine from vSphere web client

As shown below, I have deployed a small TTYLinux – Michelle Laverick appliance found here.  As you can see, it is running happily.

A test TTYLINUX virtual machine

Navigating to the datastore folder for the running virtual machine.  Let’s select all files and hit the Delete button.

Selecting all VM files in datastore and hitting delete!

We are asked to confirm!

Confirming the delete operation

Ok we are good – cannot delete file….or wait…are we?  Yikes!  We see Delete file with a status of Completed!

Files were successfully deleted!

The VM is still running, but can we power it back on?  Wow, we can’t!  File TTYLinux.vmdk was not found.  So we can delete extremely important files while the VM is running!

The power on operation of the VM now fails

Deleting files of a running virtual machine with snapshots

Does it matter if the virtual machine has snapshots in place?  I created a couple of test snapshots on the VM as you can see below.  Same operation (using the latest HTML5 3.27 UI since we have the new datastore browser that pops out).  Selected all and then hitting the Delete button.

Delete virtual machine files with snapshots

Same thing!  We WERE able to delete several files from the datastore.  The files missing compared to the above are:

  • TTYLinux-6d8a4d46.hlog

It looks like we still have our delta disks in place.

Key virtual machine files are now deleted

Let’s see if we can delete snapshots now.

Attempting to delete the snapshots

Delete snapshots operation is now failing!

Snapshot delete fails

However, can we power off and then power back on?

Powering off to test power on

As we can see, we can power off and power back on the virtual machine that we deleted files from while it was running snapshots.  The difference here is we still have the snapshot disk chain in place for booting the virtual machine.

Powering on is successful
VM is able to boot even with key snapshot files missing

Delete VMware virtual machine datastore files with caution!

The above simple example shows that we must browse a datastore with caution.  You CAN delete accidentally delete datastore files for running VM!  This can lead to serious problems.  You may be left with a running virtual machine that can’t be powered off due to not being able to power on.  Also, with snapshots, you may be left in a state of orphaned running snapshots that can’t be deleted.  I was actually able to clone from that point however.

Below, you see the TTYLinux2 that was cloned from the first virtual machine.

Cloning a broken virtual machine

The moral of the story is proceed with caution ultimately.  Don’t assume files are not being used without doing some checking first.  Take a look at the following VMware KB that details how to check for locks on files, which is a good way to tell if virtual machine files are being used – https://kb.vmware.com/s/article/10051

Back to top button