The Linux+FreeBSD mini-HOWTO <author>Niels Kristian Bech Jensen, <tt/nkbj@image.dk/ <date>v1.1, 3 October 1997 <abstract> This document describes how to use Linux and FreeBSD on the same system. It introduces FreeBSD and discuss how the two operating systems can interact, e.g. by sharing swap space. You should probably have some experience with Linux and hard drive partitioning (<tt/fdisk/) before you read this document. Do not hesitate to mail me if you have comments, questions or suggestions about this document. I would also like to hear from people who have experience using Linux together with NetBSD or OpenBSD. </abstract> <toc> <sect>What is FreeBSD? <p> FreeBSD is a free Unix-like operating system much like Linux. The main difference is that, while the Linux kernel has been written from scratch, FreeBSD is based on the freely redistributable parts of 4.4BSD (Berkeley Software Distribution) known as 4.4BSD-lite. FreeBSD runs only on the Intel PC platform (i386 and higher); a port to the DEC Alpha platform is being discussed at the moment. Hardware requirements for FreeBSD are much like those for Linux. The development of FreeBSD is more ``closed'' than the Linux development. A core team of developers makes the key decisions concerning the project. Big changes are discussed in advance on the mailing lists. The FreeBSD project has two development trees (just like Linux): <em/``-current''/ and <em/``-stable''/. ``-current'' is where the development of new features is going on, while development of the ``-stable'' releases mainly are bug fixes. FreeBSD can be used and (re-)distributed freely just as Linux. Most parts of the system are released under the BSD copyright; the rest is under the GNU GPL or the GNU LGPL. You can find more information about FreeBSD (and download the whole system) at <url url="http://www.freebsd.org/" name="FreeBSD Inc.">. The newest ``-stable'' releases and snapshots of the ``-current'' development code are sold on CDROMs by <url url="http://www.cdrom.com/" name="Walnut Creek CDROM"> (their web- and ftp-servers are running FreeBSD.) <sect>The FreeBSD way of labelling hard drives <p> Linux and FreeBSD label hard drives and partitions after two differents schemes. This section explains the main differences between the two schemes. <sect1>FreeBSD ``slices'' and ``partitions'' <p> FreeBSD needs only one entry in the primary partition table on your hard drive. This primary partition is called a <em/``slice''/ in FreeBSD terminology. It then uses the program <tt/disklabel/ to make several logical partitions in this primary partition. These logical partitions are called <em/``partitions''/ in FreeBSD terminology. This concept is similar to the way Linux (and DOS) handles logical partitions in an extended partition. Note that the Linux <tt/fdisk/ program can't display the partitions in a FreeBSD slice, the output is something like this (<tt>/dev/hda4</tt> is the FreeBSD slice): <tscreen><verb> hafnium:~# fdisk /dev/hda Command (m for help): p Disk /dev/hda: 64 heads, 63 sectors, 621 cylinders Units = cylinders of 4032 * 512 bytes Device Boot Begin Start End Blocks Id System /dev/hda1 * 1 1 27 54400+ 83 Linux native /dev/hda2 28 28 375 701568 83 Linux native /dev/hda3 376 376 403 56448 83 Linux native /dev/hda4 404 404 621 439488 a5 BSD/386 Command (m for help): q hafnium:~# </verb></tscreen> <sect1>Drive and partition labelling in Linux and FreeBSD <p> The hard drives are labelled in the following way in Linux and FreeBSD: <tscreen><verb> Linux FreeBSD First IDE drive /dev/hda /dev/wd0 Second IDE drive /dev/hdb /dev/wd1 First SCSI drive /dev/sda /dev/sd0 Second SCSI drive /dev/sdb /dev/sd1 </verb></tscreen> The partitions (FreeBSD slices) on a drive are labelled in the following way (<tt>/dev/hda</tt> is used as an example): <tscreen><verb> Linux FreeBSD First primary partition /dev/hda1 /dev/wd0s1 Second primary partition /dev/hda2 /dev/wd0s2 Third primary partition /dev/hda3 /dev/wd0s3 Fourth primary partition /dev/hda4 /dev/wd0s4 </verb></tscreen> The partitions in a FreeBSD slice is labelled in the following way (<tt>/dev/hda4</tt> is the FreeBSD slice in the example): <tscreen><verb> Linux label FreeBSD label Default FreeBSD mount point /dev/hda5 /dev/wd0s4a / /dev/hda6 /dev/wd0s4b swap /dev/hda7 /dev/wd0s4e /var /dev/hda8 /dev/wd0s4f /usr </verb></tscreen> If you have installed FreeBSD in the <tt>/dev/sdb3</tt> slice, and <tt>/dev/sdb2</tt> is a Linux extended partition containing two logical partitions (<tt>/dev/sdb5</tt> and <tt>/dev/sdb6</tt>), the previous example would look like this: <tscreen><verb> Linux label FreeBSD label Default FreeBSD mount point /dev/sdb7 /dev/sd1s3a / /dev/sdb8 /dev/sd1s3b swap /dev/sdb9 /dev/sd1s3e /var /dev/sdb10 /dev/sd1s3f /usr </verb></tscreen> <sect>Sharing swap space between Linux and FreeBSD <p> This section describes how I got Linux and FreeBSD to share a swap partition. There may be other ways to get the same result. This is based on Red Hat Linux release 4.1 and 4.2 (Linux kernel 2.0.29 and 2.0.30) and FreeBSD 2.2.2. You can install FreeBSD before Linux if you want to, just pay attention to the order of the partitions in the FreeBSD slice. <sect1>Installing and preparing Linux<label id="installlinux"> <p> The first step is to install Linux as normal. You have to leave space for the FreeBSD slice at you hard drive. You don't have to make a Linux swap partition, but if you want one, put it in the space you want to allocate for FreeBSD. That way you can delete the Linux swap partition later and use the space for FreeBSD. When you have installed Linux you have to build a new kernel. Read <bf/The Linux Kernel HOWTO/ if this is new to you. You <em/have/ to include <bf/UFS file system/ support and <bf/BSD disklabel (FreeBSD partition tables)/ support. <tscreen><verb> UFS filesystem support (read only) (CONFIG_UFS_FS) [N/y/m/?] y BSD disklabel (FreeBSD partition tables) support (CONFIG_BSD_DISKLABEL) [N/y/?] (NEW) y </verb></tscreen> Install the new kernel and reboot. Remove any line including the word <em/swap/ from your <tt>/etc/fstab</tt> file if you have made a Linux swap partition. <em/Make sure you have a working Linux boot disk with the new kernel./ You are now ready to install FreeBSD. <sect1>Installing FreeBSD <p> Install FreeBSD as described in the FreeBSD documentation. Remove the Linux swap partition is you have made one (you can use the FreeBSD <tt/fdisk/ program.) Pay attention to the order of the partitions in the FreeBSD slice. If you use the default labelling the second partition will be the swap partition. Complete the installation of FreeBSD and reboot into Linux <em/using the new Linux boot disk/. <sect1>Setting up the FreeBSD swap partition in Linux <p> Run <tt/dmesg/ when you have booted into Linux. In the output you should see something like this: <tscreen><verb> Partition check: hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 hda8 > </verb></tscreen> This means that <tt>/dev/hda4</tt> is your FreeBSD slice, while <tt>/dev/hda5</tt>, <tt>/dev/hda6</tt>, <tt>/dev/hda7</tt> and <tt>/dev/hda8</tt> are the FreeBSD partitions. If your swap partition is the second partition in the slice, it will be <tt>/dev/hda6</tt>. You have to put the following line into your <tt>/etc/fstab</tt> file to enable the swap partition: <tscreen><verb> /dev/hda6 none swap sw 0 0 </verb></tscreen> While FreeBSD can use any type of partition as swap space, Linux needs a special signature in the swap partition. This signature is made by <tt/mkswap/. FreeBSD ruins this signature when it uses the shared swap partition, so you will have to run <tt/mkswap/ each time you boot into Linux. To do this automagically you have to find the script that runs <tt/swapon/ at boot time. In Red Hat Linux it is <tt>/etc/rc.d/rc.sysinit</tt>. Put the following line into that file just <em/before/ <tt/swapon -a/: <tscreen><verb> awk -- '/swap/ && ($1 !~ /#/) { system("mkswap "$1"") }' /etc/fstab </verb></tscreen> This will run <tt/mkswap/ on any swap partitions in <tt>/etc/fstab</tt> every time you boot except if they are commented out (having ``#'' as the first character in the line.) Run <tt/free/ to check out the size of the swap space when you have rebooted into Linux. You should also reboot into FreeBSD to make sure everything works as expected. If it does not, you have probably used the wrong partition as swap partition. The only solution to that problem is to reinstall FreeBSD and try again. Experience is a great teacher. :-) <sect>Booting FreeBSD using LILO <p> You can easily boot FreeBSD with LILO. Do not install the FreeBSD boot loader (<tt/Booteasy/) if you want to use LILO. Append the following lines to your <tt>/etc/lilo.conf</tt> file and run <tt/lilo/ (the FreeBSD slice being <tt>/dev/hda4</tt>): <tscreen><verb> other=/dev/hda4 table=/dev/hda label=FreeBSD </verb></tscreen> If you have installed FreeBSD on the second SCSI drive, use something like this (the FreeBSD slice being <tt>/dev/sdb2</tt>): <tscreen><verb> other=/dev/sdb2 table=/dev/sdb loader=/boot/chain.b label=FreeBSD </verb></tscreen> <sect>Mounting file systems <sect1>Mounting UFS file systems under Linux <p> Unfortunately the UFS support in the Linux kernel is broken. When you try to mount a UFS file system, you just get some error messages (the file system actually gets mounted, but you cannot read anything from it.) However, there is a new (ALPHA) version of the UFS file system support for Linux 2.0.xx kernels on <url url="ftp://sunsite.unc.edu/pub/Linux/ALPHA/ufs/" name="SunSite">. It is called <bf/U2FS/ and the current version is <tt/u2fs-0.4.3.tar.gz/. <bf/U2FS/ is installed in the following way (assuming <tt/u2fs-0.4.3.tar.gz/ is stored in <tt>/usr/src</tt>): <tscreen><verb> cd /usr/src tar xvzf u2fs-0.4.3.tar.gz patch -p0 -E < u2fs-0.4.3.patch </verb></tscreen> Now you have to build a new kernel with support for the <bf/U2FS file system/ and <bf/BSD disklabel/. See section <ref id="installlinux" name="Installing and preparing Linux"> for more information on this. You can leave out <bf/UFS file system/ support from the kernel when you use <bf/U2FS/. When you have installed the new kernel, you can mount your UFS file systems (all the partitions in the FreeBSD slice except the swap partition) with a command like this: <tscreen><verb> mount -t u2fs /dev/hda8 /mnt </verb></tscreen> The UFS support is read-only. That is; you can read from the UFS file systems but you cannot write to them. <sect1>Mounting ext2fs file systems under FreeBSD<label id="ext2fs"> <p> To mount ext2fs file systems under FreeBSD, you first have to build a new kernel with ext2fs support. Read the FreeBSD documentation to learn how to do that. Put the line <tscreen><verb> options "EXT2FS" </verb></tscreen> in your kernel configuration file for the new kernel. When you have booted with the new kernel, you can mount an ext2fs file system by giving a command like: <tscreen><verb> mount -t ext2fs /dev/wd0s3 /mnt </verb></tscreen> Due to a bug in FreeBSD you will have to unmount all ext2fs file systems <em/before/ you shut down FreeBSD. If you shut down FreeBSD with an ext2fs file system mounted, FreeBSD cannot sync the UFS file systems. This results in <tt/fsck/ being run the next time FreeBSD is booted. This bug is reported to have been fixed in the ``-current'' development tree. <sect>Running Linux binaries under FreeBSD <p> FreeBSD has the ability to run Linux binaries, both in a.out and ELF formats. To do this you have to take the following three steps: <enum> <item>You have to enable Linux compatibility. To do this (in FreeBSD 2.2.2 --- details may vary in other versions) you have to edit your <tt>/etc/rc.conf</tt> file and change <tscreen><verb> linux_enable="NO" </verb></tscreen> to <tscreen><verb> linux_enable="YES" </verb></tscreen> <item>You have to install the Linux shared libraries. They are included in FreeBSD 2.2.2 as the package <tt/linux_lib-2.4.tgz/ (a newer version might be out now.) Run the command <tscreen><verb> pkg_add <path_to_package>/linux_lib-2.4.tgz </verb></tscreen> to install the package. <path_to_package> is the directory where the package is stored. <item>Install the Linux program(s) you want to run. The program(s) can be installed on either UFS or ext2fs file systems. See section <ref id="ext2fs" name="Mounting ext2fs file systems under FreeBSD"> for more information about using ext2fs file systems under FreeBSD. </enum> I have successfully run the Linux versions of Applixware 4.3 and Netscape 3.01 (both ELF format) under FreeBSD 2.2.2 using this method (yes, I know there is a native FreeBSD version of Netscape 4.) Read the FreeBSD documentation for more information on this topic. <sect>References and other documents of interest <p> The newest version of this mini-HOWTO can be found at <url url="http://www.image.dk/˜nkbj/" name="my homepage"> in several formats (including SGML and PostScript.) The document has been translated into Japanese by Mr. Teruyoshi Fujiwara as part of <url url="ftp://jf.linux.or.jp/pub/JF/other-formats/" name="the JF project">. The FreeBSD Handbook and The FreeBSD FAQ are distributed with FreeBSD. They can also be found at <url url="http://www.freebsd.org/" name="FreeBSD Inc.">. This site has a lot of other information about FreeBSD too. The Linux Kernel HOWTO is released as part of <url url="http://sunsite.unc.edu/LDP/" name="The Linux Documentation Project">. <sect>Acknowledgments and Copyright <p> Thanks to the members of the <url url="http://hotel.prosa.dk/bsd-dk/" name="*BSD user group in Denmark"> for answering the questions of a FreeBSD newbie and to Mr. Takeshi Okazaki for bringing the existence of <bf/U2FS/ to my attention. This document is copyrighted by Niels Kristian Bech Jensen, <tt/nkbj@image.dk/. It is distributed as part of <url url="http://sunsite.unc.edu/LDP/" name="The Linux Documentation Project"> under the terms described below. Linux (mini-)HOWTO documents may be reproduced and distributed in whole or in part, in any medium physical or electronic, as long as this copyright notice is retained on all copies. Commercial redistribution and/or printing is allowed and encouraged; however, the author would like to be notified of any such activities. All translations, derivative works, or aggregate works incorporating any Linux (mini-)HOWTO documents must be covered under this copyright notice. That is, you may not produce a derivative work from a (mini-)HOWTO and impose additional restrictions on its distribution. Exceptions to these rules may be granted under certain conditions; please contact the Linux HOWTO coordinator at the address given below. If you have questions, please contact Greg Hankins, the Linux HOWTO coordinator, at <tt/gregh@sunsite.unc.edu/ via email. <sect1>Disclaimer <p> Although the information given in this document is believed to be correct, the authors will accept no liability for the content of this document. Use the tips and examples given herein at your own risk. </article>