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