Mounting drives


Under WSL, Windows drives are mounted by default and provided under the paths /mnt/c/ etc. However, there is a huge problem: The driver responsible for converting the Windows file system to the Linux file system is very slow.

If you actually work with WSL, e.g., using a Docker container for developing a website with Apache2 / PHP, you will notice this quickly. There is only one solution: Your data must be moved from the Windows to the WSL file system.

There are two options for this:

  1. You use the VHDX file of the WSL distribution

    If you look in the Windows File Explorer, you should see a small penguin at the bottom and next to it your Linux distribution's file system. You can then move or copy your data, such as the website files in our example, to your Linux home directory using Windows Explorer.

    Changes to the Linux file system are not shown immediately. Press F5 to update the the view and check the copy status!!!

    Disadvantage of this method: If you use a dual-boot system with Windows and Linux, you cannot use the files that you have “buried” in a VHDX under Linux, but only under WSL!

  2. You use a separate data drive with the ext4 file system and mount it into WSL

    This has the advantage that you can also use the data, for example in a dual-boot system, under Linux.

    First, you'll need to find out the drive's identifier. You can use this Powershell command to help with that:

    GET-CimInstance -query "SELECT * from Win32_DiskDrive"

    Once you have the name, you need to mount the drive in WSL first:

    wsl --mount \\.\PHYSICALDRIVE2 --bare

    In WSL, you now look for the UUID of the drive using the commands

    lsblk

    and

    sudo blkid

    Now create the mount script:

    sudo bash -c "cat > /mount.sh" <<'EOF'
    #!/usr/bin/env bash
    
    /mnt/c/Users/karlheinz/AppData/Local/Microsoft/WindowsApps/wsl.exe -d Ubuntu-24.04 --mount \\\\.\\PHYSICALDRIVE2 --bare
    echo "Physical drive ECHO mounted in WSL"
    
    timeout=30
    elapsed=0
    interval=2
    
    while [ ! -e /dev/disk/by-uuid/<UUID> ]; do
       if [ $elapsed -ge $timeout ]; then
           echo "Timed out waiting for /dev/disk/by-uuid/<UUID> to become ready."
           exit 1
       fi
    
       echo "Waiting for /dev/disk/by-uuid/<UUID> to be ready..."
       sleep $interval
       elapsed=$((elapsed + interval))
    done
    echo "Device is ready"
    
    mount -t ext4 -o defaults /dev/disk/by-uuid/<UUID> /home/karlheinz/linux
    echo "Device mounted to /home/karlheinz/linux"
    EOF

    As a final step you need to setup the internal WSL configuration:

    sudo bash -c "cat > /etc/wsl.conf" <<'EOF'
    [boot]
    systemd=true
    
    [boot]
    command="bash /mount.sh"
    command="service docker start"
    EOF

Yes, you're calling WSL from within WSL to mount physical drives when starting WSL. It's just “back-to-front, inside-out” as we say here.

It's somehow crazy and brilliant at the same time!

Source