Skip to content

Commit da28658

Browse files
Added updates to wsl mount docs (#1123)
* Added updates to wsl mount docs
1 parent 0d2502b commit da28658

3 files changed

Lines changed: 49 additions & 19 deletions

File tree

WSL/media/wslmountsimple.png

113 KB
Loading

WSL/media/wslmountvhd.png

147 KB
Loading

WSL/wsl2-mount-disk.md

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ This tutorial will cover the steps to identify the disk and partition to attach
1717
> You will need to be on Windows 10 Build 20211 or higher to access this feature. You can join the [Windows Insiders Program](https://insider.windows.com/) to get the latest preview builds.
1818
> Administrator access is required to attach a disk to WSL 2.
1919
20-
## Identify the disk
20+
## Mounting an unpartitioned disk
21+
22+
In this simplest case, if you have a disk that doesn't have any partitions, you can mount it directly using the `wsl --mount` command. First you need to identify the disk.
23+
24+
### Identify the disk
2125

2226
To list the available disks in Windows, run:
2327

@@ -27,7 +31,31 @@ wmic diskdrive list brief
2731

2832
The disks paths are available under the 'DeviceID' columns. Usually under the `\\.\PHYSICALDRIVE*` format.
2933

30-
## List and select the partitions to mount in WSL 2
34+
### Mount the disk
35+
36+
Then in Powershell you can mount the disk using the Disk path discovered above.
37+
38+
```powershell
39+
wsl --mount <DiskPath>
40+
```
41+
42+
![Mounting a drive in WSL](./media/wslmountsimple.png)
43+
44+
## Mounting a disk with unknown formats
45+
46+
If you have a disk that you aren't sure what file format it is in, or what partitions it has, you can follow the steps below to mount it.
47+
48+
### Identify the disk
49+
50+
To list the available disks in Windows, run:
51+
52+
```powershell
53+
wmic diskdrive list brief
54+
```
55+
56+
The disks paths are available under the 'DeviceID' columns. Usually under the `\\.\PHYSICALDRIVE*` format
57+
58+
### List and select the partitions to mount in WSL 2
3159

3260
Once the disk is identified, run:
3361

@@ -39,7 +67,7 @@ This will make the disk available in WSL 2.
3967

4068
Once attached, the partition can be listed by running the following command inside WSL 2:
4169

42-
```powershell
70+
```bash
4371
lsblk
4472
```
4573

@@ -49,7 +77,7 @@ Inside Linux, a block device is identified as `/dev/<Device><Partition>`. For e
4977

5078
Example output:
5179

52-
```powershell
80+
```bash
5381
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
5482
sdb 8:16 0 1G 0 disk
5583
├─sdb2 8:18 0 50M 0 part
@@ -59,7 +87,7 @@ sdc 8:32 0 256G 0 disk /
5987
sda 8:0 0 256G 0 disk
6088
```
6189

62-
## Identifying the filesystem type
90+
### Identifying the filesystem type
6391

6492
If you don't know the type of filesystem of a disk or partition, you can use this command:
6593

@@ -69,7 +97,7 @@ blkid <BlockDevice>
6997

7098
This will output the detected filesystem type (under the `TYPE="<Filesystem>"` format).
7199

72-
## Mount the selected partitions
100+
### Mount the selected partitions
73101

74102
Once you have identified the partitions you want to mount, run this command on each partition:
75103

@@ -82,7 +110,7 @@ wsl --mount <DiskPath> --partition <PartitionNumber> --type <Filesystem>
82110
>
83111
> If omitted, the default filesystem type is "ext4".
84112
85-
## Access the disk content
113+
### Access the disk content
86114

87115
Once mounted, the disk can be accessed under the path pointed to by the config value: `automount.root`. The default value is `/mnt/wsl`.
88116

@@ -96,6 +124,20 @@ If you want to unmount and detach the disk from WSL 2, run:
96124
wsl --unmount <DiskPath>
97125
```
98126

127+
## Mount a VHD in WSL
128+
129+
You can also mount virtual hard disk files (VHD) into WSL using `wsl --mount`. To do this, you first need to mount the VHD into Windows using the [`Mount-VHD`](/powershell/module/hyper-v/mount-vhd) command in Windows. Be sure to run this command with administrator privileges. Below is an example where we use this command, and also output the disk path. Be sure to replace `<pathToVHD>` with your actual VHD path.
130+
131+
```powershell
132+
Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path <pathToVHD> -PassThru | Get-Disk).Number)"
133+
```
134+
135+
You can use the output above to obtain the disk path for this VHD and mount that into WSL following the instructions in the previous section.
136+
137+
You can also use this technique to mount and interact with the virtual hard disks of other WSL distros, as each WSL 2 distro is stored via a virtual hard disk file called: `ext4.vhdx`. By default the VHDs for WSL 2 distros are stored in this path: `C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName]`, please exercise caution accessing these system files, this is a power user workflow. Make sure to run `wsl --shutdown` before interacting with this disk to ensure the disk is not in use.
138+
139+
![Mounting WSL VHD](./media/wslmountvhd.png)
140+
99141
## Command line reference
100142

101143
### Mounting a specific filesystem
@@ -165,18 +207,6 @@ If `Diskpath` is omitted, all attached disks are unmounted and detached.
165207
> [!NOTE]
166208
> If one disk fails to unmount, WSL 2 can be forced to exit by running `wsl --shutdown`, which will detach the disk.
167209
168-
## Mount a VHD in WSL
169-
170-
You can also mount virtual hard disk files (VHD) into WSL using `wsl --mount`. To do this, you first need to mount the VHD into Windows using the [`Mount-VHD`](/powershell/module/hyper-v/mount-vhd) command in Windows. Be sure to run this command in a window with administrator privileges. Below is an example where we use this command, and also output the disk path. Be sure to replace `<pathToVHD>` with your actual VHD path.
171-
172-
```powershell
173-
Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path <pathToVHD> -PassThru | Get-Disk).Number)"
174-
```
175-
176-
You can use the output above to obtain the disk path for this VHD and mount that into WSL following the instructions in the previous section.
177-
178-
You can also use this technique to mount and interact with the virtual hard disks of other WSL distros, as each WSL 2 distro is stored via a virtual hard disk file called: `ext4.vhdx`. By default the VHDs for WSL 2 distros are stored in this path: `C:\Users\[user]\AppData\Local\Packages\[distro]\LocalState\[distroPackageName]`, please exercise caution accessing these system files, this is a power user workflow.
179-
180210
## Limitations
181211

182212
- 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.

0 commit comments

Comments
 (0)