ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / Documentation / binfmt_misc.txt
1      Kernel Support for miscellaneous (your favourite) Binary Formats v1.1
2      =====================================================================
3
4 This Kernel feature allows you to invoke almost (for restrictions see below)
5 every program by simply typing its name in the shell.
6 This includes for example compiled Java(TM), Python or Emacs programs.
7
8 To achieve this you must tell binfmt_misc which interpreter has to be invoked
9 with which binary. Binfmt_misc recognises the binary-type by matching some bytes
10 at the beginning of the file with a magic byte sequence (masking out specified
11 bits) you have supplied. Binfmt_misc can also recognise a filename extension
12 aka '.com' or '.exe'.
13
14 First you must mount binfmt_misc:
15         mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc 
16
17 To actually register a new binary type, you have to set up a string looking like
18 :name:type:offset:magic:mask:interpreter: (where you can choose the ':' upon
19 your needs) and echo it to /proc/sys/fs/binfmt_misc/register.
20 Here is what the fields mean:
21  - 'name' is an identifier string. A new /proc file will be created with this
22    name below /proc/sys/fs/binfmt_misc
23  - 'type' is the type of recognition. Give 'M' for magic and 'E' for extension.
24  - 'offset' is the offset of the magic/mask in the file, counted in bytes. This
25    defaults to 0 if you omit it (i.e. you write ':name:type::magic...')
26  - 'magic' is the byte sequence binfmt_misc is matching for. The magic string
27    may contain hex-encoded characters like \x0a or \xA4. In a shell environment
28    you will have to write \\x0a to prevent the shell from eating your \.
29    If you chose filename extension matching, this is the extension to be
30    recognised (without the '.', the \x0a specials are not allowed). Extension
31    matching is case sensitive!
32  - 'mask' is an (optional, defaults to all 0xff) mask. You can mask out some
33    bits from matching by supplying a string like magic and as long as magic.
34    The mask is anded with the byte sequence of the file.
35  - 'interpreter' is the program that should be invoked with the binary as first
36    argument (specify the full path)
37
38 There are some restrictions:
39  - the whole register string may not exceed 255 characters
40  - the magic must reside in the first 128 bytes of the file, i.e.
41    offset+size(magic) has to be less than 128
42  - the interpreter string may not exceed 127 characters
43
44 To use binfmt_misc you have to mount it first. You can mount it with
45 "mount -t binfmt_misc none /proc/sys/fs/binfmt_misc" command, or you can add
46 a line "none  /proc/sys/fs/binfmt_misc binfmt_misc defaults 0 0" to your
47 /etc/fstab so it auto mounts on boot.
48
49 You may want to add the binary formats in one of your /etc/rc scripts during
50 boot-up. Read the manual of your init program to figure out how to do this
51 right.
52
53 Think about the order of adding entries! Later added entries are matched first!
54
55
56 A few examples (assumed you are in /proc/sys/fs/binfmt_misc):
57
58 - enable support for em86 (like binfmt_em86, for Alpha AXP only):
59   echo ':i386:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register
60   echo ':i486:M::\x7fELF\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfb\xff\xff:/bin/em86:' > register
61
62 - enable support for packed DOS applications (pre-configured dosemu hdimages):
63   echo ':DEXE:M::\x0eDEX::/usr/bin/dosexec:' > register
64
65 - enable support for Windows executables using wine:
66   echo ':DOSWin:M::MZ::/usr/local/bin/wine:' > register
67
68 For java support see Documentation/java.txt
69
70
71 You can enable/disable binfmt_misc or one binary type by echoing 0 (to disable)
72 or 1 (to enable) to /proc/sys/fs/binfmt_misc/status or /proc/.../the_name.
73 Catting the file tells you the current status of binfmt_misc/the entry.
74
75 You can remove one entry or all entries by echoing -1 to /proc/.../the_name
76 or /proc/sys/fs/binfmt_misc/status.
77
78
79 HINTS:
80 ======
81
82 If you want to pass special arguments to your interpreter, you can
83 write a wrapper script for it. See Documentation/java.txt for an
84 example.
85
86 Your interpreter should NOT look in the PATH for the filename; the
87 kernel passes it the full filename to use.  Using the PATH can cause
88 unexpected behaviour and be a security hazard.
89
90
91 There is a web page about binfmt_misc at
92 http://www.tat.physik.uni-tuebingen.de/~rguenth/linux/binfmt_misc.html
93
94 Richard Günther <rguenth@tat.physik.uni-tuebingen.de>