All I'm trying to do is getting a manually installed mono (to /opt/mono-2.10) to run CLI executables without having to specify the interpreter explicitly. Wine is not installed.

Ubuntu 10.10. No mono package is currently installed (dpkg -l | grep mono gives nothing), but they were in the past before I realized that I need a much newer one, so that's probably the source of this mess.

Running a CLI executable gives me this:

Can't exec "/usr/lib/cli/binfmt-detector-cli": No such file or directory at /usr/share/binfmt-support/run-detectors line 92.

That is correct, /usr/lib/cli/binfmt-detector-cli does not exist and I don't know where it should have come from.

So I googled a bit and found some information about the binfmt_misc module. Indeed, it is loaded and I have a /proc/sys/fs/binfmt_misc/cli which contains this:

interpreter /usr/share/binfmt-support/run-detectors
offset 0
magic 4d5a

This run-detectors script is Perl, but apparently doesn't work (this is probably Debian #575776):

user@host:/$ /usr/share/binfmt-support/run-detectors
Use of uninitialized value in open at /usr/share/binfmt-support/run-detectors line 56.
Use of uninitialized value $ARGV[0] in concatenation (.) or string at /usr/share/binfmt-support/run-detectors line 56.
run-detectors: unable to open : No such file or directory

But anyway, I don't have Wine, so I don't need all that binfmt-detector-cli stuff in the first place. I just want those binaries to be hard linked with the Mono interpreter. I found this answer on SU and this blog entry, which discuss how to change these rules. Unfortunately, trying that, I always get a 'permission denied':

user@host:/$ sudo echo .:CLR:M::MZ::/opt/mono-2.10/bin/mono:. > /proc/sys/fs/binfmt_misc/register
bash: /proc/sys/fs/binfmt_misc/register: Permission denied
user@host:/$ sudo echo -1 > /proc/sys/fs/binfmt_misc/cli
bash: /proc/sys/fs/binfmt_misc/cli: Permission denied

I found /usr/share/binfmts/cli and changed it to

package mono-runtime
interpreter /opt/mono-2.10/bin/mono
magic MZ

but that seems to have no effect. Then there is /var/lib/binfmts/cli, which I changed to



but that also has no effect. I also found the script update-binfmts but I can't get it to work. I don't even manage to remove an existing configuration. The following attempt for example leaves me with a rather cryptic error message:

user@host:/$ sudo update-binfmts --remove cli /opt/mono-2.10/bin/mono
update-binfmts: warning: current package is <local>, but binary format already
installed by mono-runtime ; not removing.

I have no idea whether my arguments were valid (the help page mentions <path> but doesn't say the path to what it wants... or why), whether the second line is supposed to be an error message and whether it changed anything in the first place.

How do I make any executable that starts with the magic string 'MZ' to be run with /opt/mono-2.10/bin/mono?

Update 1: The outputs to the commands Colin suggested:

user@host:/$ sudo update-binfmts --package mono-runtime --remove cli /opt/mono-2.10/bin/mono
update-binfmts: warning: current package is mono-runtime, but binary format
already installed by mono-runtime ; not removing.
user@host:/$ dpkg -S /usr/share/binfmts/cli
dpkg: /usr/share/binfmts/cli not found.
user@host:/$ sudo rm /usr/share/binfmts/cli*
user@host:/$ sudo update-binfmts --install cli /opt/mono-2.10/bin/mono --magic MZ
update-binfmts: warning: current package is <local>, but binary format already
installed by mono-runtime
update-binfmts: exiting due to previous errors
  • 1
    If you have 300rep, please retag this with 'binfmts'. I can't create the tag myself and 'executable' was just a stopgap solution. – hheimbuerger Apr 12 '11 at 15:09

You should never edit /var/lib/binfmts/cli by hand. That's a state file for update-binfmts. You may have confused it by doing so, although I suspect the mono packages were buggy in the first place to have left things in this condition. Plus, there's a trailing space confusing matters.

I'd recommend clearing out state first:

update-binfmts --package 'mono-runtime ' --remove cli /opt/mono-2.10/bin/mono

Then check whether /usr/share/binfmts/cli is owned by any package (dpkg -S /usr/share/binfmts/cli - I don't think it should be, as you don't have mono-runtime installed), and if not then remove that file.

Then install the binary format properly, as a locally-installed format rather than one owned by a package:

update-binfmts --install cli /opt/mono-2.10/bin/mono --magic MZ

| improve this answer | |
  • Thanks, that's exactly the kind of answer I was hoping for. Unfortunately, I still can't convince update-binfmts to do anything and I just can't make any sense of its responses. They have been added as Update 1 on the question. – hheimbuerger Apr 13 '11 at 13:57
  • 2
    You've managed to tell update-binfmts that an interpreter is owned by a package name ending in a space, which is indeed bound to be confusing. (I fixed this in binfmt-support 1.2.19; trailing spaces are now automatically stripped.) I've edited the first command in my answer to account for this. – Colin Watson Apr 14 '11 at 0:38
  • Brilliant, that fixed it. Both commands now completed successfully and CLI executables can be invoked without any warnings or errors. Thanks so much! – hheimbuerger Apr 14 '11 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.