This guide will walk you through mounting and unmounting drives in Windows Subsystem for Linux (WSL) from a Windows environment. We’ll cover how to manage both manual and automatic mounting of Windows drives.
Step 1: Mount a Windows Drive in WSL
By default, WSL automatically mounts your Windows drives under the /mnt
directory. However, if you need to manually mount a drive (for example, if you have disabled automatic mounting), you can do so using the wsl
command.
- Open PowerShell or Command Prompt as Administrator.
- Manually mount a Windows drive (e.g.,
D:
) in WSL by running:
wsl --mount <DiskPath> --partition <PartitionNumber> --type <Filesystem>
For example, to mount the D:
drive, the command might look like this:
wsl --mount \\.\PHYSICALDRIVE1 --partition 1 --type ntfs
Example Output:
Mounting drive \\.\PHYSICALDRIVE1 to /mnt/d
Now, if you switch to WSL, you should be able to access the drive under /mnt/d
.
Step 2: Unmount a Windows Drive in WSL
If you need to unmount a Windows drive from within WSL, you can use the umount
or wsl --unmount
commands.
- Open WSL terminal (Ubuntu, Debian, etc.) or PowerShell/Command Prompt.
- Unmount a drive (e.g.,
D:
) by running:
sudo umount /mnt/d
Alternatively, you can unmount the drive using PowerShell or Command Prompt with:
wsl --unmount \\.\PHYSICALDRIVE1
Example Output:
Unmounting drive \\.\PHYSICALDRIVE1 from /mnt/d
This will unmount the D:
drive from WSL. You can verify it’s no longer mounted by listing the contents of /mnt
:
ls /mnt
Example Output:
c
e
If the d
drive is no longer listed, it has been successfully unmounted.
Step 3: Verify Mounted Drives
To verify the currently mounted drives within WSL, you can list the contents of the /mnt
directory:
- Open WSL terminal.
- List mounted drives:
ls /mnt
Example Output:
c d e
This shows that the C:
, D:
, and E:
drives are mounted and accessible within WSL.
Step 4: Disable Automatic Mounting of Drives
If you prefer not to have Windows drives automatically mounted, you can modify the WSL configuration:
- Create or Edit
/etc/wsl.conf
in your WSL terminal:
sudo nano /etc/wsl.conf
- Add the following configuration:
[automount]
enabled = false
- Save the file and exit.
- Restart WSL with:
wsl --shutdown
This will prevent Windows drives from automatically mounting when you start WSL.
Example Scenario: Mount and Unmount External Drive
Let’s say you have an external drive connected to your Windows system as F:
. Here’s how you would mount and unmount it in WSL:
- Mount the External Drive (F:):
wsl --mount \\.\PHYSICALDRIVE2 --partition 1 --type ntfs
Example Output:
Mounting drive \\.\PHYSICALDRIVE2 to /mnt/f
- Access the Mounted Drive in WSL:
cd /mnt/f
- Unmount the External Drive:
wsl --unmount \\.\PHYSICALDRIVE2
Example Output:
Unmounting drive \\.\PHYSICALDRIVE2 from /mnt/f
This guide should help you manage your drives within WSL from the Windows environment effectively. If you encounter any specific issues or need further customization, feel free to reach out!