从混乱的 binfmts 配置中恢复

hhe*_*ger 2 executable

我想要做的就是获得一个手动安装的单声道(到 /opt/mono-2.10)来运行 CLI 可执行文件,而不必明确指定解释器。安装Wine 。

Ubuntu 10.10。目前dpkg -l | grep mono没有安装 mono 包(什么也没安装),但是在我意识到我需要一个更新的包之前它们已经过去了,所以这可能是造成这种混乱的根源。

运行 CLI 可执行文件给了我这个:

Can't exec "/usr/lib/cli/binfmt-detector-cli": No such file or directory at /usr/share/binfmt-support/run-detectors line 92.
Run Code Online (Sandbox Code Playgroud)

这是正确的,/usr/lib/cli/binfmt-detector-cli不存在,我不知道它应该来自哪里。

所以我用谷歌搜索了一下,找到了一些关于 binfmt_misc 模块的信息。实际上,它已加载,并且我有一个/proc/sys/fs/binfmt_misc/cli包含以下内容的内容:

enabled
interpreter /usr/share/binfmt-support/run-detectors
flags:
offset 0
magic 4d5a
Run Code Online (Sandbox Code Playgroud)

这个run-detectors脚本是 Perl,但显然不起作用(这可能是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
Run Code Online (Sandbox Code Playgroud)

但无论如何,我没有 Wine,所以我一开始就不需要所有 binfmt-detector-cli 的东西。我只是希望这些二进制文件与 Mono 解释器硬链接。我在 SU这个博客条目找到了这个答案,其中讨论了如何更改这些规则。不幸的是,尝试这样做,我总是得到“权限被拒绝”:

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
Run Code Online (Sandbox Code Playgroud)

我发现/usr/share/binfmts/cli并将其更改为

package mono-runtime
interpreter /opt/mono-2.10/bin/mono
magic MZ
Run Code Online (Sandbox Code Playgroud)

但这似乎没有效果。然后是/var/lib/binfmts/cli,我改为

mono-runtime
magic
0
MZ

/opt/mono-2.10/bin/mono
Run Code Online (Sandbox Code Playgroud)

但这也没有效果。我也找到了脚本,update-binfmts但我无法让它工作。我什至无法删除现有配置。例如,以下尝试给我留下了一个相当神秘的错误消息:

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.
Run Code Online (Sandbox Code Playgroud)

我不知道我的论点是否有效(帮助页面提到<path>但没有说明它想要什么的路径......或为什么),第二行是否应该是一条错误消息以及它是否改变了第一名。

我如何制作任何以魔术字符串“MZ”开头的可执行文件来运行/opt/mono-2.10/bin/mono


更新 1:Colin 建议的命令的输出:

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
Run Code Online (Sandbox Code Playgroud)

Col*_*son 5

您永远不应该/var/lib/binfmts/cli手动编辑。这是update-binfmts. 这样做可能会让您感到困惑,尽管我怀疑单声道包首先是有问题的,从而使事情处于这种状态。另外,有一个尾随空格令人困惑的事情。

我建议先清除状态:

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

然后检查 /usr/share/binfmts/cli 是否属于任何包(dpkg -S /usr/share/binfmts/cli- 我认为不应该是,因为您没有安装单运行时),如果不是,则删除该文件。

然后正确安装二进制格式,作为本地安装的格式而不是包拥有的格式:

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

  • 您已经设法告诉 update-binfmts 解释器由以空格结尾的包名拥有,这确实会令人困惑。(我在 binfmt-support 1.2.19 中修复了这个问题;现在自动去除尾随空格。)我已经编辑了我的答案中的第一个命令来解决这个问题。 (2认同)