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

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 19
  • Comments: 25

Most upvoted comments

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.

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!

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?

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.

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.

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

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.

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

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 ❤️

Try starting LxssManager service:
image

Set it to run on boot.

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