FreeBSD

Build from source

Introduction#

Examples below are not necessarily in the correct order. See the Remarks section below for more information on the whole process.

Remarks#

Overview of the whole process

  1. Download the latest source code.
  2. Configure the kernel.
  3. Build the world and the kernel.
  4. Configure the root filesystem of your new FreeBSD.
  5. Install the world and the kernel.

Get the number of processors

An easy way to speed up the process of building and installing the new system is to use more processors to increase the computational power.

To find out what’s the number of the processors you have to speed up the process:

sysctl hw.ncpu

For example:

hw.ncpu: 1

Let’s set the $NUMBER_OF_PROCESSORS environmental variable then:

export $NUMBER_OF_PROCESSORS=$(sysctl hw.ncpu | tr -d 'a-z.: ')

Download the latest source code

SVN

FreeBSD project use SVN as default SCM. Source could be download with svnlite software.

Get Current

cd /usr/src
svnlite checkout https://svn.freebsd.org/base/head .

Get Releases

cd /usr/src
svnlite checkout https://web.freebsd.org/base/release/11.0.0 .

Tarball (http & ftp)

You can also get source from frozen tarball with fetch command

http

cd /tmp
fetch https://ftp.freebsd.org/pub/FreeBSD/releases/amd64/11.0-RELEASE/src.txz
cd /usr/src
tar xJvf /tmp/src.txz

ftp

cd /tmp
fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/11.0-RELEASE/src.txz
cd /usr/src
tar xJvf /tmp/src.txz

Git

GitHub

git clone https://github.com/freebsd/freebsd freebsdsrc

Configure the kernel

  1. Go to the directory with the source code:

    cd freebsdsrc
  2. Go to the directory with the kernel’s configuration code:

    # If your system is 32-bit.
    cd sys/i386/conf/
    # If your system is 64-bit.
    cd sys/amd64/conf/
  3. Get a copy of the GENERIC kernel (let’s call it MODEDKERNEL). It will be

the base of your customisations.

cp GENERIC MODEDKERNEL
  1. Modify the MODEDKERNEL file at your will.

Build the world and the kernel

Build the world

Go to the freebsdsrc/ (the root directory of the FreeBSD source tree you’ve already downloaded) and build the world:

sudo make -j${NUMBER_OF_PROCESSORS} buildworld KERNCONF=MODEDKERNEL -DNO_CLEAN

Estimated time

  • Estimated time on Hasee Q540S running on a one processor: 8 hours.
  • Estimated time on Dell L702X running on 8 processors: 98 minutes.

Build the kernel

To build the kernel run:

sudo make -j${NUMBER_OF_PROCCESORS} buildkernel KERNCONF=UFFIE -DNO_CLEAN

Estimated time

  • Estimated time on Hasee Q540S running on a one processor: 2 hours.
  • Estimated time on Dell L702X running on 8 processors: 19 minutes.

Configure the root filesystem of your new FreeBSD

Let’s configure the destination directory for the root filesystem of your new FreeBSD (for example /usr/home/beastie/MODEDKERNEL).

  1. Add the following lines to /etc/src.conf to set it up:

    .if ${KERNCONF} == "MODEDKERNEL"
        DESTDIR?=/usr/home/beastie/MODEDKERNEL
        MODULES_OVERRIDE=md ufs
    .endif

    Remember to use spaces not tabs if you wish to indent the code.

  2. Create the root file system now:

    • Make distribution directories:

      sudo make distrib-dirs KERNCONF=MODEDKERNEL

      Estimated time on Hasee Q540S: a few seconds.

    • Make the distribution:

      sudo make distribution KERNCONF=UFFIE

      Estimated time on Hasee Q540S: 3 minutes.

Install the world and the kernel

Install the world

sudo make installworld KERNCONF=MODEDKERNEL

Estimated time on Hasee Q540S: 5 minutes.

Install the kernel

sudo make installkernel KERNCONF=MODEDKERNEL

Estimated time on Hasee Q540S: a few seconds.


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow