Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2: Process cannot access the file because it is being used by another process #6415

Open
mariusstrom opened this issue Jan 9, 2021 · 24 comments
Labels
failure-to-launch failure to launch

Comments

@mariusstrom
Copy link

Environment

Windows build number: 10.0.21277.1000
Your Distribution version: Ubuntu-20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL2

Steps to reproduce

After upgrading processor in system, WSL2 no longer starts with the error "The process cannot access the file because it is being used by another process." I have ensured that virtualization is enabled and the WSL Windows Features are there.

WSL logs:
Logs will be in Win+F Feedback per instructions.

C:\Users\marius>wmic diskdrive get Availability,Capabilities,CapabilityDescriptions,DeviceID,InterfaceType,MediaLoaded,MediaType,Model,Name,Partitions
Availability  Capabilities  CapabilityDescriptions                 DeviceID            InterfaceType  MediaLoaded  MediaType              Model                                  Name                Partitions
              {3, 4}        {"Random Access", "Supports Writing"}  \\.\PHYSICALDRIVE2  SCSI           TRUE         Fixed hard disk media  NVMe Samsung SSD 970 SCSI Disk Device  \\.\PHYSICALDRIVE2  1
              {3, 4}        {"Random Access", "Supports Writing"}  \\.\PHYSICALDRIVE0  IDE            TRUE         Fixed hard disk media  WDC WD4005FZBX-00K5WB0                 \\.\PHYSICALDRIVE0  1
              {3, 4}        {"Random Access", "Supports Writing"}  \\.\PHYSICALDRIVE1  SCSI           TRUE         Fixed hard disk media  NVMe Samsung SSD 970 SCSI Disk Device  \\.\PHYSICALDRIVE1  3

Expected behavior

WSL2 Starts up.

Actual behavior

WSL2 does not start.

@mariusstrom
Copy link
Author

feedback link: https://aka.ms/AAarxss

@njzjz
Copy link

njzjz commented Jan 10, 2021

Same error, and #5092 (comment) saves me.

@therealkenc therealkenc added the failure-to-launch failure to launch label Feb 18, 2021
@dvat-oss
Copy link

dvat-oss commented Jun 2, 2021

I've been fighting this issue for months and nothing has been working, so I switched back to WSL 1. Very frustrating.

Today I found out that if I kill every non essential process with task manager, it works. What I find frustrating is: There is no way to tell which file can't be accessed, and which process is using this "file"

All the "fixes" are just random solutions by random people running random commands that happened to work for them. Is there a sane and civilized way to figure out what resource is being used and how to release it, or are developers on Microsoft's platforms just satisfied with random trial and error to solve their problems?

@MiroValchev
Copy link

Today I found out that if I kill every non essential process with task manager, it works. What I find frustrating is: There is no way to tell which file can't be accessed, and which process is using this "file"

It's the IIS Worker Process. Still, I have to kill it on every rebuild :(

@devbhusal
Copy link

Try to check if you had accidently mounted virtual disk to the window system. Check disk management and if you see virtual disk ,just detach it from the system.

@zuhataslan
Copy link

Try starting LxssManager service:
image

Set it to run on boot.

It gives same error when LxssManager is set to manual and is stopped

@PWM-BIA-TPA-PIE
Copy link

I have set LxssManager to start automatically, and I have tried restarting the service every time I encounter this issue. It does not work consistently.

I have also tried restarting vmcompute, which does not work consistently either.

Restarting my laptop works about 90% of the time, but not all of the time.

Can we find a root cause for this issue? I use WSL extensively for work. The alternative at this point would be to exchange my Windows PC for a Mac; something I would really rather not do!

@PWM-BIA-TPA-PIE
Copy link

As a side note, it appears that if you have the virtual drive saved to a location that syncs using OneDrive, if OneDrive starts the sync then you have to kill OneDrive before being able to access WSL.

@zuhataslan
Copy link

I have set LxssManager to start automatically, and I have tried restarting the service every time I encounter this issue. It does not work consistently.

I have also tried restarting vmcompute, which does not work consistently either.

Restarting my laptop works about 90% of the time, but not all of the time.

Can we find a root cause for this issue? I use WSL extensively for work. The alternative at this point would be to exchange my Windows PC for a Mac; something I would really rather not do!

Have you tried to install WSL Preview from Windows Store and see if that works better?

@janekathambi101
Copy link

Try to check if you had accidently mounted virtual disk to the window system. Check disk management and if you see virtual disk ,just detach it from the system.

Kindly provide the steps and possibly screenshots on how to go about this thanks.

@janekathambi101
Copy link

This worked magic! Go to the Windows Command Prompt and type:

netsh winsock reset

Then Restart your computer. NB: Don't Shutdown since it did not work for me. Instead, Restart!

@nexxyb
Copy link

nexxyb commented May 8, 2022

This worked magic! Go to the Windows Command Prompt and type:

netsh winsock reset

Then Restart your computer. NB: Don't Shutdown since it did not work for me. Instead, Restart!

This worked well for me. Thanks

@NickPastukhov
Copy link

This worked magic! Go to the Windows Command Prompt and type:

netsh winsock reset

Then Restart your computer. NB: Don't Shutdown since it did not work for me. Instead, Restart!

Yes it works after restart. Thanks

@sisrfeng
Copy link

I used https://github.com/pxlrbt/move-wsl to move ubuntu to E:\wsl, then there was E:\wsl\ext4.vhdx.
I issued wsl --list --verbose and could find ubuntu but its state was "stop".
When I issued wsl, a window flashed out and I can not get into ubuntu.

Then I try wsl --unregister Ubuntu

Now wsl --list shows nothing, but E:\wsl\ext4.vhdx is still there.

wsl --import Ubuntu E:\wsl E:\wsl\ext4.vhdx shows:

The process cannot access the file because it is being used by another process.

This does not work: netsh winsock reset and restart the computer

@Biswa96
Copy link

Biswa96 commented Jul 17, 2022

Please report the issue in that move-wsl repository.

@LachlanArthur
Copy link

The VHDX that WSL2 uses is being locked by another application. It should be located at:
C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName]

Use an application like the Sysinternals handle utility to search for lock handles on VHDX files:
(note: run this in an elevated terminal)

Lachlan@Sekhmet:~$ handle vhdx

Nthandle v4.22 - Handle viewer
Copyright (C) 1997-2019 Mark Russinovich
Sysinternals - www.sysinternals.com

bztransmit64.exe   pid: 18772  type: File           4DC: C:\Users\Lachlan\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx

In my case, it was Backblaze trying to back it up, so I added VHDX to the list of excluded file extensions in Backblaze.

@hcoona
Copy link

hcoona commented Sep 10, 2022

Not work for me.

image

@xehpuk
Copy link

xehpuk commented Sep 27, 2022

The process cannot access the file because it is being used by another process.
Error code: Wsl/Service/CreateInstance/0x80070020

@TRINCETT
Copy link

Try to check if you had accidently mounted virtual disk to the window system. Check disk management and if you see virtual disk ,just detach it from the system.

Thanks a lot, this worked for me ❤️

@darkvertex
Copy link

This worked magic! Go to the Windows Command Prompt and type:

netsh winsock reset

Then Restart your computer. NB: Don't Shutdown since it did not work for me. Instead, Restart!

Fixed it for me too. Thank you. 👍

@murder
Copy link

murder commented Dec 8, 2022

wsl --import Ubuntu E:\wsl E:\wsl\ext4.vhdx shows:

The process cannot access the file because it is being used by another process.

You cannot do that.
When you use --import you are going to create a file called ext4.vhdx in the mentioned directory (E:\wsl), and what you are doing is this:

  • Calling import using a source file that will collide with the new file because they have the same name and will be in the same directory;

Just rename E:\wsl\ext4.vhdx to E:\wsl\ext4-source.vhdx for example, and do the same, like:

PS C:\Users\default> mv E:\wsl\ext4.vhdx E:\wsl\ext4-source.vhdx
PS C:\Users\default> wsl --import Ubuntu E:\wsl E:\wsl\ext4-source.vhdx

@alensiljak
Copy link

Same error, and #5092 (comment) saves me.

Worked also without the restart.

@6rz6
Copy link

6rz6 commented Jun 5, 2023

How To solve errors in ext4.vhdx while moving or mounting WSL2 distro (docker-desktop-data in my case)

  • WSL2: Process cannot access the file because it is being used by another process

  • Can't mount ext4 partition (error 0x80070020 - the file is being used by another process)

  • Error code: Wsl/Service/AttachDisk/WSL_E_ELEVATION_NEEDED_TO_MOUNT_DISK

  1. Make sure in the windows disk partition manager the ext4.vhdx in unmounted (might appear as "disk2")
  2. in cmd shutdown wsl: wsl --shutdown
  3. check all the wsl distros are stopped : D:\Docker\wsl\distro>wsl -l -v
    NAME STATE VERSION
    * Ubuntu Stopped 2
    docker-desktop-data Stopped 2
    docker-desktop Stopped 2
  4. Copy the ext4.vhdx to the new drive for example d:/docker/wsl/distro
  5. Terminate docker-desktop-data `wsl --terminate docker-desktop-data'
  6. Unregister the old ext4.vhdx: wsl --unregister docker-desktop-data ext4.vhdx
  7. change dir and go to the new location of the vhdx file
  8. mount the distro in the new location: 'wsl --mount ext4.vhdx'
  9. import it using: wsl --import-in-place docker-desktop-data ext4.vhdx
  10. Restart the wsl in cmd
  11. Restart Docker desktop in windows
  12. check all the distros are back online: D:\Docker\wsl\distro> wsl -l -v
    NAME STATE VERSION
    * Ubuntu Running 2
    docker-desktop-data Running 2
    docker-desktop Running 2

@zapazite
Copy link

zapazite commented Jul 23, 2023

I used https://github.com/pxlrbt/move-wsl to move ubuntu to E:\wsl, then there was E:\wsl\ext4.vhdx. I issued wsl --list --verbose and could find ubuntu but its state was "stop". When I issued wsl, a window flashed out and I can not get into ubuntu.

Then I try wsl --unregister Ubuntu

Now wsl --list shows nothing, but E:\wsl\ext4.vhdx is still there.

wsl --import Ubuntu E:\wsl E:\wsl\ext4.vhdx shows:

The process cannot access the file because it is being used by another process.

This does not work: netsh winsock reset and restart the computer

I had this error : "The process cannot access the file because it is being used by another process. Error code: Wsl/0x80070020" because I was moving my wsl2 from c: to d: with the wsl --import command.

Try to run (win + r) diskmgmt.msc in windows to see the disk manager. I had the same problem and windows had automatically mount my ext4.vhdx, it was listed as a unidentified virtual drive of 256G, just right click on it and select Unmount disk or detach not sure.
After that the wsl --import command worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
failure-to-launch failure to launch
Projects
None yet
Development

No branches or pull requests