^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) Mono(tm) Binary Kernel Support for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) -----------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) To configure Linux to automatically execute Mono-based .NET binaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) (in the form of .exe files) without the need to use the mono CLR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) wrapper, you can use the BINFMT_MISC kernel support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) This will allow you to execute Mono-based .NET binaries just like any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) other program after you have done the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 1) You MUST FIRST install the Mono CLR support, either by downloading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) a binary package, a source tarball or by installing from Git. Binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) packages for several distributions can be found at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) https://www.mono-project.com/download/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) Instructions for compiling Mono can be found at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) https://www.mono-project.com/docs/compiling-mono/linux/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) Once the Mono CLR support has been installed, just check that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ``/usr/bin/mono`` (which could be located elsewhere, for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) ``/usr/local/bin/mono``) is working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 2) You have to compile BINFMT_MISC either as a module or into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) the kernel (``CONFIG_BINFMT_MISC``) and set it up properly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) If you choose to compile it as a module, you will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) to insert it manually with modprobe/insmod, as kmod
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) cannot be easily supported with binfmt_misc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Read the file ``binfmt_misc.txt`` in this directory to know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) more about the configuration process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 3) Add the following entries to ``/etc/rc.local`` or similar script
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) to be run at system startup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .. code-block:: sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) # Insert BINFMT_MISC module into the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if [ ! -e /proc/sys/fs/binfmt_misc/register ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /sbin/modprobe binfmt_misc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) # Some distributions, like Fedora Core, perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) # the following command automatically when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) # binfmt_misc module is loaded into the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) # or during normal boot up (systemd-based systems).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) # Thus, it is possible that the following line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) # is not needed at all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) # Register support for .NET CLR binaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if [ -e /proc/sys/fs/binfmt_misc/register ]; then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) # Replace /usr/bin/mono with the correct pathname to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) # the Mono CLR runtime (usually /usr/local/bin/mono
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) # when compiling from sources or CVS).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) echo "No binfmt_misc support"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 4) Check that ``.exe`` binaries can be ran without the need of a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) wrapper script, simply by launching the ``.exe`` file directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) from a command prompt, for example::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /usr/bin/xsd.exe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) .. note::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) If this fails with a permission denied error, check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) that the ``.exe`` file has execute permissions.