Guide: How to Mount and Unmount WSL Drives from Windows

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.

  1. Open PowerShell or Command Prompt as Administrator.
  2. 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.

  1. Open WSL terminal (Ubuntu, Debian, etc.) or PowerShell/Command Prompt.
  2. 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.

See also  Comprehensive guide on logging in Laravel PHP, incorporating example codes, outputs, and explanations:

Step 3: Verify Mounted Drives

To verify the currently mounted drives within WSL, you can list the contents of the /mnt directory:

  1. Open WSL terminal.
  2. 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:

  1. Create or Edit /etc/wsl.conf in your WSL terminal:
   sudo nano /etc/wsl.conf
  1. Add the following configuration:
   [automount]
   enabled = false
  1. Save the file and exit.
  2. 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:

  1. Mount the External Drive (F:):
   wsl --mount \\.\PHYSICALDRIVE2 --partition 1 --type ntfs

Example Output:

   Mounting drive \\.\PHYSICALDRIVE2 to /mnt/f
  1. Access the Mounted Drive in WSL:
   cd /mnt/f
  1. 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!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.