DEV Community

Cover image for Mount a Linux image on Windows and access to it from File Explorer with WSL2
Stefano Giraldi
Stefano Giraldi

Posted on • Edited on

12 1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay