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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
See How is Mono magical? for more background. /proc/sys/fs/binfmt_misc is a virtual file system managed by binfmt_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 using java -jar ...).
The python files provide support for Python bytecode.
status shows the overall status of binfmt_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) to register. The registered format will show up as a new file alongside cli, 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 (the love 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0