minikube: hyperv: Unable to remove machine directory: ....vmcx: The process cannot access the file because it is being used by another process.

I have the same problem and tried this:

> minikube stop
*
X Unable to stop VM: open C:\Users\Csongor Halmai\.minikube\machines\minikube\config.json: The system cannot find the file specified.
*
* minikube is exiting due to an error. If the above message is not useful, open an issue:
  - https://github.com/kubernetes/minikube/issues/new/choose

and then

> minikube delete
* Removing C:\Users\Csongor Halmai\.minikube\machines\minikube ...
*
X Unable to remove machine directory: remove C:\Users\Csongor Halmai\.minikube\machines\minikube\minikube\Snapshots\0113C205-19E6-4E44-9903-D0AA9C750A39.vmcx: The process cannot access the file because it is being used by another process.
*
* minikube is exiting due to an error. If the above message is not useful, open an issue:
  - https://github.com/kubernetes/minikube/issues/new/choose

This seems to be show-stopper for me. 😦

> minikube version
minikube version: v1.9.0
commit: 48fefd43444d2f8852f527c78f0141b377b1e42a

_Originally posted by @halmai in https://github.com/kubernetes/minikube/issues/4286#issuecomment-605488971_

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I believe this is no longer an issue in more recent releases.

My solution

Windows 10 pro 1909 (os build: 18363.1256)
minikube version: v1.15.1
commit: 9f1e482427589ff8451c4723b6ba53bb9742fbb1

In my case, I installed minikube by Chocolatey. But it worked as below. Even though I ran commands on PowerShell, Chocolatey shell was executed!

image

So I found a process that uses the minikube directory,

image

and I killed the process.

taskkill /F /PID <PID_NUMBER>

PURGE MINIKUBE.

minikube delete --purge
# Successfully purged minikube directory located at - [C:\Users\csu04\.minikube]

I installed minikube by Windows installer, not the Chocolatey. Finally, the command below was executed well.

minikube start
❯ kubectl get po -A
NAMESPACE     NAME                               READY   STATUS    RESTARTS   AGE
kube-system   coredns-74ff55c5b-cnn46            1/1     Running   0          22m
kube-system   etcd-minikube                      1/1     Running   0          22m
kube-system   kube-apiserver-minikube            1/1     Running   0          22m
kube-system   kube-controller-manager-minikube   1/1     Running   0          22m
kube-system   kube-proxy-xk2nk                   1/1     Running   0          22m
kube-system   kube-scheduler-minikube            1/1     Running   0          22m
kube-system   storage-provisioner                1/1     Running   1          22m

stopping hyper-v service worked for me

I had the same issue, and in Hyper-V Manager I deleted the minikube instance running. I tried the command again:

minikube delete --all --purge

and it works!

image

Stopping the service in hyper-v manager solved the problem for me.

I was also facing the same issue , but after Shutting down all the process related to Hyper V from task manager my problem got resolved

@tstromberg thanks for the quick response.

It is possible that the files it was unable to delete were coming from an earlier version of minikube. However, even after stopping Hyper-V Host Compute Service from the Task Manager, I was unable to delete the files, which is strange. Both minikube delete and manual delete via Explorer failed. The solution I chose was to reboot win10 in safe mode and delete all the Snapshots manually. After a normal reboot everything works fine.

Hey @halmai -

I’m very curious about what happened here, because it’s not supposed to be possible, but clearly it is. From your stop output:

X Unable to stop VM: open C:\Users\Csongor Halmai\.minikube\machines\minikube\config.json: The system cannot find the file specified.

minikube was asked to stop a cluster that does not have any local state associated to it, so it failed. Is it possible that you accidentally deleted or moved C:\Users\Csongor Halmai\.minikube\machines, or do we have a bug somewhere?

Alternatively, is it possible that you called stop with a pre-v1.9.0 version of minikube first? We didn’t handle Hyper-V deletion so well before.

As far as your delete output: X Unable to remove machine directory: remove C:\Users\Csongor Halmai\.minikube\machines\minikube\minikube\Snapshots\0113C205-19E6-4E44-9903-D0AA9C750A39.vmcx: The process cannot access the file because it is being used by another process.

This is stating that Hyper-V does in fact have a virtual machine running from this directory, even if the minikube state is gone. This is recoverable by launching the Hyper-V console and shutting the minikube VM down. Then minikube delete should function as expected.

Let me know how it works out. If the instructions work, I’ll make sure the error message points users to the appropriate solution. We can do a lot better here.