1.\" $NetBSD: compat_freebsd.8,v 1.15 2011/11/21 15:11:45 wiz Exp $ 2.\" from: compat_linux.8,v 1.1 1995/03/05 23:30:36 fvdl Exp 3.\" 4.\" Copyright (c) 1995 Frank van der Linden 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project 18.\" by Frank van der Linden 19.\" 4. The name of the author may not be used to endorse or promote products 20.\" derived from this software without specific prior written permission 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\" 33.Dd June 4, 1995 34.Dt COMPAT_FREEBSD 8 35.Os 36.Sh NAME 37.Nm compat_freebsd 38.Nd setup procedure for running FreeBSD binaries 39.Sh DESCRIPTION 40.Nx 41supports running 42.Fx 43binaries. 44Most binaries should work, except programs that use 45.Fx Ns -specific 46features. 47These include i386-specific calls, such as syscons utilities. 48The 49.Fx 50compatibility feature is active for kernels compiled 51with the 52.Dv COMPAT_FREEBSD 53option enabled. 54.Pp 55A lot of programs are dynamically linked. 56This means, that you will also need the 57.Fx 58shared libraries that the program depends on, and the runtime 59linker. 60Also, you will need to create a 61.Dq shadow root 62directory for 63.Fx 64binaries on your 65.Nx 66system. 67This directory is named 68.Pa /emul/freebsd . 69Any file operations done by 70.Fx 71programs run under 72.Nx 73will look in this directory first. 74So, if a 75.Fx 76program opens, for example, 77.Pa /etc/passwd , 78.Nx 79will 80first try to open 81.Pa /emul/freebsd/etc/passwd , 82and if that does not exist open the 83.Sq real 84.Pa /etc/passwd 85file. 86It is recommended that you install 87.Fx 88packages that include configuration files, etc under 89.Pa /emul/freebsd , 90to avoid naming conflicts with possible 91.Nx 92counterparts. 93Shared libraries should also be installed in the shadow tree. 94.Pp 95Generally, you will need to look for the shared libraries that 96.Fx 97binaries depend on only the first few times that you install a 98.Fx 99program on your 100.Nx 101system. 102After a while, you will have a sufficient set of 103.Fx 104shared libraries on your system to be able to run newly imported 105.Fx 106binaries without any extra work. 107.Ss Setting up shared libraries 108How to get to know which shared libraries 109.Fx 110binaries need, and where 111to get them? Basically, there are 2 possibilities (when following 112these instructions: you will need to be root on your 113.Nx 114system to do the necessary installation steps). 115.Pp 116.Bl -enum -compact 117.It 118You have access to a 119.Fx 120system. 121In this case you can temporarily install the binary there, see what 122shared libraries it needs, and copy them to your 123.Nx 124system. 125Example: you have just ftp-ed the 126.Fx 127binary of SimCity. 128Put it on the 129.Fx 130system you have access to, and check which shared libraries it 131needs by running 132.Sq ldd sim : 133.Bd -literal -offset indent 134me@freebsd% ldd /usr/local/lib/SimCity/res/sim 135/usr/local/lib/SimCity/res/sim: 136 -lXext.6 =\*[Gt] /usr/X11R6/lib/libXext.so.6.0 (0x100c1000) 137 -lX11.6 =\*[Gt] /usr/X11R6/lib/libX11.so.6.0 (0x100c9000) 138 -lc.2 =\*[Gt] /usr/lib/libc.so.2.1 (0x10144000) 139 -lm.2 =\*[Gt] /usr/lib/libm.so.2.0 (0x101a7000) 140 -lgcc.261 =\*[Gt] /usr/lib/libgcc.so.261.0 (0x101bf000) 141.Ed 142.Pp 143You would need go get all the files from the last column, and 144put them under 145.Pa /emul/freebsd . 146This means you eventually have these files on your 147.Nx 148system: 149.Bl -item -compact 150.It 151.Pa /emul/freebsd/usr/X11R6/lib/libXext.so.6.0 152.It 153.Pa /emul/freebsd/usr/X11R6/lib/libX11.so.6.0 154.It 155.Pa /emul/freebsd/usr/lib/libc.so.2.1 156.It 157.Pa /emul/freebsd/usr/lib/libm.so.2.0 158.It 159.Pa /emul/freebsd/usr/lib/libgcc.so.261.0 160.El 161.Pp 162Note that if you already have a 163.Fx 164shared library with a matching major revision number to the first 165column of the 166.Ic ldd 167output, you won't need to copy the file named 168in the last column to your system, the one you already have should 169work. 170It is advisable to copy the shared library anyway if it is a newer version, 171though. 172You can remove the old one. 173So, if you have these libraries on your system: 174.Bl -item -compact 175.It 176.Pa /emul/freebsd/usr/lib/libc.so.2.0 177.El 178.Pp 179and you find that the ldd output for a new binary you want to 180install is: 181.Bd -literal 182\-lc.2 =\*[Gt] /usr/lib/libc.so.2.1 (0x10144000) 183.Ed 184.Pp 185You won't need to worry about copying 186.Pa /usr/lib/libc.so.2.1 187too, because the program should work fine with the slightly older version. 188You can decide to replace the libc.so anyway, and that should leave 189you with: 190.Bl -item -compact 191.It 192.Pa /emul/freebsd/usr/lib/libc.so.2.1 193.El 194.Pp 195Finally, you must make sure that you have the 196.Fx 197runtime linker and its config files on your system. 198You should copy these files from the 199.Fx 200system to their appropriate place on your 201.Nx 202system (in the 203.Pa /emul/freebsd 204tree): 205.Bl -item -compact 206.It 207.Pa usr/libexec/ld.so 208.It 209.Pa var/run/ld.so.hints 210.El 211.It 212You don't have access to a 213.Fx 214system. 215In that case, you should get the extra files you need from various ftp sites. 216Information on where to look for the various files is appended 217below. 218For now, let's assume you know where to get the files. 219.Pp 220Retrieve the following files (from _one_ ftp site to avoid 221any version mismatches), and install them under 222.Pa /emul/freebsd 223(i.e. 224.Pa foo/bar 225is installed as 226.Pa /emul/freebsd/foo/bar ) : 227.Bl -item -compact 228.It 229.Pa sbin/ldconfig 230.It 231.Pa usr/bin/ldd 232.It 233.Pa usr/lib/libc.so.x.y.z 234.It 235.Pa usr/libexec/ld.so 236.El 237.Pp 238.Ic ldconfig 239and 240.Ic ldd 241don't necessarily need to be under 242.Pa /emul/freebsd , 243you can install them elsewhere in the system too. 244Just make sure they don't conflict with their 245.Nx 246counterparts. 247A good idea would be to install them in 248.Pa /usr/local/bin 249as 250.Ic ldconfig-freebsd 251and 252.Ic ldd-freebsd . 253.Pp 254Run the 255.Fx 256ldconfig program with directory arguments in which the 257.Fx 258runtime linker should look for shared libs. 259.Pa /usr/lib 260are standard, you could run like the following: 261.Bd -literal -offset indent 262me@netbsd% mkdir -p /emul/freebsd/var/run 263me@netbsd% touch /emul/freebsd/var/run/ld.so.hints 264me@netbsd% ldconfig-freebsd /usr/X11R6/lib /usr/local/lib 265.Ed 266.Pp 267Note that argument directories of ldconfig are 268mapped to 269.Pa /emul/freebsd/XXXX 270by 271.Nx Ns 's 272compat code, and should exist as such on your system. 273Make sure 274.Pa /emul/freebsd/var/run/ld.so.hints 275is existing when you run 276.Fx Ns 's 277ldconfig, if not, you may lose 278.Nx Ns 's 279.Pa /var/run/ld.so.hints . 280.Fx 281.Ic ldconfig 282should be statically 283linked, so it doesn't need any shared libraries by itself. 284It will create the file 285.Pa /emul/freebsd/var/run/ld.so.hints . 286You should rerun the 287.Fx 288version of the ldconfig program each time you add a new shared library. 289.Pp 290You should now be set up for 291.Fx 292binaries which only need a shared libc. 293You can test this by running the 294.Fx 295.Ic ldd 296on itself. 297Suppose that you have it installed as 298.Ic ldd-freebsd , 299it should produce something like: 300.Bd -literal -offset indent 301me@netbsd% ldd-freebsd `which ldd-freebsd` 302/usr/local/bin/ldd-freebsd: 303 -lc.2 =\*[Gt] /usr/lib/libc.so.2.1 (0x1001a000) 304.Ed 305.Pp 306This being done, you are ready to install new 307.Fx 308binaries. 309Whenever you install a new 310.Fx 311program, you should check if it needs shared libraries, and if so, 312whether you have them installed in the 313.Pa /emul/freebsd 314tree. 315To do this, you run the 316.Fx 317version 318.Ic ldd 319on the new program, and watch its output. 320.Ic ldd 321(see also the manual page for 322.Xr ldd 1 ) 323will print a list 324of shared libraries that the program depends on, in the 325form -l\*[Lt]majorname\*[Gt] =\*[Gt] \*[Lt]fullname\*[Gt]. 326.Pp 327If it prints 328.Dq not found 329instead of \*[Lt]fullname\*[Gt] it means that you need an extra library. 330Which library this is, is shown 331in \*[Lt]majorname\*[Gt], which will be of the form XXXX.\*[Lt]N\*[Gt] 332You will need to find a libXXXX.so.\*[Lt]N\*[Gt].\*[Lt]mm\*[Gt] on a 333.Fx 334ftp site, and install it on your system. 335The XXXX (name) and \*[Lt]N\*[Gt] (major 336revision number) should match; the minor number(s) \*[Lt]mm\*[Gt] are 337less important, though it is advised to take the most 338recent version. 339.Pp 340.It 341In some cases, 342.Fx 343binary needs access to certain device file. 344For example, 345.Fx 346X server software needs 347.Fx 348.Pa /dev/ttyv0 349for ioctls. 350In this case, create a symbolic link from 351.Pa /emul/freebsd/dev/ttyv0 352to a 353.Xr wscons 4 354device file like 355.Pa /dev/ttyE0 . 356You will need to have at least 357.Cd options WSDISPLAY_COMPAT_SYSCONS 358and probably also 359.Cd options WSDISPLAY_COMPAT_USL 360in your kernel (see 361.Xr options 4 362and 363.Xr wscons 4 ) . 364.El 365.Ss Finding the necessary files 366.Em Note : 367the information below is valid as of the time this 368document was written (June, 1995), but certain details 369such as names of ftp sites, directories and distribution names 370may have changed by the time you read this. 371.Pp 372The 373.Fx 374distribution is available on a lot of ftp sites. 375Sometimes the files are unpacked, and you can get the individual 376files you need, but mostly they are stored in distribution sets, 377usually consisting of subdirectories with gzipped tar files in them. 378The primary ftp sites for the distributions are: 379.Bl -item -compact -offset indent 380.It 381.Pa ftp.freebsd.org:/pub/FreeBSD 382.El 383.Pp 384Mirror sites are described on: 385.Bl -item -compact -offset indent 386.It 387.Pa ftp.freebsd.org:/pub/FreeBSD/MIRROR.SITES 388.El 389.Pp 390This distribution consists of a number of tar-ed and gzipped files, 391Normally, they're controlled by an install program, but you can 392retrieve files 393.Dq by hand 394too. 395The way to look something up is to retrieve all the files in the 396distribution, and ``tar ztvf'' through them for the file you need. 397Here is an example of a list of files that you might need. 398.Bd -literal -offset indent 399Needed Files 400 401ld.so 2.0-RELEASE/bindist/bindist.?? 402ldconfig 2.0-RELEASE/bindist/bindist.?? 403ldd 2.0-RELEASE/bindist/bindist.?? 404libc.so.2 2.0-RELEASE/bindist/bindist.?? 405libX11.so.6.0 2.0-RELEASE/XFree86-3.1/XFree86-3.1-bin.tar.gz 406libX11.so.6.0 XFree86-3.1.1/X311bin.tgz 407libXt.so.6.0 2.0-RELEASE/XFree86-3.1/XFree86-3.1-bin.tar.gz 408libXt.so.6.0 XFree86-3.1.1/X311bin.tgz 409.\" libX11.so.3 oldlibs 410.\" libXt.so.3 oldlibs 411.Ed 412.Pp 413The files called 414.Dq bindist.?? 415are tar-ed, gzipped and split, so you can extract contents by 416.Dq cat bindist.?? | tar zpxf - . 417.Pp 418Extract the files from these gzipped tarfiles in your 419.Pa /emul/freebsd 420directory (possibly omitting or afterwards removing files you don't 421need), and you are done. 422.Sh BUGS 423The information about 424.Fx 425distributions may become outdated. 426