PiShrink: PiShrink Fails running in WSL Ubuntu 18.04

I have installed PiShrink on WSL Ubuntu 18.04. I tried to run it with ‘sudo pishrink.sh RPi-backup-Hipot-18-07-19-shrunk.img’ . When I run it I receive the following error.

Kernel not configured for semaphores (System V IPC). Not using udev synchronisation code. losetup: cannot find an unused loop device losetup: : failed to use device: No such device tune2fs: No such file or directory while trying to open Couldn't find valid filesystem superblock. losetup: : failed to use device: No such device mount: /tmp/tmp.vgF8KzVyQs: unknown filesystem type. losetup: : failed to use device: No such device md5sum: /tmp/tmp.vgF8KzVyQs/etc/rc.local: No such file or directory /usr/local/bin/pishrink.sh: line 78: [: !=: unary operator expected umount: /tmp/tmp.vgF8KzVyQs: not mounted. losetup: : failed to use device: No such device ext2fs_check_if_mount: Can't check if filesystem is mounted due to missing mtab file while determining whether is mounted. e2fsck: No such file or directory while trying to open Possibly non-existent device? losetup: : failed to use device: No such device resize2fs 1.44.1 (24-Mar-2018) ext2fs_check_mount_point: Can't check if filesystem is mounted due to missing mtab file while determining whether is mounted. ERROR: Image already shrunk to smallest size losetup: : failed to use device: No such device losetup: : failed to use device: No such device

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (2 by maintainers)

Most upvoted comments

Thanks for sticking with me!

I still see the old kernel (transcript below)

To install the new kernel I simply double clicked the .msi from Windows Explorer, the same as I would for other software. Is that correct? Do I need to do it from a particular directory? Or some different way?

PS C:\WINDOWS\system32> wsl --set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
PS C:\WINDOWS\system32> wsl --set-version Ubuntu-20.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
Please enable the Virtual Machine Platform Windows feature and ensure virtualization is enabled in the BIOS.
For information please visit https://aka.ms/wsl2-install
PS C:\WINDOWS\system32> wsl --shutdown
PS C:\WINDOWS\system32> wsl
andrew@SPROG2-PC:/mnt/c/WINDOWS/system32$ uname -r
4.4.0-19041-Microsoft
andrew@SPROG2-PC:/mnt/c/WINDOWS/system32$

So Windows is updated to 20H219042.746 but I still don’t know how to update the kernel.

Okay, this we should be able to solve.

  1. Go to the link above, and download and install either of the current WLS2 kernels there.
  2. You need to convert your current WSL to use that new kernel. I’m probably over-specifying the steps here, but
  • Open up a Powershell as root
  • wsl --set-default-version 2
  • wsl --set-version Ubuntu-20.04 2
  • wsl --shutdown
  • wsl
  • Verify the new kernel with uname -a

I just completed these steps to update my 20.04 WSL installation to the 5.4.72 kernel and re-ran PiShrink to verify it still works.

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

Before I explain this, the quick solution (assuming you’ve already mounted the drive where your image is stored) is to create a symlink between the /proc/self/mounts file and /etc/mtab

sudo ln -s /proc/self/mounts /etc/mtab

Once this is done, you should not get the “ext2fs_check_if_mount: Can’t check if filesystem is mounted due to missing mtab file while determining whether /dev/loop0 is mounted” error any more.

You can check my page for this, and the step by step of upgrading to WSL2, installing Debian and PiShrink, mounting a USB drive with the image, the symlink, and running PiShrink if you want more info at: https://news.timekills.info/pishrink-using-windows-10-windows-subsystem-for-linux-2-wsl-2/

Short background: 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. Windows Subsystem for Linux (1 and 2) do not include that symlink, which is why you must create yourself.