Installation fails on WSL

Hi all - after much trial and error, I finally got it all working on WSL2 Ubuntu 18.04 LTS.

The problem

The problem is with QEMU and binfmt as most post and replies allude to, and the errors on my install was the same as for @dima.dubnevych. ie:

ERROR: File System and OS - target_image: chroot: failed to run command 'dpkg': Exec format error

Investigations showed that qemu-aarch64 was missing under /proc/sys/fs/binfmt_misc/, even though qemu-user-static and binfmt-support was properly installed and enabled.
Trying to resolve this via sudo update-binfmts --import qemu-aarch64 that is suggested everywhere did not work, just as it didn’t for Dima:

update-binfmts: warning: unable to open /usr/share/binfmts/qemu-aarch64: No such file or directory
update-binfmts: warning: couldn't find information about 'qemu-aarch64' to import
update-binfmts: exiting due to previous errors

So, for some reason /usr/share/binfmts/ is missing all qemu- templates, even though they as far as I can tell, are supposed to be installed with qemu-user-static.

Solutions

Steps from a fresh install (but cherry-picking should be fine too):

  1. Setup the WSL Environment according to the sdk-manager documentation.
  2. Install qemu sudo apt install qemu-user-static.
  3. Now we need to fix the missing binfmts. We have two options:
    • Either just directly install the missing /proc/sys/fs/binfmt_misc/qemu-aarch64:
      sudo update-binfmts \
       --package qemu-user \
       --install qemu-aarch64 /usr/bin/qemu-aarch64-static \
       --magic '\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' \
       --mask '\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'
      
      ps. I saw this same approach in a different thread that didn’t work for me or the others - but it turned out that the magic and mask parameters were incorrect, taking the correct ones from the qemu source did the trick. ds.
    • OR install all the missing qemu templates into /usr/share/binfmts/ and import that:
      wget https://github.com/qemu/qemu/raw/master/scripts/qemu-binfmt-conf.sh
      chmod +x qemu-binfmt-conf.sh
      sudo ./qemu-binfmt-conf.sh --qemu-path /usr/bin --qemu-suffix -static --debian
      sudo update-binfmts --import qemu-aarch64
      
  4. Verify /proc/sys/fs/binfmt_misc/qemu-aarch64 exists.
  5. Run sdkmanager and cross your fingers.
9 Likes