Annotation of wikisrc/guide/linux.mdwn, revision 1.3

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

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