Mount a Linux image on Windows and access to it from File Explorer with WSL2

sgtino

Stefano Giraldi

Posted on October 30, 2021

Mount a Linux image on Windows and access to it from File Explorer with WSL2

Requisites

A Windows system with WSL2 and an installed distro.

1. Downlaod linux distro image

wget __linux_image_url
Enter fullscreen mode Exit fullscreen mode

2. Run wsl console

$ wsl
Enter fullscreen mode Exit fullscreen mode

3. Check disk image sectors

$ partx --show __linux_image_filepath__
NR  START     END SECTORS SIZE NAME UUID
 1   8192  532479  524288 256M      9730496b-01
 2 532480 3661823 3129344 1.5G      9730496b-02
Enter fullscreen mode Exit fullscreen mode

3. Calculate offset

$ bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
> 532480 * 512
> 272629760
> quit
Enter fullscreen mode Exit fullscreen mode

4. Mount Image

Create mounting point

$ sudo mkdir /mnt/other
Enter fullscreen mode Exit fullscreen mode

Mount image

$ sudo mount -v -o offset=272629760 -t ext4 /_path_to_file_image/__filename__.img /mnt/other
mount: /dev/loop0 mounted on /mnt/other.
Enter fullscreen mode Exit fullscreen mode

Check mounted image

$ ls /mnt/other
Enter fullscreen mode Exit fullscreen mode

5. Access to Filesystem through File Explorer

  1. Open File Explorer
  2. Type \\wsl$ in the address bar
  3. Installed distros will be shown up. Click on it and navigate in the file system into the mounted path.

References

Photo Credit Dorolein

💖 💪 🙅 🚩
sgtino
Stefano Giraldi

Posted on October 30, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related