File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_build_netbsd-current.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Sun Nov 20 20:55:21 2011 UTC (2 years, 4 months ago) by mspo
Branches: MAIN
CVS tags: HEAD
import all of the how-to articles from the pkgsrc.se wiki

Thanks to the Autobuild-System, you can easily build a new Release from the NetBSD CVS sources. I'll show you, how to build a release, sets and a bootable installation CD-ROM for i386, step by step. For this, you need a running NetBSD System and a working Internet Connection.
#Contents

[[!toc]]

#Disk space requirements

You will need a minimum of 5.1 GB of disk space to build a whole release. You need currently 1.2 GB for the sources src and 579 MB for xsrc. About 2.4 GB will reside in the obj directory after building a release.
#Short way for impatient
<pre><code>
# fetch source:
cd /usr; cvs -z3 -d anoncvs@anoncvs.se.netbsd.org:/cvsroot co -P src
# everything goes into this directory
mkdir /usr/obj
# build tools (to build everything else), custom kernel, binary sets
cd /usr/src; ./build.sh -O /usr/obj -U -j 8 tools kernel=H4KK1T modules distribution sets
# install kernel:
cd /usr/obj/sys/compile/arch/*/compile/H4KK1T; su root -c 'make install'
# test kernel:
su root -c 'shutdown -r now'
# update userland:
cd /usr/src; ./build.sh -O /usr/obj install=/
# follow printed instructions about "postinstall"

# build CD image (omit "tools" if built already):
cd /usr/src; ./build.sh -O /usr/obj -U -j 8 tools release iso-image
</code></pre>

#Obtaining the sources via CVS

Create the directories src, xsrc and objdir as root in /usr

    # cd /usr
    # mkdir src xsrc objdir 

We also create the following directories in /usr: tooldir, releasedir, destdir. We do this, because we want the src directory to stay clean and not polluted by the build process. We will pass options flags to build.sh, to separate the directories.

    # mkdir tooldir releasedir destdir

Change the owner of the directories:

    # chown john src/ xsrc/ objdir/ tooldir/ releasedir/ destdir/

The following steps from now on can be done as a non-root user:

    # logout
    $

Set the environment variable CVSROOT: (For that, please choose a [Mirror](http://www.de.netbsd.org/mirrors/#anoncvs) close to you)

csh users:

    % setenv CVSROOT anoncvs@anoncvs.se.NetBSD.org:/cvsroot

Bourne compatible shell (sh, ksh, zsh, bash...) Users:

    $ export CVSROOT=anoncvs@anoncvs.se.NetBSD.org:/cvsroot

Set the environment variable CVS_RSH:

    $ export CVS_RSH=ssh

The src directory currently needs about 1500 MB disk space and the xsrc directory currently needs about 579 MB of disk space.
Now check out the current sources, like this:

    $ cvs checkout -PA src

If you want to use Xorg from pkgsrc you can skip the next step.

    $ cvs checkout -PA xsrc

Or you can check out a certain release, by passing -r

    $ cvs checkout -rnetbsd-5-0 -PA src
    $ cvs checkout -rnetbsd-5-0 -PA xsrc

#Building the toolchain

The toolchain contains the software that is needed to build NetBSD, like the GNU C-Compiler and other tools. This way, it is ensured that NetBSD can build itself on almost any Unix™. You can omit this step, if you want to build a new release, because a release always includes building the tools.
<pre><code>
$ cd /usr/src
$ ./build.sh -T ../tooldir -D ../destdir -R ../releasedir -O ../objdir -U -j2 tools 

        build.sh started: Sat Jan 22 21:34:56 CET 2005
        No /usr/tools/bin/nbmake, needs building.
        Bootstrapping nbmake
        MACHINE:          i386
        MACHINE_ARCH:     i386
        TOOLDIR path:     /usr/tooldir
        DESTDIR path:     /usr/destdir
        RELEASEDIR path:  /usr/releasedir
        Created /usr/tools/bin/nbmake
        makewrapper:      /usr/tools/bin/nbmake-i386
        Updated /usr/src/obj/tooldir/bin/nbmake-i386
        Tools built to /usr/src/obj/tooldir
        build.sh started: Sat Jan 22 21:34:56 CET 2005
        build.sh ended:   Sat Jan 22 21:41:26 CET 2005
</code></pre>
#Building the release

Variables to pass to build.sh can be found in [src/share/mk/bsd.README](http://cvsweb.de.netbsd.org/cgi-bin/cvsweb.cgi/src/share/mk/bsd.README?rev=1.165.2.3;content-type=text%2Fx-cvsweb-markup).

In this example
We are building as a user (non-root): -U
We are building the X11R6 sources (Xservers, this is XFree 4.5.0 not Xorg): -x
We are using separate directories: -T, -D, -R, -O, -X
We are removing contents of tooldir and destdir before building: -r
We are using -j2 because we have a multiprocessor system

We are building a release: release

    $ ./build.sh -T ../tooldir -D ../destdir -R ../releasedir -O ../objdir -X ../xsrc -U -x -j2 -r release 

This process takes at least two hours on an high-end server, and usually much longer, depending on your computing power.
<pre><code>
        build.sh started: Sat Jan 22 21:50:47 CET 2005
        No nonexistent/bin/nbmake, needs building.
        Bootstrapping nbmake
        MACHINE:          i386
        MACHINE_ARCH:     i386
        TOOLDIR path:     /usr/src/tooldir
        DESTDIR path:     /usr/src/destdir
        RELEASEDIR path:  /usr/src/releasedir
        Created /usr/src/tooldir/bin/nbmake
        makewrapper:      /usr/src/tooldir/bin/nbmake-i386
        Updated /usr/src/tooldir/bin/nbmake-i386
        Successful make release
        build.sh started: Sat Jan 22 21:50:47 CET 2005
        build.sh ended:   Sun Jan 23 01:20:43 CET 2005
</code></pre>
If you are using Xorg via pkgsrc (recommended), you can skip building the Xserver (-x).

If you have a multiprocessor system, add -j. The number of jobs should be equal to your number of CPU's/cores. Don't use -j on single CPU systems.

If your build fails, because of insufficient space on install flopies, you might find this useful: [[How to build install sets, when you can't build install floppies]]
#Creating an ISO-Image

to create an iso-image just add the option iso-image

    $ ./build.sh <other options> -U -x -r release iso-image

the resulting iso image will reside in relasedir/platform/installation/cdrom/

This option will create an iso-image only on platforms that are bootable from such a media.
#Burning the image

If you have a CD/DVD-Writer, you can burn the iso image to a CD. For this task you need to install cdrecord, which is part of sysutils/cdrtools.

    # cdrecord -dev=/dev/rcd0d -data -pad -v NetBSD-install.iso

#Building current faster

In case you don't need whole a release or a bootable iso image, the fastest way to build current is to build new tools, distribution, followed by sets and a kernel (custom or GENERIC). I recommend to build a custom kernel that fits your needs.

$ ./build.sh <your options> -U tools distribution sets kernel=MYKERNEL

Additional Information

* [cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-current) manpage
* [Tracking NetBSD-current](http://www.netbsd.org/docs/current/)

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb