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

Failed to attach disk 'LocalState\ext4.vhdx' to WSL2: The system cannot find the file specified. #10032

Open
1 of 2 tasks
liudonghua123 opened this issue Apr 27, 2023 · 52 comments

Comments

@liudonghua123
Copy link

liudonghua123 commented Apr 27, 2023

Windows Version

Microsoft Windows [Version 10.0.22621.1555]

WSL Version

1.2.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.90.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Jan 27 02:56:13 UTC 2023

Distro Version

Kali linux

Other Software

No response

Repro Steps

  1. uninstall the old kali linux
  2. reinstall kali linux from ms store.

Expected Behavior

The Kali linux installed successfully.

Actual Behavior

Could not open/start it when installed finished.

Diagnostic Logs

Failed to attach disk 'C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState\ext4.vhdx' to WSL2: The system cannot find the file specified.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Press any key to continue...
C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg>du -v

DU v1.62 - Directory disk usage reporter
Copyright (C) 2005-2018 Mark Russinovich
Sysinternals - www.sysinternals.com

           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AC\INetCache
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AC\INetCookies
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AC\INetHistory
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AC\Temp
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AC
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\AppData
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Local\Microsoft
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Local
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Roaming\Microsoft\Windows\Start Menu\Programs
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Roaming\Microsoft\Windows\Start Menu
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Roaming\Microsoft\Windows
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Roaming\Microsoft
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache\Roaming
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalCache
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\LocalState
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\RoamingState
           8  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\Settings
          32  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\SystemAppData\Helium
          32  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\SystemAppData
           0  C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg\TempState

Totals:
Files:        8
Directories:  21
Size:         40,960 bytes
Size on disk: 135,168 bytes


C:\Users\Liu.D.H\AppData\Local\Packages\KaliLinux.54290C8133FEE_ey8k8hqnwqnmg>
@cakeGH
Copy link

cakeGH commented Apr 30, 2023

Hello, I'm new to this computer stuff but I had this issue too. Couldn't find anything except a short 2min YT video. Basically you need to re-install and run your Unix installation through Powershell first.

Steps:
run Windows Powershell as Admin
wsl --uninstall kali-linux
wsl --install --distribution kali-linux

This will run kali-linux in the Powershell terminal. You can just close the Powershell terminal then run the app from the store. Not sure how or why it works but it worked for me. Hope this helps you and whoever encounters this!

@davhdavh
Copy link

davhdavh commented May 8, 2023

>wsl --unregister ubuntu
followed by
>wsl --install
fixes the problem for ubuntu atleast

@dreamflasher
Copy link

I can confirm, a simple reinstallation via Microsoft Store does not work, but wsl unregister and then install does.

@kilogold
Copy link

I can confirm, a simple reinstallation via Microsoft Store does not work, but wsl unregister and then install does.

Agreed. Same issue. This is the way.

@bi44fv
Copy link

bi44fv commented Jun 10, 2023

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

it worked for me, thanks alot

@danikane
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

On point! Thanks!

@githubrowdy
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

It does also for kali
wsl --unregsiter kali-linux

@mcscwizzy
Copy link

Can confirm the unregister and install works. Saved my backside today.

@azuraerae
Copy link

I can confirm, a simple reinstallation via Microsoft Store does not work, but wsl unregister and then install does.

This is it 👍

@pauljones0
Copy link

This fixed it. Thank you

@V4mp1reeee
Copy link

i have it loading, its saying installing ubuntu, im worried.

@kumarchandresh
Copy link

> wsl --unregister ubuntu
followed by reinstall from ms store also worked.

@alizul01
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

worked!

@bmaciag
Copy link

bmaciag commented Jul 29, 2023

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

worked. thx

@marviniciuz
Copy link

I have the same problem how to solve?

@marviniciuz
Copy link

I achieved
after running the commands
wsl --unregister ubuntu and wsl --instal

after uninstalling ubuntu from the microsoft store and installing again

@sradu86
Copy link

sradu86 commented Aug 7, 2023

in pws:
wsl --unregister kali-linux

wsl --install kali-linux

@meyerbro
Copy link

It's kind of obvious that loosing all your work would fix it guys.
But what's the solution when we can't/don't want to lose all the data???

@TheFlash787
Copy link

It's kind of obvious that loosing all your work would fix it guys. But what's the solution when we can't/don't want to lose all the data???

If your vhdx file is missing, it might be that your data is already gone -- as that file has been deleted which is the storage volume for the Ubuntu operating system. Uninstalling and reinstalling just reinstates that fresh volume.

@Senbonzakura1234
Copy link

Senbonzakura1234 commented Sep 9, 2023

Facing this problem too, when trying to install wsl

@johnnymatt
Copy link

Works (as of 11/09/2023):
wsl --unregister ubuntu
wsl -- install

@daniel-rodriguez-azumo
Copy link

It's kind of obvious that loosing all your work would fix it guys. But what's the solution when we can't/don't want to lose all the data???

TL;DR: Go to "Turn windows features on and off" -> uncheck windows subsystem for linux -> restart -> do it again and check the windows subsystem for linux box and after restarting again you are good to go.

I had the same issue as OP, I tried moving my ext4.vhdx disk file, in an attempt to free it from whatever process was using it, it denied this action but also told me which process was using this file, it was System in my case, so I tried the steps described on my tldr and it worked, without losing data or any side effects.

I also tried other solutions which didn't work: Signing out of my user, restarting, closing other processes.

Hope this helps.

@Silic0nS0ldier
Copy link

Silic0nS0ldier commented Sep 17, 2023

I've run into the same problem. Tried using Recuva to see if I could restore the file with no luck.

I wonder if this data loss is related to behaviours associated with these directories. From the UWP docs;

  • Each UWP app gets several folders under c:\users<user name>\AppData\Local\Packages<app package identifier>\, which appears to be the case for WSL distros as well. At least those distributed via the store.
  • LocalState is for data local to the current device. OneDrive backs up this data, such that it can be restored on new devices.
  • There is also RoamingState (in Windows 11 it no longer roams) and TempState.
    Such backup behaviour should be readonly for the current device, so I do not know how it could cause this. I just know from the docs that it is a mechanism that touches this area and that something abnormal has occurred.

Possibly related issues;

I know on Android if the certificate used to sign an app changes, data-loss occurs. I believe the same applies to UWP/sandboxed apps on Windows. So in my case if the certificate for Ubuntu 22.04 changed with an app update, that may have wiped the data (possibly in a manner that leaves just enough behind that errors are raised rather than a new install being started).

Looking at the last modified date in MS Store, I can see "Ubuntu 22.04.2 LTS" was modified on 2023-09-03, which is between my last usage and discovery of this issue. Currently installed version is 2204.2.47.0.

Assuming the issue was caused by LocalState being wiped due to certificate changes, preventing reoccurrence means having the WSL files live somewhere else. The easiest way to achieve this would be;

  1. Install as normal.
  2. Open shell (not in installed distro, Windows Powershell is what I used)
  3. Export distro
    wsl --export <distro-name> $env:UserProfile\Downloads\distro.tar
  4. Delete distro
    wsl --unregister <distro-name>
  5. Import exported distro
    wsl --import <distro-name> <install-location> $env:UserProfile\Downloads\distro.tar

Output is slightly different to what OP posted, so here it what I got (to aid future searches).

Failed to attach disk 'C:\Users\jorda\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The system cannot find the file specified.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND

[process exited with code 4294967295 (0xffffffff)]
You can now close this terminal with Ctrl+D, or press Enter to restart.

@dobigbadwolf
Copy link

i had to adapt the unix command so it was 'wsl unregister kali-linux' the ran the 2nd linux command and it worked perfectly thanx!

@realyukii
Copy link

realyukii commented Sep 22, 2023

I've also had a similar problem, and trying @daniel-rodriguez-azumo's solution didn't work for me. In my case, wsl error after updating the user directory

what should I do? how to update the OldPath to CurrentPath on users directory?

Failed to attach disk 'C:\Users\OldPath\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The system cannot find the path specified.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_PATH_NOT_FOUND
// The old path
C:\Users\OldPath\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx
// The right path:
C:\Users\CurrentPath\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx

@realyukii
Copy link

Ah NVM, #9349 (comment) solved my problem

I hope in the future this process will be done automatically when updating the user directory.

@gexadax
Copy link

gexadax commented Sep 27, 2023

Thanks this is working 👍
wsl --unregister ubuntu
wsl -- install

@TuanDung0902
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

Yeah, it worked!

@TiloGit
Copy link

TiloGit commented Nov 2, 2023

had this today. Got lucky just reboot of Windows fixed it. (Microsoft Windows NT 10.0.22621.0)

@xanthisafk
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

This is the one. Thank you!

@CihatDinc
Copy link

>wsl --unregister ubuntu ardından >wsl --install en azından ubuntu için sorun düzeltildi

it worked, thanks 👍

@gayashvihangana
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

This worked for me. Thank you!

@mcpower
Copy link

mcpower commented Dec 6, 2023

WARNING: wsl --unregister ubuntu MAY REMOVE USER DATA

If you unintentionally run it:

  • Try finding your old files in AppData\Local\Packages. My files were in CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc, which is thankfully different from the newly installed CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc.
  • Recover your files by either mounting them in a new WSL distro with wsl --mount --vhd <pathToVHD>, or following WSL2 Register Command #4762 (comment).

@Leonezz
Copy link

Leonezz commented Dec 29, 2023

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

One should NOTE this operation removes the distro entirely

@dmtzs
Copy link

dmtzs commented Dec 30, 2023

Executing the command: wsl --unregister adn then wsl --install doenst fix the problem.
What really does is to install another ubuntu which is the latest version too with LTS, and is not the same as the one in the microsoft store.

But if for a reason you prefer to install it like this way then you should be sure to delete the broken version if you dont want to have trash in your pc

@adnanh5
Copy link

adnanh5 commented Jan 8, 2024

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

Thank you so much for this solution I was struggling for hours

@ueeou
Copy link

ueeou commented Jan 13, 2024

Thank you so much

@Smiley2507
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

Thank you. This solved my problem.

@spidy2356
Copy link

Hello, I'm new to this computer stuff but I had this issue too. Couldn't find anything except a short 2min YT video. Basically you need to re-install and run your Unix installation through Powershell first.

Steps: run Windows Powershell as Admin wsl --uninstall kali-linux wsl --install --distribution kali-linux

This will run kali-linux in the Powershell terminal. You can just close the Powershell terminal then run the app from the store. Not sure how or why it works but it worked for me. Hope this helps you and whoever encounters this!

just use unregister instead of uninstall in the given cmd wsl --uninstall kali-linux

and my issue solved

@safwanshamsir99
Copy link

I found another solution on David Bombal YouTube

@ASV1995
Copy link

ASV1995 commented Apr 1, 2024

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

Still works thank you :)

@dobigbadwolf
Copy link

dobigbadwolf commented Apr 2, 2024 via email

@fikfr
Copy link

fikfr commented Apr 15, 2024

help, i cant unregister it, cos powershell says there is no wsl installed, even tho it says there is...
image
when starting kali, it still says the same error...

@Emereh-boop
Copy link

thank a lot this fixed the issue 👍

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

@Fabienjulio
Copy link

Works (as of 11/09/2023): wsl --unregister ubuntu wsl -- install

Thanks a lot!
I had the same problem but with Docker Desktop
provisioning docker WSL distros: ensuring main distro is deployed: checking if main distro is up to date: checking main distro bootstrap version: getting main distro bootstrap version: exit code: 4294967295: running WSL command wsl.exe C:\Windows\System32\wsl.exe -d docker-desktop -u root -e wsl-bootstrap version: Échec de l’attachement du disque « <HOME>\AppData\Local\Docker\wsl\distro\ext4.vhdx » à WSL2. Error code: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_FILE_NOT_FOUND : exit status 0xffffffff

Solved it with just wsl --unregister docker-desktop and then restarting Docker

@jjavierdguezas
Copy link

Thanks a lot! I had the same problem but with Docker Desktop provisioning docker WSL distros: ensuring main distro is deployed: checking if main distro is up to date: checking main distro bootstrap version: getting main distro bootstrap version: exit code: 4294967295: running WSL command wsl.exe C:\Windows\System32\wsl.exe -d docker-desktop -u root -e wsl-bootstrap version: Échec de l’attachement du disque « <HOME>\AppData\Local\Docker\wsl\distro\ext4.vhdx » à WSL2. Error code: Wsl/Service/CreateInstance/MountVhd/HCS/ERROR_FILE_NOT_FOUND : exit status 0xffffffff

Solved it with just wsl --unregister docker-desktop and then restarting Docker

same problem here, wsl --unregister docker-desktop and restart Docker Desktop just work! thanks @Fabienjulio ... no data was lost btw

@sayol
Copy link

sayol commented Aug 21, 2024

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

Confirm that this works perfectly!

@EricHerlitz
Copy link

This is usually an issue with your rights, ensure you have sufficient rights to the vhdx file. Which you probably don't have since this file most likely was moved from another computer.
E.g
image

@chozillla
Copy link

chozillla commented Sep 18, 2024

it is 2024 and this works for me!

wsl --unregister ubuntu wsl -- install

@omereliusuk
Copy link

thank you

@RobertoAlessandri
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

What if I don't want to --unregister? I am afraid I'd loose al my (non backed-up) files

@luwukien
Copy link

>wsl --unregister ubuntu followed by >wsl --install fixes the problem for ubuntu atleast

thank you. It's working.

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

No branches or pull requests