File:  [NetBSD Developer Wiki] / wikisrc / guide / linux.mdwn
Revision 1.2: download - view: text, annotated - select for diffs
Fri Mar 8 23:44:42 2013 UTC (7 years, 6 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
Remove trailing newlines.

    1: # Linux emulation
    2: 
    3: The NetBSD port for i386, amd64, mac68k, macppc, and many others can execute a
    4: great number of native Linux programs, using the Linux emulation layer.
    5: Generally, when you think about emulation you imagine something slow and
    6: inefficient because, often, emulations must reproduce hardware instructions and
    7: even architectures (usually from old machines) in software. In the case of the
    8: Linux emulation, this is radically different: it is only a thin software layer,
    9: mostly for system calls which are already very similar between the two systems.
   10: The application code itself is processed at the full speed of your CPU, so you
   11: don't get a degraded performance with the Linux emulation and the feeling is
   12: exactly the same as for native NetBSD applications.
   13: 
   14: This chapter explains how to configure the Linux emulation with an example: the
   15: installation of the well known Acrobat Reader version 7 program.
   16: 
   17: ## Emulation setup
   18: 
   19: The installation of the Linux emulation is described in the
   20: [compat\_linux(8)](http://netbsd.gw.com/cgi-bin/man-cgi?compat_linux+8+NetBSD-5.0.1+i386)
   21: man page; using the package system, only two steps are needed.
   22: 
   23:  1. Configuring the kernel.
   24:  2. Installing the Linux libraries.
   25:  3. Installing Linux applications like Acrobat Reader
   26: 
   27: ### Configuring the kernel
   28: 
   29: If you use a GENERIC kernel you don't need to do anything because Linux
   30: compatibility is already enabled.
   31: 
   32: If you use a customized kernel, check that the following options are enabled:
   33: 
   34:     option COMPAT_LINUX
   35:     option EXEC_ELF32
   36: 
   37: or the following options if you are going to use 64-bit ELF binaries:
   38: 
   39:     option COMPAT_LINUX
   40:     option EXEC_ELF64
   41: 
   42: When you have compiled a kernel with the previous options, you can start
   43: installing the necessary software.
   44: 
   45: ### Installing the Linux libraries
   46: 
   47: Usually, applications are linked against shared libraries, and for Linux
   48: applications, Linux shared libraries are needed. You can get the shared
   49: libraries from any Linux distribution, provided it's not too old, but the
   50: suggested method is to use the package system and install the libraries
   51: automatically (which uses SUSE libraries). When you install the libraries, the
   52: following happens:
   53: 
   54:  * A *secondary root directory* is created which will be used for Linux
   55:    programs. This directory is `/emul/linux`. The Linux programs in emulation
   56:    mode will use this directory as their root directory and use files there. If
   57:    a required file is not found, it will be searched with `/` as root directory.
   58: 
   59:    For example, if a Linux application opens `/etc/ld.so.conf`, it will first be
   60:    searched in `/emul/linux/etc/ld.so.conf`, and if not found there, in
   61:    `/etc/ld.so.conf`.
   62: 
   63:  * The shared libraries for Linux are installed. Most applications are linked
   64:    dynamically and expect to find the necessary libraries on the system. For
   65:    example, for Acrobat Reader, if you go to the `/usr/pkgsrc/print/acroread7`
   66:    and give the `make depends` command, pkgsrc will fetch and install all
   67:    dependencies for Acrobat Reader.
   68: 
   69: Both operations will be handled automatically by the package system, without the
   70: need of manual intervention from the user (we suppose that, by now, you have
   71: already begun to love the package system...). Note that this section describes
   72: manual installation of the Linux libraries.
   73: 
   74: To install the libraries, a program must be installed that handles the RPM
   75: format: it is `rpm`, which will be used to extract the SUSE libraries. Execute
   76: `make` and `make install` in the `/usr/pkgsrc/misc/rpm/` directory to build
   77: and install `rpm`.
   78: 
   79: Next the `suse121_base` package must be installed. The SUSE RPM files can be
   80: downloaded by the package system or, if you have a SUSE CD, you can copy them in
   81: the `/usr/pkgsrc/distfiles/suse121` directory and then run `make` and
   82: `make install` after going to the `/usr/pkgsrc/emulators/suse121_base`
   83: directory.
   84: 
   85: With the same method install `suse121_compat` and `suse121_x11`. The final
   86: configuration is:
   87: 
   88:     # pkg_info -a | grep suse
   89: 	suse_base-12.1nb3   Linux compatibility package
   90: 	suse_compat-12.1    Linux compatibility package with old shared libraries
   91: 	suse_x11-12.1       Linux compatibility package for X11
   92: 
   93: *Note*: Of course you can also install the packages binary. To do this, you
   94: would either set the proper `PKG_PATH` and then
   95: 
   96:     # pkg_add rpm
   97:     # pkg_add suse_base
   98:     # pkg_add suse_compat
   99:     # pkg_add suse_x11
  100: 
  101: Or, using `pkgin`:
  102: 
  103:     # pkgin install rpm suse_base suse_compat suse_x11
  104: 
  105: *Note*: You can also skip this step when you are installing a package from
  106: pkgsrc which requires Linux emulation! A good example for this is the package
  107: `www/opera`, which will automatically install the packages needed for emulating
  108: the Linux version of the Opera browser.
  109: 
  110: ### Installing Acrobat Reader
  111: 
  112: Now everything is ready for the installation of the Acrobat Reader program (or
  113: other Linux programs). Change to `/usr/pkgsrc/print/acroread7` and give the
  114: usual commands.
  115: 
  116:     # make
  117:     # make install
  118: 
  119: ### Note
  120: 
  121: To download and install Acrobat Reader you need to add the line
  122: `ACCEPTABLE_LICENSES+=adobe-acrobat-license` to `/etc/mk.conf` to accept the
  123: Acrobat Reader license, simply follow the instructions given after `make`.
  124: 
  125: ## Directory structure
  126: 
  127: If we examine the outcome of the installation of the Linux libraries and
  128: programs we find that `/emul/linux` is a symbolic link pointing to
  129: `/usr/pkg/emul/linux`, where the following directories have been created:
  130: 
  131:  * `bin/`
  132:  * `dev/`
  133:  * `etc/`
  134:  * `lib/`
  135:  * `opt/`
  136:  * `proc/`
  137:  * `root/`
  138:  * `sbin/`
  139:  * `usr/`
  140:  * `var/`
  141: 
  142: *Note*: Please always refer to `/emul/linux` and not to `/usr/pkg/emul/linux`.
  143: The latter is an implementation detail and may change in the future.
  144: 
  145: How much space is required for the Linux emulation software? On one system we
  146: got the following figure:
  147: 
  148:     # cd /usr/pkg/emul
  149:     # du -k /emul/linux/
  150:     ...
  151:     127804  /emul/linux/
  152: 
  153: Acrobat Reader, the program, has been installed in the usual directory for
  154: package binaries: `/usr/pkg/bin`. It can be run just as any other program:
  155: 
  156:     $ acroread netbsd.pdf
  157: 
  158: ## Emulating /proc
  159: 
  160: Some Linux programs rely on a Linux-like `/proc` filesystem. The NetBSD procfs
  161: filesystem can emulate a `/proc` filesystem that contains Linux-specific
  162: pseudo-files. To accomplish this you can mount the procfs with the
  163: `linux`-option:
  164: 
  165:     # mount_procfs -o linux procfs /emul/linux/proc
  166: 
  167: In this example a Linux-like proc filesystem will be mounted to the
  168: `/emul/linux/proc` directory. You can also let NetBSD mount it automatically
  169: during the booting process of NetBSD, by adding the following line to
  170: `/etc/fstab`:
  171: 
  172:     procfs /emul/linux/proc procfs ro,linux
  173: 
  174: ## Using Linux browser plugins
  175: 
  176: Linux plugins for Mozilla-based browsers can be used on native NetBSD Firefox
  177: builds through nspluginwrapper, a wrapper that translates between the native
  178: browser and a foreign plugin. At the moment, nspluginwrapper only works reliably
  179: on Mozilla-based browsers that link against GTK2+ (GTK1+ is not supported).
  180: nspluginwrapper can be installed through pkgsrc:
  181: 
  182:     # cd /usr/pkgsrc/www/nspluginwrapper
  183:     # make install
  184: 
  185: Plugins can then be installed in two steps: first, the plugin has to be
  186: installed on the system (e.g. through pkgsrc). After that the plugin should be
  187: registered with the `nspluginwrapper` by the users who want to use that
  188: plugin.
  189: 
  190: In this short example we will have a look at installing the Macromedia Flash
  191: plugin. We can fullfill the first step by installing the Flash plugin through
  192: pkgsrc:
  193: 
  194:     # cd /usr/pkgsrc/multimedia/ns-flash
  195:     # make install
  196: 
  197: After that an unprivileged user can register the Flash plugin:
  198: 
  199:     $ nspluginwrapper -i /usr/pkg/lib/netscape/plugins/libflashplayer.so
  200: 
  201: The plugin should then be registered correctly. You can check this by using the
  202: `-l` option of `nspluginwrapper` (`nspluginwrapper -l`). If the plugin is
  203: listed, you can restart Firefox, and verify that the plugin was installed by
  204: entering `about:plugins` in the location bar.
  205: 
  206: ## Further reading
  207: 
  208: The following articles may be of interest for further understanding Linux (and other) emulation:
  209: 
  210:  * *[Implementing Linux emulation on NetBSD](http://www.linux.com/articles/35998)*. Peter Seebach. May 2004.
  211:  * *[Linux compatibility on BSD for the PPC platform, part 1](http://www.onlamp.com/pub/a/onlamp/2001/05/10/linux_bsd.html)*. Emmanuel Dreyfus. May 2001.
  212:  * *[Linux compatibility on BSD for the PPC platform, part 2](http://www.onlamp.com/pub/a/onlamp/2001/05/17/linux_bsd.html)*. Emmanuel Dreyfus. May 2001.
  213:  * *[Linux compatibility on BSD for the PPC platform, part 3](http://www.onlamp.com/pub/a/onlamp/2001/06/07/linux_bsd.html)*. Emmanuel Dreyfus. Jun 2001.
  214:  * *[Linux compatibility on BSD for the PPC platform, part 4](http://www.onlamp.com/pub/a/onlamp/2001/06/21/linux_bsd.html)*. Emmanuel Dreyfus. Jun 2001.
  215:  * *[Linux compatibility on BSD for the PPC platform, part 5](http://www.onlamp.com/pub/a/onlamp/2001/08/09/linux_bsd.html)*. Emmanuel Dreyfus. Aug 2002.
  216:  * *[Irix binary compatibility, part 1](http://www.onlamp.com/pub/a/bsd/2002/08/08/irix.html)*. Emmanuel Dreyfus. Aug 2002.
  217:  * *[Irix binary compatibility, part 2](http://www.onlamp.com/pub/a/bsd/2002/08/29/irix.html)*. Emmanuel Dreyfus. Aug 2002.
  218:  * *[Irix binary compatibility, part 3](http://www.onlamp.com/pub/a/bsd/2002/09/12/irix.html)*. Emmanuel Dreyfus. Sep 2002.
  219:  * *[Irix binary compatibility, part 4](http://www.onlamp.com/pub/a/bsd/2002/10/10/irix.html)*. Emmanuel Dreyfus. Oct 2002.
  220:  * *[Irix binary compatibility, part 5](http://www.onlamp.com/pub/a/bsd/2002/12/19/irix.html)*. Emmanuel Dreyfus. Dec 2002.
  221:  * *[Irix binary compatibility, part 6](http://www.onlamp.com/pub/a/bsd/2003/04/03/irix.html)*. Emmanuel Dreyfus. Apr 2003.
  222: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb