18c2ecf20Sopenharmony_ciMono(tm) Binary Kernel Support for Linux
28c2ecf20Sopenharmony_ci-----------------------------------------
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciTo configure Linux to automatically execute Mono-based .NET binaries
58c2ecf20Sopenharmony_ci(in the form of .exe files) without the need to use the mono CLR
68c2ecf20Sopenharmony_ciwrapper, you can use the BINFMT_MISC kernel support.
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciThis will allow you to execute Mono-based .NET binaries just like any
98c2ecf20Sopenharmony_ciother program after you have done the following:
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci1) You MUST FIRST install the Mono CLR support, either by downloading
128c2ecf20Sopenharmony_ci   a binary package, a source tarball or by installing from Git. Binary
138c2ecf20Sopenharmony_ci   packages for several distributions can be found at:
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci	https://www.mono-project.com/download/
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci   Instructions for compiling Mono can be found at:
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	https://www.mono-project.com/docs/compiling-mono/linux/
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci   Once the Mono CLR support has been installed, just check that
228c2ecf20Sopenharmony_ci   ``/usr/bin/mono`` (which could be located elsewhere, for example
238c2ecf20Sopenharmony_ci   ``/usr/local/bin/mono``) is working.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci2) You have to compile BINFMT_MISC either as a module or into
268c2ecf20Sopenharmony_ci   the kernel (``CONFIG_BINFMT_MISC``) and set it up properly.
278c2ecf20Sopenharmony_ci   If you choose to compile it as a module, you will have
288c2ecf20Sopenharmony_ci   to insert it manually with modprobe/insmod, as kmod
298c2ecf20Sopenharmony_ci   cannot be easily supported with binfmt_misc.
308c2ecf20Sopenharmony_ci   Read the file ``binfmt_misc.txt`` in this directory to know
318c2ecf20Sopenharmony_ci   more about the configuration process.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci3) Add the following entries to ``/etc/rc.local`` or similar script
348c2ecf20Sopenharmony_ci   to be run at system startup:
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci   .. code-block:: sh
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci    # Insert BINFMT_MISC module into the kernel
398c2ecf20Sopenharmony_ci    if [ ! -e /proc/sys/fs/binfmt_misc/register ]; then
408c2ecf20Sopenharmony_ci        /sbin/modprobe binfmt_misc
418c2ecf20Sopenharmony_ci	# Some distributions, like Fedora Core, perform
428c2ecf20Sopenharmony_ci	# the following command automatically when the
438c2ecf20Sopenharmony_ci	# binfmt_misc module is loaded into the kernel
448c2ecf20Sopenharmony_ci	# or during normal boot up (systemd-based systems).
458c2ecf20Sopenharmony_ci	# Thus, it is possible that the following line
468c2ecf20Sopenharmony_ci	# is not needed at all.
478c2ecf20Sopenharmony_ci	mount -t binfmt_misc none /proc/sys/fs/binfmt_misc
488c2ecf20Sopenharmony_ci    fi
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci    # Register support for .NET CLR binaries
518c2ecf20Sopenharmony_ci    if [ -e /proc/sys/fs/binfmt_misc/register ]; then
528c2ecf20Sopenharmony_ci	# Replace /usr/bin/mono with the correct pathname to
538c2ecf20Sopenharmony_ci	# the Mono CLR runtime (usually /usr/local/bin/mono
548c2ecf20Sopenharmony_ci	# when compiling from sources or CVS).
558c2ecf20Sopenharmony_ci        echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register
568c2ecf20Sopenharmony_ci    else
578c2ecf20Sopenharmony_ci        echo "No binfmt_misc support"
588c2ecf20Sopenharmony_ci        exit 1
598c2ecf20Sopenharmony_ci    fi
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci4) Check that ``.exe`` binaries can be ran without the need of a
628c2ecf20Sopenharmony_ci   wrapper script, simply by launching the ``.exe`` file directly
638c2ecf20Sopenharmony_ci   from a command prompt, for example::
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/usr/bin/xsd.exe
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci   .. note::
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci      If this fails with a permission denied error, check
708c2ecf20Sopenharmony_ci      that the ``.exe`` file has execute permissions.
71