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

how-to-repair-a-vhd-mounting-error? the tutorial not work at all! #10169

Closed
1 of 2 tasks
ethever opened this issue Jun 7, 2023 · 10 comments
Closed
1 of 2 tasks

how-to-repair-a-vhd-mounting-error? the tutorial not work at all! #10169

ethever opened this issue Jun 7, 2023 · 10 comments

Comments

@ethever
Copy link

ethever commented Jun 7, 2023

Windows Version

Microsoft Windows [Version 10.0.19044.2965]

WSL Version

WSL version: 1.2.5.0 Kernel version: 5.15.90.1 WSLg version: 1.0.51 MSRDC version: 1.2.3770 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19044.2965

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

Debian

Other Software

non

Repro Steps

visit and try https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-repair-a-vhd-mounting-error.

Expected Behavior

should repaired

Actual Behavior

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl.exe --mount .\ext4.vhdx --vhd --bare
The operation completed successfully.
PS F:\wsl\Debian> wsl.exe sudo e2fsck -f /dev/sdc
Failed to attach disk 'F:\wsl\Debian\ext4.vhdx' to WSL2: 另一个程序正在使用此文件,进程无法访问。
Error code: Wsl/Service/CreateInstance/MountVhd/0x80070020
PS F:\wsl\Debian>

Diagnostic Logs

Why ?

@ethever
Copy link
Author

ethever commented Jun 7, 2023

PS F:\wsl\Debian> wsl.exe sudo e2fsck -f /dev/sdc
An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
See recovery instructions on: https://aka.ms/wsldiskmountrecovery
e2fsck 1.46.2 (28-Feb-2021)
/dev/sdc is in use.
e2fsck: Cannot continue, aborting.

@ethever
Copy link
Author

ethever commented Jun 7, 2023

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl sudo e2fsck -f /dev/sdc
An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
See recovery instructions on: https://aka.ms/wsldiskmountrecovery
e2fsck 1.46.2 (28-Feb-2021)
/dev/sdc is in use.
e2fsck: Cannot continue, aborting.

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl sudo e2fsck -f /dev/sda
An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
See recovery instructions on: https://aka.ms/wsldiskmountrecovery
e2fsck 1.46.2 (28-Feb-2021)
/dev/sda is in use.
e2fsck: Cannot continue, aborting.

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl sudo e2fsck -f /dev/sdb
An error occurred mounting the distribution disk, it was mounted read-only as a fallback.
See recovery instructions on: https://aka.ms/wsldiskmountrecovery
e2fsck 1.46.2 (28-Feb-2021)
/dev/sdb is mounted.
e2fsck: Cannot continue, aborting.

@ethever
Copy link
Author

ethever commented Jun 7, 2023

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl --mount .\ext4.vhdx --vhd --bare
The operation completed successfully.
PS F:\wsl\Debian>
PS F:\wsl\Debian> wsl sudo e2fsck -f /dev/sdb
Failed to attach disk 'F:\wsl\Debian\ext4.vhdx' to WSL2: 另一个程序正在使用此文件,进程无法访问。
Error code: Wsl/Service/CreateInstance/MountVhd/0x80070020
PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl --mount .\ext4.vhdx --vhd --bare
The operation completed successfully.
PS F:\wsl\Debian> wsl sudo e2fsck -f /dev/sdc
Failed to attach disk 'F:\wsl\Debian\ext4.vhdx' to WSL2: 另一个程序正在使用此文件,进程无法访问。
Error code: Wsl/Service/CreateInstance/MountVhd/0x80070020

@ethever
Copy link
Author

ethever commented Jun 7, 2023

(base) root@DESKTOP-D2P8H7D:/mnt/f/wsl/Debian# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 363.3M 1 disk
sdb 8:16 0 3G 0 disk [SWAP]
sdc 8:32 0 256G 0 disk

@EngineerReversed
Copy link

EngineerReversed commented Jun 7, 2023

Facing the same error and I can't access my WSL2 terminal.
Error:

Failed to attach disk 'D:\Ubuntu_20.04_LTS\ext4.vhdx' to WSL2: The requested operation could not be completed due to a file system limitation
Error code: Wsl/Service/CreateInstance/MountVhd/0x80070299"

I had to unregister and install ubuntu distribution again to solve the problem. I lost all of my ssh keys(to access servers), vpn configurations etc.
I don't know if it was because of the pre-release version or recent windows updates which broke it.

@ethever
Copy link
Author

ethever commented Jun 7, 2023

unregister will lost all my data in the distribution. I have some important data in it.

@elsaco
Copy link

elsaco commented Jun 8, 2023

@ethever the error message is obivous Another program is using this file and the process cannot access it. You already mounted Debian vhd and wsl.exe sudo e2fsck -f /dev/sdc is trying to mount it again. Is Debian your default distro?

You could use the system distro or another after mounting Debian's vhd. Here's sample run using the system distro:

PS E:\> wsl --mount e:\fedora\ext4.vhdx --vhd --bare
The operation completed successfully.
PS E:\> wsl --system -u root e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc: 24973/67108864 files (0.3% non-contiguous), 4959752/268435456 blocks

Make sure you specify the root user otherwise you'll be greeted by:

PS E:\> wsl --system e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
e2fsck: Permission denied while trying to open /dev/sdc
You must have r/w access to the filesystem or be root

@ethever
Copy link
Author

ethever commented Jun 8, 2023

@ethever the error message is obivous Another program is using this file and the process cannot access it. You already mounted Debian vhd and wsl.exe sudo e2fsck -f /dev/sdc is trying to mount it again. Is Debian your default distro?

You could use the system distro or another after mounting Debian's vhd. Here's sample run using the system distro:

PS E:\> wsl --mount e:\fedora\ext4.vhdx --vhd --bare
The operation completed successfully.
PS E:\> wsl --system -u root e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdc: 24973/67108864 files (0.3% non-contiguous), 4959752/268435456 blocks

Make sure you specify the root user otherwise you'll be greeted by:

PS E:\> wsl --system e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
e2fsck: Permission denied while trying to open /dev/sdc
You must have r/w access to the filesystem or be root

Debian is my default distribution:

PS F:\wsl\Debian> wsl --list
Windows Subsystem for Linux Distributions:
Debian (Default)
Ubuntu
docker-desktop-data
docker-desktop

wsl --system -u root e2fsck -f /dev/sdc not work for the same error:

PS F:\wsl\Debian> wsl --shutdown
PS F:\wsl\Debian> wsl --list
Windows Subsystem for Linux Distributions:
Debian (Default)
Ubuntu
docker-desktop-data
docker-desktop
PS F:\wsl\Debian>
PS F:\wsl\Debian>
PS F:\wsl\Debian> wsl --mount .\ext4.vhdx --vhd --bare
The operation completed successfully.
PS F:\wsl\Debian> wsl --system -u root e2fsck -f /dev/sdc
Failed to attach disk 'F:\wsl\Debian\ext4.vhdx' to WSL2: 另一个程序正在使用此文件,进程无法访问。
Error code: Wsl/Service/CreateInstance/MountVhd/0x80070020
PS F:\wsl\Debian> 

But i try it using Ubuntu instread of system distri and it works:

PS F:\wsl\Debian> wsl -d Ubuntu -u root e2fsck -f /dev/sdc
e2fsck 1.46.5 (30-Dec-2021)
/dev/sdc: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Inode 501800 extent tree (at level 1) could be shorter.  Optimize<y>? yes

Inode 1056183 extent tree (at level 1) could be shorter.  Optimize<y>? yes
Inode 1955138 extent tree (at level 1) could be shorter.  Optimize<y>? yes

Inode 3313721 extent tree (at level 1) could be shorter.  Optimize<y>? yes
Inode 3349709 extent tree (at level 1) could be shorter.  Optimize<y>? yes
Pass 1E: Optimizing extent trees
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/sdc: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sdc: 3516340/16777216 files (0.2% non-contiguous), 67104763/67108864 blocks

@ethever
Copy link
Author

ethever commented Jun 8, 2023

wsl --system -u root e2fsck -f /dev/sdc

Extremely appriciate this.

@rikrdo89
Copy link

rikrdo89 commented Aug 8, 2024

This worked for me! thanks for posting this. I just would add that after e2fsck is completed successfully, unmount the vhd using wsl.exe --unmount and you are ready to have your wsl2 working again.

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

4 participants