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] mount "The disk is in use or locked by another process" - workaround #5997

Closed
nikitalita opened this issue Sep 28, 2020 · 22 comments
Closed
Labels

Comments

@nikitalita
Copy link

Environment

Windows build number: Microsoft Windows [Version 10.0.20221.1000]
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL 2

Issue

I am on a dual boot set-up with EFI enabled. I have two disks, one with my Ubuntu 20.04 install, another with my Windows install. I have my grub bootloader on the Ubuntu disk, set up to either boot me into Ubuntu or Windows.

On Windows, attempting to mount my boot disk onto my WSL 2 instance fails:

wsl --mount \\.\PHYSICALDRIVE2 --bare
The disk is in use or locked by another process

Reading the article about mounting disks into WSL 2 reveals why:

At this time, only entire disks can be attached to WSL 2, meaning that it's not possible to attach only a partition. Concretely, this means that it's not possible to use wsl --mount to read a partition on the boot device, because that device can't be detached from Windows.

Because I was chainloading the Windows boot loader with grub, Windows considered my Ubuntu disk a boot disk, and locked the drive.

Workaround

In your motherboard settings, change the system to boot from the windows bootloader instead of the linux bootloader. Then, it won't chainload from the linux drive, and Windows won't consider it a boot disk.

@therealkenc therealkenc changed the title [WSL2] mount "The disk is in use or locked by another process" - workaround [WSL2] allow --mount of a drive partition Sep 28, 2020
@noriakia
Copy link

noriakia commented Oct 1, 2020

I get the same message in my environment.

PS C:\Users\xxxxxx> wsl --mount \\.\PHYSICALDRIVE0 --partition 2
プロセスはファイルにアクセスできません。別のプロセスが使用中です。

It is displayed in a Japanese message, but has the same meaning as below.
The disk is in use or locked by another process

Windows build number:
Microsoft Windows [Version 10.0.20226.1000]

@bubnikv
Copy link

bubnikv commented Oct 2, 2020

I am sorry, but that the current limitation of not being able to mount a Linux partition from the Windows disk disables mounting of Linux partitions for the majority of us.

@nikitalita
Copy link
Author

You can, but you can't mount the whole drive with the --bare option.

@bubnikv
Copy link

bubnikv commented Oct 2, 2020

At this time, only entire disks can be attached to WSL 2, meaning that it's not possible to attach only a partition. Concretely, this means that it's not possible to use wsl --mount to read a partition on the boot device, because that device can't be detached from Windows.

You can, but you can't mount the whole drive with the --bare option.

I don't understand the statement above then. The way I understand the limitation is that I cannot mount a linux partition to WSL2 if the linux partition resides on the same disk as my Windows partition with efi.

@nikitalita
Copy link
Author

nikitalita commented Oct 2, 2020

That's not what I had originally labeled the issue as, someone changed it. it's about mounting whole disks.

You can mount a partition by doing this: wsl --mount <DiskPath> --partition <PartitionNumber> --type <Filesystem>

I think the article may have been written piecemeal and that warning wasn't updated? I only used it to explain why it refuses to mount whole disks that it isn't using.

@therealkenc therealkenc changed the title [WSL2] allow --mount of a drive partition [WSL2] mount "The disk is in use or locked by another process" - workaround Oct 2, 2020
@eromoe
Copy link

eromoe commented Oct 3, 2020

I have same error as @noriakia when launch wsl2

C:\Users\ufo>bash
另一个程序正在使用此文件,进程无法访问。

Is the recently update break wsl2 down ?


What change I have made to wsl2:

  1. move the system image to another dist by https://github.com/DDoSolitary/LxRunOffline

  2. yesterday , I the depart command to shrink the vhd file size :

wsl --shutdown
diskpart
# open window Diskpart
select vdisk file="C:\WSL-Distros\…\ext4.vhdx"
attach vdisk readonly
compact vdisk
detach vdisk
exit

Is that I only can't depart or I can't do both ?

@noriakia
Copy link

noriakia commented Oct 9, 2020

I get the same message in my environment.

PS C:\Users\xxxxxx> wsl --mount \\.\PHYSICALDRIVE0 --partition 2
プロセスはファイルにアクセスできません。別のプロセスが使用中です。

It is displayed in a Japanese message, but has the same meaning as below.
The disk is in use or locked by another process

Windows build number:
Microsoft Windows [Version 10.0.20226.1000]

It hasn't been fixed even after 20231.

@smohring
Copy link

Windows/Ubuntu 20.10 in the same disk, getting the same error during mount:

Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird.

@Cr1ft
Copy link

Cr1ft commented Oct 12, 2020

My external hard drive has three partitions: one ext4 and two NTFS.

I tried to mount the ext4 partition on the external hard disk, but it shows an error that another program is using this file and the process cannot access it.

`C:\Users\xxxxx>wmic diskdrive list brief
Caption DeviceID Model Partitions Size
Seagate BUP Slim SCSI Disk Device \.\PHYSICALDRIVE1 Seagate BUP Slim SCSI Disk Device 4 1000202273280
SAMSUNG MZVLB1T0HBLR-000L2 \.\PHYSICALDRIVE0 SAMSUNG MZVLB1T0HBLR-000L2 6 1024203640320

C:\Users\xxxx>wsl --mount \.\PHYSICALDRIVE1 --partition 2
另一个程序正在使用此文件,进程无法访问。`

@bubnikv
Copy link

bubnikv commented Oct 12, 2020 via email

@OneBlue
Copy link
Collaborator

OneBlue commented Oct 29, 2020

Let me try to bring some clarity on this.

WSL --mount always detaches the disk from Windows, and then attaches it as a block device to WSL2.
That's the reason why wsl --mount fails if the disk is in use, because we can't detach it from Windows.

What actually happens when wsl --mount X --partition Y is:

  • Disk X is unmounted & detached from Windows
  • Disk X is attached to WSL2
  • Partition Y is mounted in WSL2

So even if --partition is passed to wsl --mount, the whole disk needs to be available so it can be attached to WSL2.

In @nikitalita's scenario, I imagine that the EFI partition is on PHYSICALDRIVE2, and it's of course in use by Windows, so it's not possible to detach it if this disk was used as the boot disk. The suggested workaround of using a different boot disk makes perfect sense since it means that Windows won't use the EFI partition in PHYSICALDRIVE2 and so the disk is not in use when wsl --mount runs.

I'll close this issue now. Let me know if you have any other questions !

@OneBlue OneBlue closed this as completed Oct 29, 2020
@Amondale
Copy link

Amondale commented Oct 9, 2021

@OneBlue think you are on the right track. However, how to stop Windows from continuously attempting to mount an NTFS or FAT32 partition? Hopefully I won't have to resort to reg hacks with PHYSICALDISK settings, as I recently had to do with SDXC cards with ext4 partitions that keep coming up "format me so windows can use me" or some such nonsense.

@onlycs
Copy link

onlycs commented Jan 8, 2022

Having this same problem, except my windows boot is on another drive.
i can also use Get-Process * | Select-Object Path | findstr D:\ and confirm that there are no processes running on D:\ (aka \.\physicaldrive0 partition 1)

how would you unmount this drive then?

@jivanf
Copy link

jivanf commented Mar 10, 2022

Having this same problem, except my windows boot is on another drive. i can also use Get-Process * | Select-Object Path | findstr D:\ and confirm that there are no processes running on D:\ (aka .\physicaldrive0 partition 1)

how would you unmount this drive then?

What I did to fix this was go to Disk Management, right-click the disk and set it to offline to unmount it. Then I was able to mount it on WSL.

@YoungElPaso
Copy link

@jivanf Can confirm that also worked for me - had to use diskpart in powershell however, but same thing - set offline, then mount.

@rraayyii
Copy link

The disks are now automatically mounted in the /mnt folder under wsl.
image

@xTye
Copy link

xTye commented Mar 2, 2023

@jivanf Can confirm that also worked for me - had to use diskpart in powershell however, but same thing - set offline, then mount.

https://answers.microsoft.com/en-us/windows/forum/all/online-offline-a-disk-in-disk-management-w10-home/c4c472a8-7fa1-41a5-a9ad-68434b64dc35

Here's the link on how to do it through powershell

@MordaNakmor
Copy link

EHM.. had the same problem and the solution is "quite simple".. before you even try to use power shell as admin to mount the disk, you "simply" have to put it offline in disk manager.. those Carrotsoft idiots either forgot to notify users about it or made it out of sheer evil joy for those who would try to do it by the book.. one stupid detail managed to put countless people to lay off of it..

@obfuscated-loop
Copy link

EHM.. had the same problem and the solution is "quite simple".. before you even try to use power shell as admin to mount the disk, you "simply" have to put it offline in disk manager.. those Carrotsoft idiots either forgot to notify users about it or made it out of sheer evil joy for those who would try to do it by the book.. one stupid detail managed to put countless people to lay off of it..

Tried your solution, unfortunately even this didn't work and I got this MessageBox: Disk attributes may not be changed on the current system disk or BIOS disk 0.

It is not the current system disk, neither is it using slot 0! This is ridiculous

@moezakura
Copy link

EHM.. had the same problem and the solution is "quite simple".. before you even try to use power shell as admin to mount the disk, you "simply" have to put it offline in disk manager.. those Carrotsoft idiots either forgot to notify users about it or made it out of sheer evil joy for those who would try to do it by the book.. one stupid detail managed to put countless people to lay off of it..

Tried your solution, unfortunately even this didn't work and I got this MessageBox: Disk attributes may not be changed on the current system disk or BIOS disk 0.

It is not the current system disk, neither is it using slot 0! This is ridiculous

Isn't the boot loader in the disk you are trying to mount?
I moved my boot loader to another disk and that solved the problem.

@SpiderUnderUrBed
Copy link

I also have this issue, is windows working on a solution? with me its because my efi partition is on the disk im trying to mount, atleast i want a solution to that, or if its some random process using it, i would like to know how to debug it

@901238746
Copy link

901238746 commented Jul 30, 2024

Due to how it unmounts the whole disk and not the partition while its mounting it to WSL it fails since critical windows system files are using the C drive.

Also trying to make it offline fails with "Disk attributes may not be changed on the boot disk."

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

No branches or pull requests