How to Recover or Remove Orphaned Virtual Machines (VMs)

By dnsstuff on April 29, 2020

When using a Hyper-V, VMware, or other hypervisor, you’ll occasionally see a virtual machine marked “orphaned.” Virtual machines in this state are unusable, and you have two main options when dealing with them: recover them or remove them. This process is usually done manually through the hypervisor itself, such as through VMware vCenter server (part of the vSphere suite).what causes orphaned virtual machines

Ideally, you would try to prevent virtual machines from becoming orphaned in the first place. Orphaned virtual machines can use up disk space and contribute to VM sprawl and problems with managing your infrastructure. You can deal with orphaned VMs manually or tackle the issue with virtual machine management software, which can monitor your virtual machine infrastructure and keep everything organized. Software like SolarWinds® Virtualization Manager (VMAN) can help you efficiently handle orphaned VMs, powered-off VMs, and VMs you no longer need, so you can reduce VM sprawl and engage in better capacity planning and VM management.

What Is an Orphaned VM?
How Do You Recover or Remove Orphaned VMs?
How to Verify Orphaned Status
How to Recover Orphaned VMs
How a VM Management Tool Can Help
Key Takeaways

What Is an Orphaned VM?

An orphaned virtual machine has been disconnected from its host in some way. The “orphaned” status means the machine may or may not exist anymore—it’s hard to tell—but in either case it’s no longer connected to the larger virtual environment in some respect.

Causes of Orphaned VMs

Orphaned virtual machines are caused by several primary factors. A virtual machine can become orphaned when it exists in the hypervisor’s server database but has been deleted at another layer of the infrastructure. Or an orphaned VM could still be in the database but incorrectly registered elsewhere, so it can’t be accessed. These issues can be caused by errors in the DNS migration or by a host failover.

Some kinds of network stress or problems can also cause a virtual machine to be marked as orphaned. In other cases, VMs can become orphaned when several different people are working on the VM infrastructure and configuration. For example, when one person changes a configuration setting or moves files and forgets to move a VM another administrator created, this leaves the VM behind. Because its related files are in another location, the VM gets marked as orphaned.

Orphaned VMs can also result when a hypervisor server or its database is restored from a snapshot or recovered from a backup. If virtual machines have been deleted after the snapshot, they might reappear in the inventory after the snapshot is restored, but they’ll be marked as orphaned in their status.

Invalid vs. Orphaned VMs

On occasion, you might see a VM marked “invalid.” This is a slightly different state than “orphaned.” If you see an invalid VM, this could mean the ESXi host—the host the vSphere client runs on—for the hypervisor isn’t responding. Alternatively, the ESXi host could be disconnected.

In other situations, a VM can appear as invalid because its configuration files are locked or missing, or because the configuration file itself contains invalid options or text errors. By contrast, orphaned machines theoretically have no problems with their files, and there’s no accompanying problem with the ESXi host. Rather, there’s a disconnect between where the orphaned VM or its files are located and where the hypervisor is trying to detect it.

How Do You Recover or Remove Orphaned VMs?

There are several approaches you can take to an orphaned VM. Orphaned virtual machine files are virtual hard disks, which means they stay as a part of the virtual infrastructure even when the VM they relate to has been deleted. These orphaned files still use up disk space, meaning they may be taking up resources even when the VM isn’t in use. Deciding what to do with an orphaned VM will depend on whether you think the virtual machine is able to be recovered, or whether you just want to delete it.

In this section, I’ll walk you through the steps required to recover or remove an orphaned VM when using VMware, including vSphere and vCenter.

How to Verify Orphaned Status

If you want to recover orphaned VM instances, it’s important to follow through with the process; be sure to go through all the steps before you decide to give up and delete or abandon the virtual machine.

The first step is to check whether the virtual machine is actually orphaned. Do this by restarting all the host management services in your hypervisor. If the VM remains in the display in vSphere with the “orphaned” tag next to it, and you believe it’s still recoverable, you can try to recover it by taking the following steps.

How to Recover Orphaned VMs

VMware orphaned VMs can be approached by migrating them to another host within vSphere, or by trying to re-register them in vCenter, which is done by deleting and re-registering the VMX file.

To recover VMware orphaned VMs using vSphere:

  1. Find the VM folder on the datastore. If you have multiple hard drives for this machine spread across different datastores, you’ll need to find the datastore with the VMX file. Whatever location is set for Hard Disk 1 is most likely to contain the VMX file.
  2. Open the folder for the datastore to view the VM folder hierarchy, and search for the VMX file.
  3. Verify you have found the correct VMX file in the datastore, and note which folder it’s in.
  4. Go back to where the virtual machine is listed in vSphere, right-click it, and select “All Virtual Infrastructure Actions.” Then choose “Remove from Inventory.”
  5. Go back to the VMX file you found and verified, and click “Register VM.”

Alternatively, you may need to remove orphaned VM instances that no longer exist on your system. If you’ve restarted the ESXi host and vCenter and the orphaned machines haven’t disappeared from the list of VMs, you’ll need to remove these manually or use a tool.

To remove VMware orphaned VMs by hand, you’ll need to go through a command-line tool such as PowerCLI. PowerCLI allows you to enter commands to manage and automate aspects of vSphere and VMware.

  1. Access PowerCLI and search for the VMs by their connection state with the following command: ExtensionData.Runtime.ConnectionState
  2. Organize the VMs by connection state to display of the machines with their state set as “orphaned.”
  3. Use the Remove-VM command (cmdlet) to remove all the VMs still displaying as orphaned even after you’ve restarted your host management services and recovered any VMs you believe are recoverable.

How a VM Management Tool Can Help

To simplify this process, I recommend implementing a virtual machine management tool, such as SolarWinds Virtualization Manager (VMAN). These kinds of solutions can speed up the VM management process—they allow you to see all your VM statuses and alerts, and make configuration changes and clear orphaned or abandoned VMs, without having to switch between multiple tools or go through the console or hypervisor itself.

SolarWinds VMAN includes utilities for monitoring and managing virtual machines, including reducing virtual machine sprawl, capacity planning, and fast troubleshooting across the full application stack. It works with both VMware and Hyper-V hypervisors, regardless of whether your infrastructure is on-premises, hybrid, or in the cloud.

Regarding orphaned virtual machines and virtual machine management, VMAN comes with a customizable dashboard to display virtual machine status and critical performance issues. Issues could include VM memory ballooning, datastore latency, phantom files, and high CPU utilization. With the sprawl management tool included in VMAN, you can power off idle VMs and delete orphaned VMDK files or snapshots to reclaim resources.

Using a virtual machine monitoring and management tool like VMAN, you can see which files and VMs are orphaned and react to them quickly to free up the usable disk space. Importantly, you can do this without logging in to vCenter, which can help speed up virtual machine management processes in general.

Orphaned Virtual Machines (VMs) – Key Takeaways

When a virtual machine has been orphaned, with a few quick fixes you can resolve the issue and, depending on the circumstances, either recover or remove the orphaned VM. A virtual machine management and monitoring tool will help simplify and speed up this process.

My favorite tool for the purpose is easily SolarWinds VMAN. By centralizing your VM management—including capacity planning, sprawl reduction, and dealing with orphaned, abandoned, or powered-off VMs—the software stops and prevents unnecessary resource utilization that could be distributed elsewhere. You can try a fully functional trial of SolarWinds VMAN free for 30 days.

In short, a good tool will assist you in dealing with any issues you may encounter with an orphaned virtual machine. Orphaned VMs don’t need to be a headache when you use an automatic tool to approach their management.

Related Posts