COMPAT_LINUX(8) | System Manager's Manual | COMPAT_LINUX(8) |
The Linux compatibility feature is active for kernels compiled with the COMPAT_LINUX option enabled. If support for Linux a.out executables is desired, the EXEC_AOUT option should be enabled in addition to option COMPAT_LINUX. Similarly, if support for Linux 32-bit and/or 64-bit ELF executables is desired, the EXEC_ELF32 and/or EXEC_ELF64 options (respectively) should be enabled in addition to COMPAT_LINUX.
A lot of programs are dynamically linked. This means that you will also need the Linux shared libraries that the program depends on, and the runtime linker. Also, you will need to create a “shadow root” directory for Linux binaries on your NetBSD system. This directory is named /emul/linux or /emul/linux32 for 32bit emulation on 64bit systems. Any file operations done by Linux programs run under NetBSD will look in this directory first. So, if a Linux program opens, for example, /etc/passwd, NetBSD will first try to open /emul/linux/etc/passwd, and if that does not exist open the ‘real' /etc/passwd file. It is recommended that you install Linux packages that include configuration files, etc under /emul/linux, to avoid naming conflicts with possible NetBSD counterparts. Shared libraries should also be installed in the shadow tree. Filenames that start "/../" are only looked up in the real root.
Generally, you will need to look for the shared libraries that Linux binaries depend on only the first few times that you install a Linux program on your NetBSD system. After a while, you will have a sufficient set of Linux shared libraries on your system to be able to run newly imported Linux binaries without any extra work.
(me@linux) ldd linuxxdoom libXt.so.3 (DLL Jump 3.1) => /usr/X11/lib/libXt.so.3.1.0 libX11.so.3 (DLL Jump 3.1) => /usr/X11/lib/libX11.so.3.1.0 libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
You would need go get all the files from the last column, and put them under /emul/linux, with the names in the first column as symbolic links pointing to them. This means you eventually have these files on your NetBSD system:
Note that if you already have a Linux shared library with a matching major revision number to the first column of the ldd(1) output, you won't need to copy the file named in the last column to your system, the one you already have should work. It is advisable to copy the shared library anyway if it is a newer version, though. You can remove the old one, as long as you make the symbolic link point to the new one. So, if you have these libraries on your system:
and you find that the ldd output for a new binary you want to install is:
libc.so.4 (DLL Jump 4.5pl26) => /lib/libc.so.4.6.29
you won't need to worry about copying /lib/libc.so.4.6.29 too, because the program should work fine with the slightly older version. You can decide to replace the libc.so anyway, and that should leave you with:
Please note that the symbolic link mechanism is only needed for Linux binaries, the NetBSD runtime linker takes care of looking for matching major revision numbers itself, you don't need to worry about that.
Finally, you must make sure that you have the Linux runtime linker and its config files on your system. You should copy these files from the Linux system to their appropriate place on your NetBSD system (in the /emul/linux tree):
Retrieve the following files (from _one_ ftp site to avoid any version mismatches), and install them under /emul/linux (i.e. /foo/bar is installed as /emul/linux/foo/bar):
ldconfig and ldd don't necessarily need to be under /emul/linux, you can install them elsewhere in the system too. Just make sure they don't conflict with their NetBSD counterparts. A good idea would be to install them in /usr/local/bin as ldconfig-linux and ldd-linux.
Create the file /emul/linux/etc/ld.so.conf, containing the directories in which the Linux runtime linker should look for shared libs. It is a plain text file, containing a directory name on each line. /lib and /usr/lib are standard, you could add the following:
Note that these are mapped to /emul/linux/XXXX by NetBSD's compat code, and should exist as such on your system.
Run the Linux ldconfig program. It should be statically linked, so it doesn't need any shared libraries by itself. It will create the file /emul/linux/etc/ld.so.cache You should rerun the Linux version of ldconfig each time you add a new shared library.
You should now be set up for Linux binaries which only need a shared libc. You can test this by running the Linux ldd on itself. Suppose that you have it installed as ldd-linux, it should produce something like:
This being done, you are ready to install new Linux binaries. Whenever you install a new Linux program, you should check if it needs shared libraries, and if so, whether you have them installed in the /emul/linux tree. To do this, you run the Linux ldd on the new program, and watch its output. ldd (see also the manual page for ldd(1)) will print a list of shared libraries that the program depends on, in the form <majorname> (<jumpversion>) => <fullname>.
If it prints “not found” instead of <fullname> it means that you need an extra library. Which library this is, is shown in <majorname>, which will be of the form libXXXX.so.<N> You will need to find a libXXXX.so.<N>.<mm> on a Linux ftp site, and install it on your system. The XXXX (name) and <N> (major revision number) should match; the minor number(s) <mm> are less important, though it is advised to take the most recent version.
Mount procfs on NetBSD using following command:
You can also set up your system so that procfs is mounted automatically on system boot, by putting an entry like the one below to /etc/fstab.
See mount_procfs(8) for further information.
Linux is distributed by several groups that make their own set of binaries that they distribute. Each distribution has its own name, like “Slackware” or “Yggdrasil”. The distributions are available on a lot of ftp sites. Sometimes the files are unpacked, and you can get the individual files you need, but mostly they are stored in distribution sets, usually consisting of subdirectories with gzipped tar files in them. The primary ftp sites for the distributions are:
Some European mirrors:
For simplicity, let's concentrate on Slackware here. This distribution consists of a number of subdirectories, containing separate packages. Normally, they're controlled by an install program, but you can retrieve files “by hand” too. First of all, you will need to look in the contents subdir of the distribution. You will find a lot of small textfiles here describing the contents of the separate packages. The fastest way to look something up is to retrieve all the files in the contents subdirectory, and grep through them for the file you need. Here is an example of a list of files that you might need, and in which contents-file you will find it by grepping through them:
Needed Package ld.so ldso ldconfig ldso ldd ldso libc.so.4 shlibs libX11.so.6.0 xf_lib libXt.so.6.0 xf_lib libX11.so.3 oldlibs libXt.so.3 oldlibs
So, in this case, you will need the packages ldso, shlibs, xf_lib and oldlibs. In each of the contents-files for these packages, look for a line saying “PACKAGE LOCATION”, it will tell you on which ‘disk' the package is, in our case it will tell us in which subdirectory we need to look. For our example, we would find the following locations:
Package Location ldso diska2 shlibs diska2 oldlibs diskx6 xf_lib diskx9
The locations called diskXX refer to the slakware/XX subdirectories of the distribution, others may be found in the contrib subdirectory. In this case, we could now retrieve the packages we need by retrieving the following files (relative to the root of the Slackware distribution tree):
Extract the files from these gzipped tarfiles in your /emul/linux directory (possibly omitting or afterwards removing files you don't need), and you are done.
Be warned: the first link mentioned here makes SVGAlib binaries work, but may confuse others, so you may have to remove it again at some point.
Absolute pathnames pointed to by symbolic links are only looked up in the shadow root when the symbolic link itself was found by an absolute pathname inside the shadow root. This is not consistent.
Linux executables cannot handle directory offset cookies > 32 bits. Should such an offset occur, you will see the message “linux_getdents: dir offset too large for emulated program”. Currently, this can only happen on NFS mounted file systems, mounted from servers that return offsets with information in the upper 32 bits. These errors should rarely happen, but can be avoided by mounting this file system with offset translation enabled. See the -X option to mount_nfs(8). The -2 option to mount_nfs(8) will also have the desired effect, but is less preferable.
April 30, 2007 | NetBSD 6.1 |