Skip to content

binfmt-misc: add service#15521

Open
agorgl wants to merge 1 commit intobatocera-linux:masterfrom
agorgl:binfmt-misc
Open

binfmt-misc: add service#15521
agorgl wants to merge 1 commit intobatocera-linux:masterfrom
agorgl:binfmt-misc

Conversation

@agorgl
Copy link
Contributor

@agorgl agorgl commented Mar 4, 2026

Adds init service that setups binfmt_misc mount and registers binary formats similarly to systemd-binfmt.service.
Can be used alongside box64 and wine to allow non native executables to run transparently.

Augments: #15494

@dmanlfc
Copy link
Collaborator

dmanlfc commented Mar 9, 2026

needs more explanation as to why we need this and the benefits.
in addition the code is still constructed with systemd in mind and is not valid for Batocera.

@agorgl
Copy link
Contributor Author

agorgl commented Mar 10, 2026

The binfmt_misc linux kernel capability allows to run directly non-native executables on a linux system as native.

This, in batocera can be applied to the following two cases:

  1. Windows pe executables that can be run with wine
  2. x86_64 linux elf executables in ARM systems that can be run with box64

Given that batocera has its own wine wrappers and manages its own prefixes the case (1) doesn't have much value, as all x86_64 windows games should be run through the batocera-wine script.

The case (2) though is very interesting and I have actually successfully tested it myself. If we decide to add support for box64 with #15494, then the ARM systems will be able to run x86_64 executables transparently, without prefixing them with the box64 command. This means that the ARM systems will be able to transparently run the x86_64 linux elf wine executables, which in turn run the x86_64 windows pe executables, making x86_64 windows games work in ARM linux systems (32bit x86 games will work too when using a wine version with WOW64 enabled).

With this addition we don't need to complicate the batocera-wine script and it can remain agnostic to the host architecture, allowing it to work transparently with the ARM systems (when box64 is available ofc).

Now for the executable type registration part. The binfmt_misc Linux kernel capability can be manually setup with as per the Linux kernel docs here that involves the following steps:

  1. First you must mount binfmt_misc: mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  2. To actually register a new binary type, you have to set up a string looking like
    :name:type:offset:magic:mask:interpreter:flags (where you can choose the : upon your needs) and echo it to /proc/sys/fs/binfmt_misc/register.

The linux systems that use systemd, have a helper service systemd-binfmt.service that performs the above executable type registration automatically, using entries in /etc/binfmt.d/*.conf files (and some more) as described here.

Given that box64 (and possibly wine) provides these types of binfmt configuration files, we can leverage them with a custom sysv style init service that does whatever the similar systemd binfmt service does. This PR adds an implementation of such a service.

Signed-off-by: Loukas Agorgianitis <loukas@agorgianitis.com>
@dmanlfc dmanlfc added 44 and removed don't merge labels Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants