I following Michael's reply to see what executable formats my Ubuntu can recognize to execute
$ ls -l /proc/sys/fs/binfmt_misc/
total 0
-rw-r--r-- 1 root root 0 Apr 19 16:11 cli
-rw-r--r-- 1 root root 0 Apr 19 16:11 jar
-rw-r--r-- 1 root root 0 Apr 19 16:11 python2.7
-rw-r--r-- 1 root root 0 Apr 19 16:11 python3.5
--w------- 1 root root 0 Apr 19 16:11 register
-rw-r--r-- 1 root root 0 Apr 19 16:11 status
I have never intentionally changed anything there, and the files were created by default or when I installed some other programs.
$ cat /proc/sys/fs/binfmt_misc/cli
enabled
interpreter /usr/lib/binfmt-support/run-detectors
flags:
offset 0
magic 4d5a
What kind of executable format is this? I googled "magic 4d5a" and found https://en.wikipedia.org/wiki/DOS_MZ_executable, but I am not sure how the file was created there since it is not a native executable format to Linux. Did installation of wine
add it?
$ cat /proc/sys/fs/binfmt_misc/jar
enabled
interpreter /usr/lib/jvm/java-9-oracle/lib/jexec
flags:
offset 0
magic 504b0304
Is the above for JVM bytecode format?
$ cat /proc/sys/fs/binfmt_misc/python3.5
enabled
interpreter /usr/bin/python3.5
flags:
offset 0
magic 160d0d0a
Is the above for Python bytecode or Python?
$ cat /proc/sys/fs/binfmt_misc/status
enabled
$ cat /proc/sys/fs/binfmt_misc/register
cat: /proc/sys/fs/binfmt_misc/register: Permission denied
What is /proc/sys/fs/binfmt_misc/register
used for? Does it also allow some executable format?
Does ELF format need a file under /proc/sys/fs/binfmt_misc/
?
Thanks.
Best Answer
See How is Mono magical? for more background.
/proc/sys/fs/binfmt_misc
is a virtual file system managed bybinfmt_misc
(which is why the files are all 0-sized).cli
is used for Windows and .NET executables (and really any MZ executable, as also used in DOS and OS/2); the detector it refers to determines whether a given binary should be run using Wine or Mono.jar
provides support for JAR files, as used by Java programs. You can thus make a JAR executable, and run it directly (instead of usingjava -jar ...
).The
python
files provide support for Python bytecode.status
shows the overall status ofbinfmt_misc
: in this case, it’s enabled.register
allows new formats to be registered. This is done by echoing a string in a specific format (see the documentation for details) toregister
. The registered format will show up as a new file alongsidecli
,jar
and the others.Many kinds of executable formats can be registered using
binfmt_misc
. They can be matched using a file extension (.jar
etc., although JAR files are identified by their “PK” signature instead) or a magic value (“MZ” etc.), as long as the magic value occurs within the first 128 bytes. Beyond the files you’ve listed, other formats typically handled in this way are binaries for other architectures (“interpreted” by QEMU, or emulators such as Hatari), some interpreted game formats (thelove
game engine registers itself in this fashion under Debian at least)...Under Debian and derivatives, packages register binary formats using
binfmt-support
and files in/usr/share/binfmts/cli
;dlocate -S /usr/share/binfmts/*
will tell you which packages are adding binary formats.ELF doesn’t need any registration, it’s supported natively by the kernel.