VMware

Accidentally delete VMware datastore files for a running VM?

Can you accidentally delete VMware datastore files for a running VM? A look at what can be done accidentally deleting files from a VMware datastore

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-cant-delete-a-running-virtual-machine-from-vSphere-web-client
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
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
Selecting all VM files in datastore and hitting delete!

We are asked to confirm!

Confirming-the-delete-operation
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
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
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
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
    TTYLinux-Snapshot1.vmsn
    TTYLinux-Snapshot2.vmsn
    TTYLinux.vmsd

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

Key-virtual-machine-files-are-now-deleted
Key virtual machine files are now deleted

Let’s see if we can delete snapshots now.

Attempting-to-delete-the-snapshots
Attempting to delete the snapshots

Delete snapshots operation is now failing!

Snapshot-delete-fails
Snapshot delete fails

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

Powering-off-to-test-power-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
Powering on is successful
VM-is-able-to-boot-even-with-key-snapshot-files-missing
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
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

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

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