0

How can I make registered extensions for binfmt_misc persist across reboots?

Consider the following command, which performs a binfmt_misc registration:

echo ':golang:E::go::/tmp/test:OC' | sudo tee /proc/sys/fs/binfmt_misc/register

It needs to be executed as root, since only root is allowed to write to /proc/sys/fs/binfmt_misc/register. Thus, I cannot put such registrations into e.g. ~/.bashrc as an unprivileged user.

Shuzheng
  • 4,023
  • 1
  • 31
  • 71

1 Answers1

4

Since you’re using Debian, you could install binfmt-support and register your extension using update-binfmts:

sudo update-binfmts --install golang /tmp/test --extension go --credentials yes

If that works, you can store the binfmt_misc specification in a file under /usr/share/binfmts, which will ensure it’s loaded every time the system boots:

cat <<EOF | sudo tee /usr/share/binfmts/golang
package <local>
interpreter /tmp/test
extension go
credentials yes
EOF

To check the above works, run

sudo update-binfmts --import golang

Alternatively, you can use systemd’s support for binfmt_misc:

echo ':golang:E::go::/tmp/test:OC' | sudo tee /etc/binfmt.d/golang.conf

This will be loaded at boot by systemd-binfmt.service .

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Weird, `/usr/share/binfmts` already exists (and contains `python3` support), but `binfmt-support` is not installed? Does `binfmt-support` install a `systemd` service, or how are the specifications loaded on boot? Finally, do you know if `systemd` provides support for `binfmt_misc`? I read some comments that it might do. – Shuzheng Mar 23 '21 at 09:04
  • Packages install `binfmt-support` files so that, if `binfmt-support` is installed, their entries are automatically registered (in the same way as `logrotate` configuration files etc.). `binfmt-support` installs an init script and a systemd service. See the forthcoming update re systemd support. – Stephen Kitt Mar 23 '21 at 09:07
  • Thanks :) - Since `systemd` now provides `binfmt_misc` support doesn't that makes `binfmt-support` obsolete? – Shuzheng Mar 23 '21 at 11:45
  • For systems using systemd, yes, but Debian doesn’t mandate systemd. – Stephen Kitt Mar 23 '21 at 12:29