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 ๐
As shown below, I have deployed a small TTYLinux – Michelle Laverick appliance found here.ย As you can see, it is running happily.
Navigating to the datastore folder for the running virtual machine.ย Let’s select all files and hit theย Delete button.
We are asked to confirm!
Ok we are good – cannot delete file….or wait…are we?ย Yikes!ย We seeย Delete file with a status ofย Completed!
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!
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.
Same thing!ย We WERE able to delete several files from the datastore.ย The files missing compared to the above are:
- TTYLinux-6d8a4d46.hlog
TTYLinux-Snapshot1.vmsn
TTYLinux-Snapshot2.vmsn
TTYLinux.vmsd
It looks like we still have our delta disks in place.
Let’s see if we can delete snapshots now.
Delete snapshots operation is now failing!
However, can we power off and then power back 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.
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.
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