Updating to WSL 2 (Ubuntu 20.04) and mounting an image on a Raspberry Pi

公開日: 2020年06月06日最終更新日: 2021年10月17日

I want to see the contents of the image of Raspberry, and I tried to mount it with WSL, but it didn't work.
It is good timing because I am using Windows Sbusystem for Linux recently and WSL2 became an official version.

Installing WSL 2

The Windows Subsystem for Linux BUILD 2020 Summary has a , It says that if you are installing WSL for the first time, you just need to wsl --install to get WSL 2, but that didn't apply in my case, so I proceeded with the following page. https://docs.microsoft.com/en-us/windows/wsl/install-win10

You must have Windows 10 version 2004 or higher. When I checked, version 2004 is not yet delivered to my PC, so I went to get it myself. You can download it from the Get Windows Update Assistant link.

Once Windows 10 is updated, run the commands as described.

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

wsl --set-default-version 2

When I ran wsl --set-default-version 2, it said that the WSL 2 Linux kernel needs to be updated, so I downloaded and installed it from Updating the WSL 2 Linux kernel.
I ran wsl --set-default-version 2 again and it passed.

As I already had Ubuntu installed, I ran the following command to change it to WSL 2.

wsl --set-version Ubuntu-20.04 2

It took a few minutes, but it was done.

Mount the image of Raspberry

I tried to mount it as a loopback device, but it didn't work.

mount -t ext4 -o loop raspbian.img /mnt/image

mount: /mnt/image: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.

If you specify offset directly, you can mount it.

partx --show raspbian.img
NR START      END  SECTORS  SIZE NAME UUID
 1  8192    96042    87851 42.9M      a50165a4-01
 2 98304 25264127 25165824   12G      a50165a4-02

START 98304 multiplied by 512 bytes of sector size will be the value of the offset. In this case, it is 98304 * 512 = 50331648.
It works well when you mount it with this value.

sudo mount -v -t ext4 -o offset=50331648 raspbian.img /mnt/image

Considering the time alone, it was faster to burn it to an SD card and mount it on Linux.

I hope this information will be of some help to you. It would be my pleasure if you could click on the link below and then shop for something.