from Hacker News

Transparently running binaries from any architecture in Linux (2018)

by billwashere on 4/24/22, 12:52 PM with 29 comments

  • by quag on 4/24/22, 6:37 PM

    For those on NixOS add boot.binfmt.emulatedSystems = ["aarch64-linux"]; to /etc/nixos/configuration.nix and it will enable running ARM binaries.

    https://search.nixos.org/options?channel=21.11&show=boot.bin...

  • by fargle on 4/24/22, 3:25 PM

    Toward the end of the article they use chroot to run an entire rootfs as sort of a user-level system emulation.

    The next step is to do the same thing except using containers/namespaces. I was able to run a Yocto rootfs build for ARM completely, including init, and IIRC networking, using LXC and binfmt_misc. A very handy technique for testing and it does run much faster than full-system emulation.

  • by giomasce on 4/24/22, 6:27 PM

    First: you don't necessarily need an alternative chroot, Debian allows installing packages of foreign architectures in the same main tree. It has some hiccups, but it should mostly work.

    Second: of you like playing with foreign architectures, I have a collection of ready to boot Debian images of many architectures, that you can promptly boot with QEMU. Command line included. It is mostly aimed at full system emulation, though (but if you look through the cogs you can also download chroots). https://people.debian.org/~gio/dqib/

  • by FooBarWidget on 4/24/22, 8:37 PM

    How does qemu-user's performance compare to Rosetta 2? The latter is marketed as nearly native performance because it performs binary translation. But I read that qemu-user also performs binary translation.
  • by ranger_danger on 4/24/22, 6:57 PM

    You can also do this with docker containers for other architectures + the binfmt qemu-user trick, which may be easier to work with pre-existing rootfs images and other software.
  • by sgtnoodle on 4/24/22, 6:17 PM

    I've been using this technique to manipulate raspberry pi OS images for use in embedded system prototypes. It's very easy to set up. It's also nice to be able to use the image's embedded toolchain rather than set up a proper cross-compiler. It's slow to compile stuff due to the emulation, but relatively foolproof.

    Of course, the best long term solution is to use something like yocto or buildroot, but that takes considerable time and knowledge to do properly.

  • by mkoubaa on 4/24/22, 5:29 PM

    What exactly does "transparently" mean in this context. I've seen that term used in a dozen different ways within software engineering
  • by lproven on 4/25/22, 11:01 AM

    All that work to recreate what Inferno (Unix 3) did out of the box over 25 years ago.

    FOSS Unix: 42 steps forward, 42 steps back. :-/

  • by snvzz on 4/24/22, 3:08 PM

    I have found this useful in practice when debootstrapping for a different architecture.
  • by hsnewman on 4/24/22, 3:02 PM

    This is exaggeration, I doubt that it can run AS/400 binaries.
  • by anonymousDan on 4/24/22, 7:23 PM

    I presume it is not safe to do this with malware?
  • by skykooler on 4/24/22, 6:18 PM

    Does this work for graphical programs?