<?xml version="1.0" encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/gentoo-freebsd.xml,v 1.9 2005/10/16 15:31:50 neysx Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/gentoo-freebsd.xml">
<title>A short guide to Gentoo/FreeBSD</title>

<author title="Author">
  <mail link="ignacio.arquelatour@gmail.com">Ignacio Arque-Latour</mail>
</author>
<author title="Author">
  <mail link="citizen428@gentoo.org">Michael Kohl</mail>
</author>
<author title="Author">
  <mail link="angusyoung@gentoo.org">Otavio R. Piske</mail>
</author>
<author title="Author">
  <mail link="ka0ttic@gentoo.org">Aaron Walker</mail>
</author>

<abstract>
This document gives some general information on FreeBSD, as well as
installation instructions for Gentoo/FreeBSD. It also includes some reference
for people interested in helping out with development.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
<license/>

<version>1.7</version>
<date>2005-10-16</date>

<chapter>
<title>Introduction to FreeBSD</title>
<section>
<title>What is FreeBSD?</title>
<body>

<p>
<uri link="http://www.freebsd.org/">FreeBSD</uri> is a free (<uri
link="http://www.freebsd.org/copyright/freebsd-license.html">license</uri>)
Unix-like operating system. Back in 1993 when development of <uri
link="http://www.386bsd.org/">386BSD</uri> stopped, two projects were born:
<uri link="http://www.netbsd.org/">NetBSD</uri>, commonly known to run on a
huge number of architetures, and FreeBSD which focuses mainly on the x86
platform. FreeBSD is renowned for its stability, performance and security, thus
being used from small to huge companies all over the world. FreeBSD's current
production release version is 5.4, which is also used as the foundation for the
Gentoo/FreeBSD project.
</p>

</body>
</section>
<section>
<title>What is Gentoo/FreeBSD?</title>
<body>

<p>
Gentoo/FreeBSD is an effort to provide a fully-capable FreeBSD operating system
with Gentoo's design sensibilities. The long-term goal of the Gentoo/BSD project
is to allow users to choose any combination of *BSD or Linux kernels, *BSD or
GNU libc, and *BSD or GNU userland tools.
</p>

</body>
</section>
<section>
<title>FreeBSD and Linux</title>
<body>

<p>
Users migrating from Linux to FreeBSD commonly consider the two operating
systems "almost the same". In fact, FreeBSD really shares a lot of similarities
with Linux distributions in general. Nevertheless, it has some key differences
that are worth noting:
</p>

<ul>
  <li>
    Contrary to Linux, which actually only refers to the kernel, FreeBSD is a
    complete operating system, consisting of a C library, userland tools and
    much more. This development approach makes the overall system very
    consistent.
  </li>
  <li>
    Contrary to the Linux kernel, FreeBSD development is not led by one person,
    but instead managed by a small group of people called the <uri
    link="http://www.freebsd.org/doc/en_US.ISO8859-1/articles/contributors/staff-core.html">Core
    Team</uri>.
  </li>
</ul>

<p>
Besides, FreeBSD also has some technical differences which set it apart
from Linux. Some of them are very important to know, even if you don't plan on
joining the Gentoo/FreeBSD development effort:
</p>

<ul>
  <li>
    To get run-time dynamic linking functions like <c>dlopen()</c>, programs do
    not need to be linked against libdl like on GNU/Linux. Instead they are
    linked against libc.
  </li>
  <li>
    FreeBSD doesn't have an official tool for kernel compilation, thus you'll
    have to resolve feature dependencies on your own.
  </li>
  <li>
    FreeBSD uses UFS/UFS-2 as its filesystems and has no official support for
    e.g. ReiserFS or XFS. However, there are projects for adding read-only
    support for these filesystems. Accessing ext2/ext3 partitions is already
    possible, but you cannot install your system on them.
  </li>
</ul>

</body>
</section>
</chapter>

<chapter>
<title>Installing Gentoo/FreeBSD</title>
<section>
<title>Installation instructions</title>
<body>

<p>
After this short introduction, it's about time to finally install
Gentoo/FreeBSD. Unfortunately, we currently lack our own installation media, so
you have to choose between two alternative installation methods. The first
would be to use an existing FreeBSD installation to partition your hard drive
and use it as a base for installing Gentoo/FreeBSD. Alternatively, you can also
use the excellent <uri link="http://www.freesbie.org/">FreeSBIE LiveCD</uri> as
an installation medium for Gentoo/FreeBSD.
</p>

<p>
Before you can begin with the installation, you have to setup a hard disk for
use with Gentoo/FreeBSD. This can either be done via <c>sysinstall</c>
(available from a current FreeBSD installation as well as from within FreeSBIE)
or by manually using the commands <c>fdisk</c>, <c>disklabel</c> and
<c>newfs</c>. If you have never set up a FreeBSD system before,
<c>sysinstall</c> may be the better option for you. If you face difficulties
while partitioning or formatting your hard disks, have a look at the great
<uri link="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/">FreeBSD
Handbook</uri> or hop onto <c>#gentoo-bsd</c> on the Freenode IRC server.
</p>

<p>
Once you're done setting up your disks, you have to create a mount point for
your Gentoo/FreeBSD installation and mount all the necessary partitions.
</p>

<pre caption="Creating a mount point and mounting partitions">
# <i>mkdir /mnt/gentoo</i>
<comment>(Replace X with the correct numbers for your hard disk.)</comment>
# <i>mount /dev/adXsXa /mnt/gentoo</i>
</pre>

<p>
Now that you have mounted the target partition, it is time to fetch and unpack
a stage3 tarball.
</p>

<pre caption="Obtaining and unpacking a stage3 tarball">
# <i>cd /mnt/gentoo/</i>
<comment>(Any other Gentoo mirror which includes the experimental/ directory will also work.)</comment>
# <i>wget http://gentoo.osuosl.org/experimental/x86/freebsd/stages/stage3-x86-fbsd-20051013.tar.bz2</i>
# <i>tar -jxvpf stage3-x86-fbsd-20051013.tar.bz2</i>
<comment>(You can delete the tarball with the following command if you want to.)</comment>
# <i>rm stage3-x86-fbsd-20051013.tar.bz2</i>
</pre>

<p>
Before chrooting into the newly-extracted stage, you first must obtain an up-to-date
copy of the Gentoo/FreeBSD overlay. The easiest way to achieve this is to to get our latest
snapshot which you than extract to <path>/mnt/gentoo/usr/local/portage</path>
</p>

<pre caption="Getting the Gentoo/FreeBSD Portage overlay">
# <i>cd /mnt/gentoo/usr/local/portage</i>
# <i>wget http://gentoo.osuosl.org/experimental/snapshots/portage-alt-overlay-latest.tar.bz2</i>
# <i>tar -xjf portage-alt-overlay-latest.tar.bz2</i>
</pre>

<p>
Alternatively, you can also use Subversion to check out the current version of
the overlay. If you are interested in this possibility, please refer to the
<uri link="/proj/en/gentoo-alt/overlay.xml">Gentoo/ALT overlay
documentation</uri>.
</p>

<p>
In order for your install to work, you need to mount the <path>/dev</path>
filesystem from the currently running system into the Gentoo/FreeBSD mount
point before proceeding with the chroot.
</p>

<pre caption="Mounting the /dev filesystem and chrooting">
# <i>mount -t devfs none /mnt/gentoo/dev/</i>
# <i>cp /etc/resolv.conf /mnt/gentoo/etc</i>
# <i>chroot /mnt/gentoo/ /bin/bash</i>
# <i>source /etc/profile</i>
</pre>

<p>
After you got hold of the Gentoo/FreeBSD overlay, it's time to link
<path>/etc/make.profile</path> to the correct profile and add get your
<path>/etc/make.conf</path> ready for Gentoo/FreeBSD.
</p>

<pre caption="Setting up the profile and editing /etc/make.conf">
# <i>ln -sf /usr/local/portage/portage-alt-overlay/profiles/default-bsd/fbsd/5.4/x86/ /etc/make.profile</i>
<comment>(FreeBSD's standard editor is ee, which is used to edit /etc/make.conf)</comment>
# <i>ee /etc/make.conf</i>
<comment>(Please make sure you add at least the following entries:)</comment>
CHOST="i686-gentoo-freebsd5.4"
ACCEPT_KEYWORDS="~x86-fbsd ~x86"
FEATURES="-sandbox collision-protect"
PORTDIR_OVERLAY="/usr/local/portage/portage-alt-overlay"
</pre>

<p>
Now, you have to obtain a copy of the main Gentoo Portage tree, which depending
on your connection might take quite a while.
</p>

<pre caption="Obtaining the Portage tree">
# <i>emerge --sync</i>
<comment>(It's also possible to retrieve the Portage tree in another way:)</comment>
# <i>cd /</i>
# <i>wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2</i>
# <i>tar -xjf portage-latest.tar.bz2 -C /usr/</i>
# <i>emerge --metadata</i>
</pre>

<p>
Congratulations, by the time you have reached this step you should have a
running Gentoo/FreeBSD system! If you want, you can now rebuild the system's
core packages.
</p>

<pre caption="Rebuilding the FreeBSD core packages">
# <i>emerge -e system</i>
</pre>

<impo>
Please make absolutely sure you add your new Gentoo/FreeBSD installation to the
configuration of your bootloader, otherwise you won't be able to boot your newly
installed system! If you don't have another bootloader installed, you should use 
<c>boot0</c>, as it is currently the only one supported by FreeBSD.
</impo>

<pre caption="Installing and setting up boot0">
# <i>emerge boot0</i>
<comment>(Leave the chroot environment)</comment>
# <i>exit</i>
<comment>(Issued from outside the chroot)</comment>
# <i>fdisk -b -B /mnt/gentoo/boot/boot0 /dev/adX</i>
# <i>chroot /mnt/gentoo /bin/bash</i>
# <i>disklabel -B adXsY</i>
</pre>

<p>
If you need additonal information on setting up <c>boot0</c>, please consult 
<uri link="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/boot.html">
chapter 12</uri> of the FreeBSD handbook.
</p>

<p>
When you did <c>emerge system</c>, the sources for the FreeBSD kernel got 
installed to <path>/usr/src/sys</path>. Configuring and compiling a custom
kernel is really different from compiling Linux, so if you are not familiar with
the process we encourage you to have a look at <uri
link="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig.html">
chapter 8</uri> of the FreeBSD handbook. 
</p>

<p>
Please note that currently only the "Traditional" way of building the kernel is 
supported on Gentoo/FreeBSD! Also note that <c>make install</c> will probably
ask you for a <path>/boot/device.hints</path> file. A default version can be
found in the <path>conf</path> subdirectory of the <c>GENERIC</c> configuration
and is called <path>GENERIC.hints</path>
</p>

</body>
</section>
</chapter>

<chapter>
<title>Developing for Gentoo/FreeBSD</title>
<section>
<title>How to help</title>
<body>

<p>
There are many things you could help with, depending on your skill level and
spare time:
</p>

<ul>
  <li>
    We need GCC and binutils hackers who are able to port FreeBSD's patches to
    the original versions of these tools provided by our main Portage tree.
  </li>
  <li>
    Working on current ebuilds: this means working closely with ebuild maintainers 
    in order to create patches or modify ebuilds in a way that can be accepted 
    into the main tree.
  </li>
  <li>
    Security: if you are into security, we need you! Although security
    advisories from the FreeBSD project are tracked and fixed, we can always
    use help in this area.
  </li>
  <li>
    Contacts: we need people who can get in touch with FreeBSD developers to
    maintain contacts between us and the original project to exchange patches
    and discuss various problems and their solutions. Note that this should
    never involve any kind of spamming of mailing lists or IRC channels.
  </li>
  <li>
    Testing: the more people are actively using Gentoo/FreeBSD, the more bugs
    will be discovered, which helps us improving the quality of the port. If
    you are good at describing bugs or problems, we definitely want to hear
    from you.
  </li>
  <li>
    Other areas where we need help include: system ebuilds, baselayout,
    creation of installation CDs, documentation, kernel hacking.
  </li>
</ul>

</body>
</section>
<section>
<title>Building the system and dealing with issues</title>
<body>

<p>
Although Linux and FreeBSD both are Unix-like operating systems, there are some
important differences you have to know about if you want to contribute to our
development effort:
</p>

<ul>
  <li>
    FreeBSD doesn't use the GNU autotools (autoconf, automake, autoheader).
    Instead, it uses its own implementation of <c>make</c>, putting
    configuration options in external files and some .mk files that are
    included with each Makefile. Although a lot of work has been put into
    those .mk files, it is not hard to find some installations failing due to
    a missing <c>${INSTALL}&nbsp;-d</c> somewhere. The easy way to deal with
    this kind of problem is to read the Makefile to find the accompanying .mk
    file, then open that file and try to figure out which part failed (this is
    not really hard once you figure out where in the installation process it
    stopped).
  </li>
  <li>
    Besides, due to the fact that FreeBSD is a complete operating system, you
    won't find things like a FreeBSD kernel tarball for download on a web site.
    The system is meant to be concise, thus whenever you start making an ebuild
    for something that uses system sources, you are very likely to run into
    problems when it tries to access non-existent files or directories. This
    generally occurs when a Makefile points to <path>${.CURDIR}/../sys</path>,
    or when a Makefile has a source dependency on another system package. There
    is no default rule on dealing with such issues, but generally one of the
    following procedures helps:
    <ul>
      <li>
        If the ebuild is trying to access kernel sources, patch it to point to
        <path>/usr/src/sys</path>
      </li>
      <li>
        If it's trying to access some other source that is provided by the
        system, it's easier to add it to <c>$SRC_URI</c> and unpack it to
        <c>$WORKDIR</c>
      </li>
    </ul>
  </li>
  <li>
    In order to maintain a concise buildsystem, we have several tarballs which
    are grouped by their functionality. This means that system libraries can be
    found in the freebsd-lib tarball, which contains the sources you would
    usually find in /usr/src/lib. On the other hand, freebsd-usrsbin contains
    <path>/usr/sbin/*</path> tools and consists of sources from
    <path>/usr/src/usr.sbin</path>.
  </li>
</ul>

</body>
</section>
<section>
<title>Known issues</title>
<body>

<p>
At the moment, there are still quite a lot of known issues. Here are the ones
really worth noting:
</p>

<ul>
  <li>
    Some init scripts depend on the clock service which we don't provide right
    now. You can just remove it from the dependencies of the script and report
    that on our <uri link="http://bugs.gentoo.org/">bugzilla</uri>. Please
    remember to use the "Gentoo BSD" product for your submission.
  </li>
  <li>glib and gnome in general need a lot of fixes to be backported.</li>
</ul>

</body>
</section>
</chapter>

<chapter>
<title>Contact</title>
<section>
<body>

<p>
A list of Gentoo/FreeBSD developers can be found at the <uri
link="/proj/en/gentoo-alt/bsd/fbsd/">project page</uri>. Other ways to contact
Gentoo/FreeBSD developers include our IRC Channel <c>#gentoo-bsd</c> on
Freenode, as well as the <uri link="/main/en/lists.xml">gentoo-bsd mailing
list</uri>.
</p>

</body>
</section>
</chapter>
</guide>
