1.\" $NetBSD: compat_linux.8,v 1.31 2003/09/01 18:51:15 wiz Exp $ 2.\" 3.\" Copyright (c) 1995 Frank van der Linden 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed for the NetBSD Project 17.\" by Frank van der Linden 18.\" 4. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\" 32.Dd September 1, 2003 33.Dt COMPAT_LINUX 8 34.Os 35.Sh NAME 36.Nm compat_linux 37.Nd setup procedure for running Linux binaries 38.Sh DESCRIPTION 39.Nx 40supports running Linux binaries. 41This applies to arm, alpha, i386, m68k and powerpc systems for now. 42Both the a.out and ELF binary formats are supported. 43Most programs should work, including the ones that use the Linux SVGAlib (only 44on i386). 45Programs that will not work include some that use 46i386-specific calls, such as enabling virtual 8086 mode. 47Currently, sound is only partially supported for Linux binaries (they will 48probably run, depending on what Linux sound support features are used). 49.Pp 50The Linux compatibility feature is active 51for kernels compiled with the 52.Dv COMPAT_LINUX 53option enabled. 54If support for Linux a.out executables is desired, the 55.Dv EXEC_AOUT 56option should be enabled in addition to option 57.Dv COMPAT_LINUX . 58Similarly, if support for Linux 32-bit and/or 64-bit ELF executables 59is desired, the 60.Dv EXEC_ELF32 61and/or 62.Dv EXEC_ELF64 63options (respectively) should be enabled in addition to 64.Dv COMPAT_LINUX . 65.Pp 66A lot of programs are dynamically linked. 67This means that you will also need the Linux shared libraries that the 68program depends on, and the runtime linker. 69Also, you will need to create a 70.Dq shadow root 71directory for Linux binaries on your 72.Nx 73system. 74This directory is named 75.Pa /emul/linux . 76Any file operations done by Linux programs run under 77.Nx 78will look in this directory first. 79So, if a Linux program opens, for example, 80.Pa /etc/passwd , 81.Nx 82will 83first try to open 84.Pa /emul/linux/etc/passwd , 85and if that does not exist open the 86.Sq real 87.Pa /etc/passwd 88file. 89It is recommended that you install 90Linux packages that include configuration files, etc under 91.Pa /emul/linux , 92to avoid naming conflicts with possible 93.Nx 94counterparts. 95Shared libraries should also be installed in the shadow tree. 96.Pp 97Generally, you will need to look for the shared libraries that Linux 98binaries depend on only the first few times that you install a Linux 99program on your 100.Nx 101system. 102After a while, you will have a sufficient 103set of Linux shared libraries on your system to be able to run newly 104imported Linux binaries without any extra work. 105.Ss Setting up shared libraries 106How to get to know which shared libraries Linux binaries need, and where 107to get them? Basically, there are 2 possibilities (when following 108these instructions: you will need to be root on your 109.Nx 110system to 111do the necessary installation steps). 112.Bl -enum 113.It 114For i386, you can simply install the SuSE shared libs using the 115.Pa pkgsrc/emulators/suse_linux 116package(s). 117On PowerPC ports, the 118.Pa pkgsrc/emulators/linuxppc_lib 119will install the needed libraries. 120If you are on other platforms, or this doesn't supply you with all 121the needed libraries, read on. 122.It 123You have access to a Linux system. 124In this case you can temporarily install the binary there, see what 125shared libraries it needs, and copy them to your 126.Nx 127system. 128Example: you have just ftp-ed the Linux binary of Doom. 129Put it on the Linux system you have access to, and check which shared libraries it 130needs by running 131.Sq ldd linuxxdoom : 132.Pp 133.Bl -tag -width 123 -compact -offset indent 134.It (me@linux) ldd linuxxdoom 135.nf 136libXt.so.3 (DLL Jump 3.1) =\*[Gt] /usr/X11/lib/libXt.so.3.1.0 137libX11.so.3 (DLL Jump 3.1) =\*[Gt] /usr/X11/lib/libX11.so.3.1.0 138libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29 139.fi 140.El 141.Pp 142You would need go get all the files from the last column, and 143put them under 144.Pa /emul/linux , 145with the names in the first column 146as symbolic links pointing to them. 147This means you eventually have these files on your 148.Nx 149system: 150.Bl -item -compact 151.It 152.Pa /emul/linux/usr/X11/lib/libXt.so.3.1.0 153.It 154.Pa /emul/linux/usr/X11/lib/libXt.so.3 155(symbolic link to the above) 156.It 157.Pa /emul/linux/usr/X11/lib/libX11.so.3.1.0 158.It 159.Pa /emul/linux/usr/X11/lib/libX11.so.3 160(symbolic link to the above) 161.It 162.Pa /emul/linux/lib/libc.so.4.6.29 163.It 164.Pa /emul/linux/lib/libc.so.4 165(symbolic link to the above) 166.El 167.Pp 168Note that if you already have a Linux shared library with a 169matching major revision number to the first column of the 170.Xr ldd 1 171output, you won't need to copy the file named in the last column 172to your system, the one you already have should work. 173It is advisable to copy the shared library anyway if it is a newer version, 174though. 175You can remove the old one, as long as you make the symbolic 176link point to the new one. 177So, if you have these libraries on your system: 178.Pp 179.Bl -item -compact 180.It 181.Pa /emul/linux/lib/libc.so.4.6.27 182.It 183.Pa /emul/linux/lib/libc.so.4 184-\*[Gt] 185.Pa /emul/linux/lib/libc.so.4.6.27 186.El 187.Pp 188and you find that the 189.Ic ldd 190output for a new binary you want to install is: 191.nf 192.Pp 193libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29 194.fi 195.Pp 196you won't need to worry about copying 197.Pa /lib/libc.so.4.6.29 198too, because the program should work fine with the slightly older version. 199You can decide to replace the libc.so anyway, and that should leave 200you with: 201.Bl -item -compact 202.It 203.Pa /emul/linux/lib/libc.so.4.6.29 204.It 205.Pa /emul/linux/lib/libc.so.4 206-\*[Gt] 207.Pa /emul/linux/lib/libc.so.4.6.29 208.El 209.Pp 210Please note that the symbolic link mechanism is 211.Em only 212needed for Linux binaries, the 213.Nx 214runtime linker takes care of 215looking for matching major revision numbers itself, you 216don't need to worry about that. 217.Pp 218Finally, you must make sure that you have the Linux runtime linker 219and its config files on your system. 220You should copy these 221files from the Linux system to their appropriate place on your 222.Nx 223system (in the 224.Pa /emul/linux 225tree): 226.Bl -item -compact 227.It 228.Pa /lib/ld.so 229.It 230.Pa /etc/ld.so.cache 231.It 232.Pa /etc/ld.so.config 233.El 234.It 235You don't have access to a Linux system. 236In that case, you should get the extra files you need from various ftp sites. 237Information on where to look for the various files is appended below. 238For now, let's assume you know where to get the files. 239.Pp 240Retrieve the following files (from _one_ ftp site to avoid 241any version mismatches), and install them under 242.Pa /emul/linux 243(i.e. 244.Pa /foo/bar 245is installed as 246.Pa /emul/linux/foo/bar ) : 247.Pp 248.Bl -item -compact 249.It 250.Pa /sbin/ldconfig 251.It 252.Pa /usr/bin/ldd 253.It 254.Pa /lib/libc.so.x.y.z 255.It 256.Pa /lib/ld.so 257.El 258.Pp 259.Ic ldconfig 260and 261.Ic ldd 262don't necessarily need to be under 263.Pa /emul/linux , 264you can install them elsewhere in the system too. 265Just make sure they don't conflict with their 266.Nx 267counterparts. 268A good idea would be to install them in 269.Pa /usr/local/bin 270as 271.Ic ldconfig-linux 272and 273.Ic ldd-linux . 274.Pp 275Create the file 276.Pa /emul/linux/etc/ld.so.conf , 277containing the directories in which the Linux runtime linker should look 278for shared libs. 279It is a plain text file, containing a directory name on each line. 280.Pa /lib 281and 282.Pa /usr/lib 283are standard, you could add the following: 284.Bl -item -compact 285.It 286.Pa /usr/X11/lib 287.It 288.Pa /usr/local/lib 289.El 290.Pp 291Note that these are mapped to 292.Pa /emul/linux/XXXX 293by 294.Nx Ns 's 295compat 296code, and should exist as such on your system. 297.Pp 298Run the Linux 299.Ic ldconfig 300program. 301It should be statically 302linked, so it doesn't need any shared libraries by itself. 303It will create the file 304.Pa /emul/linux/etc/ld.so.cache 305You should rerun the Linux version of 306.Ic ldconfig 307each time you add a new shared library. 308.Pp 309You should now be set up for Linux binaries which only need 310a shared libc. 311You can test this by running the Linux 312.Ic ldd 313on itself. 314Suppose that you have it installed as 315.Ic ldd-linux , 316it should produce something like: 317.Pp 318.Bl -tag -width 123 -compact -offset indent 319.It (me@netbsd) ldd-linux `which ldd-linux` 320libc.so.4 (DLL Jump 4.5pl26) =\*[Gt] /lib/libc.so.4.6.29 321.El 322.Pp 323This being done, you are ready to install new Linux binaries. 324Whenever you install a new Linux program, you should check 325if it needs shared libraries, and if so, whether you have 326them installed in the 327.Pa /emul/linux 328tree. 329To do this, you run the Linux 330.Ic ldd 331on the new program, and watch its output. 332.Ic ldd 333(see also the manual page for 334.Xr ldd 1 ) 335will print a list 336of shared libraries that the program depends on, in the 337form 338.Aq majorname 339.Pq Aq jumpversion 340=\*[Gt] 341.Aq fullname . 342.Pp 343If it prints 344.Dq not found 345instead of 346.Aq fullname 347it means that you need an extra library. 348Which library this is, is shown in 349.Aq majorname , 350which will be of the form libXXXX.so.\*[Lt]N\*[Gt] 351You will need to find a libXXXX.so.\*[Lt]N\*[Gt].\*[Lt]mm\*[Gt] on a 352Linux ftp site, and install it on your system. 353The XXXX (name) and 354.Aq N 355(major revision number) should match; the minor number(s) 356.Aq mm 357are less important, though it is advised to take the most recent version. 358.El 359.Ss Setting up procfs 360Some Linux binaries expect procfs to be mounted and that it would 361contain some Linux specific stuff. 362If it's not the case, they behave unexpectedly or even crash. 363.Pp 364Mount procfs on 365.Nx 366using following command: 367.Bl -tag -width 123 -offset indent 368.It (me@netbsd) mount_procfs -o linux procfs /emul/linux/proc 369.El 370.Pp 371You can also set up your system so that procfs is mounted automatically 372on system boot, by putting an entry like the one below to 373.Pa /etc/fstab . 374.Bl -tag -width 123 -offset indent 375.It procfs /emul/linux/proc procfs ro,linux 376.El 377.Pp 378See 379.Xr mount_procfs 8 380for further information. 381.Ss Setting up other files 382Newer version of Linux use 383.Pa /etc/nsswitch.conf 384for network information, such as 385.Tn NIS 386and DNS. 387You must create or get a valid copy of this file and put it in 388.Pa /emul/linux/etc . 389.Ss Finding the necessary files 390.Em Note : 391the information below is valid as of the time this 392document was first written (March, 1995), but certain details 393such as names of ftp sites, directories and distribution names 394may have changed by the time you read this. 395.Pp 396Linux is distributed by several groups that make their own set 397of binaries that they distribute. 398Each distribution has its own name, like 399.Dq Slackware 400or 401.Dq Yggdrasil . 402The distributions are 403available on a lot of ftp sites. 404Sometimes the files are unpacked, 405and you can get the individual files you need, but mostly they 406are stored in distribution sets, usually consisting of subdirectories 407with gzipped tar files in them. 408The primary ftp sites for the distributions are: 409.Bl -item -compact -offset indent 410.It 411.Pa sunsite.unc.edu:/pub/Linux/distributions 412.It 413.Pa tsx-11.mit.edu:/pub/linux/distributions 414.El 415.Pp 416Some European mirrors: 417.Bl -item -compact -offset indent 418.It 419.Pa ftp.luth.se:/pub/linux/distributions 420.It 421.Pa ftp.demon.co.uk:/pub/linux/distributions 422.It 423.Pa src.doc.ic.ac.uk:/packages/linux/distributions 424.El 425.Pp 426For simplicity, let's concentrate on Slackware here. 427This distribution 428consists of a number of subdirectories, containing separate packages. 429Normally, they're controlled by an install program, but you can 430retrieve files 431.Dq by hand 432too. 433First of all, you will need to look in the 434.Pa contents 435subdir of the distribution. 436You will find a lot of small textfiles here describing the contents of 437the separate packages. 438The fastest way to look something up is to retrieve all the files in the 439contents subdirectory, and grep through them for the file you need. 440Here is an example of a list of files that you might need, and 441in which contents-file you will find it by grepping through them: 442.Pp 443.Bd -literal -offset indent 444Needed Package 445 446ld.so ldso 447ldconfig ldso 448ldd ldso 449libc.so.4 shlibs 450libX11.so.6.0 xf_lib 451libXt.so.6.0 xf_lib 452libX11.so.3 oldlibs 453libXt.so.3 oldlibs 454.Ed 455.Pp 456So, in this case, you will need the packages ldso, shlibs, xf_lib and oldlibs. 457In each of the contents-files for these packages, look for a line saying 458.Dq PACKAGE LOCATION , 459it will tell you on which 460.Sq disk 461the package is, 462in our case it will tell us in which subdirectory we need to look. 463For our example, we would find the following locations: 464.Pp 465.Bd -literal -offset indent 466Package Location 467 468ldso diska2 469shlibs diska2 470oldlibs diskx6 471xf_lib diskx9 472.Ed 473.Pp 474The locations called 475.Pa diskXX 476refer to the 477.Pa slakware/XX 478subdirectories 479of the distribution, others may be found in the 480.Pa contrib 481subdirectory. 482In this case, we could now retrieve the packages we need by retrieving 483the following files (relative to the root of the Slackware distribution 484tree): 485.Bl -item -compact 486.It 487.Pa slakware/a2/ldso.tgz 488.It 489.Pa slakware/a2/shlibs.tgz 490.It 491.Pa slakware/x6/oldlibs/tgz 492.It 493.Pa slakware/x9/xf_lib.tgz 494.El 495.Pp 496Extract the files from these gzipped tarfiles in your /emul/linux directory 497(possibly omitting or afterwards removing files you don't need), and you 498are done. 499.Ss Programs using SVGAlib 500SVGAlib binaries require some extra care. 501You need to have 502.Cd options WSDISPLAY_COMPAT_USL 503in your kernel (see 504.Xr wscons 4 ) , 505and you will also have to create 506some symbolic links in the 507.Pa /emul/linux/dev 508directory, namely: 509.Bl -item -compact 510.It 511.Pa /emul/linux/dev/console 512-\*[Gt] 513.Pa /dev/tty 514.It 515.Pa /emul/linux/dev/mouse 516-\*[Gt] whatever device your mouse is connected to 517.It 518.Pa /emul/linux/dev/ttyS0 519-\*[Gt] 520.Pa /dev/tty00 521.It 522.Pa /emul/linux/dev/ttyS1 523-\*[Gt] 524.Pa /dev/tty01 525.El 526.Pp 527Be warned: the first link mentioned here makes SVGAlib binaries 528work, but may confuse others, so you may have to remove it again at 529some point. 530.Sh BUGS 531The information about Linux distributions may become outdated. 532.Pp 533Pathnames pointed to by symbolic links are not looked up in the 534shadow root when running a Linux executable. 535This is not consistent. 536.Pp 537Linux executables cannot handle directory offset cookies \*[Gt] 32 bits. 538Should such an offset occur, you will see the message 539.Dq linux_getdents: dir offset too large for emulated program . 540Currently, this can only 541happen on NFS mounted filesystems, mounted from servers that return 542offsets with information in the upper 32 bits. 543These errors should rarely happen, but can be avoided by mounting this 544filesystem with offset translation enabled. 545See the 546.Fl X 547option to 548.Xr mount_nfs 8 . 549The 550.Fl 2 551option to 552.Xr mount_nfs 8 553will also have the desired effect, but is less preferable. 554