You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: WSL/wsl2-mount-disk.md
+49-19Lines changed: 49 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,11 @@ This tutorial will cover the steps to identify the disk and partition to attach
17
17
> 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.
18
18
> Administrator access is required to attach a disk to WSL 2.
19
19
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
21
25
22
26
To list the available disks in Windows, run:
23
27
@@ -27,7 +31,31 @@ wmic diskdrive list brief
27
31
28
32
The disks paths are available under the 'DeviceID' columns. Usually under the `\\.\PHYSICALDRIVE*` format.
29
33
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
+

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
31
59
32
60
Once the disk is identified, run:
33
61
@@ -39,7 +67,7 @@ This will make the disk available in WSL 2.
39
67
40
68
Once attached, the partition can be listed by running the following command inside WSL 2:
41
69
42
-
```powershell
70
+
```bash
43
71
lsblk
44
72
```
45
73
@@ -49,7 +77,7 @@ Inside Linux, a block device is identified as `/dev/<Device><Partition>`. For e
49
77
50
78
Example output:
51
79
52
-
```powershell
80
+
```bash
53
81
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
54
82
sdb 8:16 0 1G 0 disk
55
83
├─sdb2 8:18 0 50M 0 part
@@ -59,7 +87,7 @@ sdc 8:32 0 256G 0 disk /
59
87
sda 8:0 0 256G 0 disk
60
88
```
61
89
62
-
## Identifying the filesystem type
90
+
###Identifying the filesystem type
63
91
64
92
If you don't know the type of filesystem of a disk or partition, you can use this command:
65
93
@@ -69,7 +97,7 @@ blkid <BlockDevice>
69
97
70
98
This will output the detected filesystem type (under the `TYPE="<Filesystem>"` format).
71
99
72
-
## Mount the selected partitions
100
+
###Mount the selected partitions
73
101
74
102
Once you have identified the partitions you want to mount, run this command on each partition:
> If omitted, the default filesystem type is "ext4".
84
112
85
-
## Access the disk content
113
+
###Access the disk content
86
114
87
115
Once mounted, the disk can be accessed under the path pointed to by the config value: `automount.root`. The default value is `/mnt/wsl`.
88
116
@@ -96,6 +124,20 @@ If you want to unmount and detach the disk from WSL 2, run:
96
124
wsl --unmount <DiskPath>
97
125
```
98
126
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.
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
+

140
+
99
141
## Command line reference
100
142
101
143
### Mounting a specific filesystem
@@ -165,18 +207,6 @@ If `Diskpath` is omitted, all attached disks are unmounted and detached.
165
207
> [!NOTE]
166
208
> If one disk fails to unmount, WSL 2 can be forced to exit by running `wsl --shutdown`, which will detach the disk.
167
209
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.
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
-
180
210
## Limitations
181
211
182
212
- 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