PiShrink using Windows 10 Windows Subsystem for Linux 2 (WSL 2) – Part 1

PiShrink in WSL2 works if you create the proper symlink

This finally works. No more Virtual machines just to run PiShrink.

That said – there is one workaround (very simple) you must do.
I’ll walk through the steps of confirming you have or installing WSL2, Debian, PiShrink and “patch” in other posts but assuming you’ve already followed the WSL2 install, and have installed Ubuntu or Debian, and mounted your external drive in Linux (via WSL2), and downloaded PiShrink, you might be getting this error:

ext2fs_check_if_mount: Can’t check if filesystem is mounted due to missing mtab file while determining whether /dev/loop0 is mounted

So before I go through the process for those that are starting from scratch, the fix for that error is quite easy. I’ll explain the cause of it later, but first – the fix.

You simply need to create a symlink between the /proc/self/mounts file and the (non-existent in WSL/WSL2) /etc/mtab by entering the following line:
sudo ln -s /proc/self/mounts /etc/mtab

Et voila, now run PiShrink and it should work.

For those of you that need the step by step process starting from upgrading your Windows 10 to use WSL2, follow this link to my instruction page: How to use WSL2 for PiShrink

 

————- More info on /etc/mtab and /proc/self/mounts in WSL/WSL2 and newer Linux distros if you’re interested below ——————–

Debian (or Ubuntu and likely other images) fail in WSL2 with pishrink because pishrink looks for the /etc/mtab file to determine mounts.

The mtab file (/etc/mtab) is a legacy from Unix to store mounted locations. It was included in many (most) Linux distros to ensure backward compatibility and Posix/Unix compatibility.

More recently, most Linux distros create a symlink between the replacement file (/proc/self/mounts) and the legacy /etc/mtab file.

Windows Subsystem for Linux (1 and 2) do not include that symlink, which is why you must create yourself.

Leave a Reply

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