File:  [NetBSD Developer Wiki] / wikisrc / guide / fetch.mdwn
Revision 1.3: download - view: text, annotated - select for diffs
Tue Mar 5 23:33:53 2013 UTC (13 months, 1 week ago) by jdf
Branches: MAIN
CVS tags: HEAD
Cosmetics (mainly removing trailing whitespaces).

# Obtaining the sources

To read the NetBSD sources from your local disk or to build the system or parts
of it, you need to download the NetBSD sources. This chapter explains how to get
the NetBSD source using a number of different ways, although the preferred one
is to get the tarballs and then update via
[cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-5.0.1+i386).

## Preparing directories

Kernel and userland sources are usually placed in `/usr/src`. This directory is
not present by default in the NetBSD installation and you will need to create it
first. As it is in a system directory, you will need root access to create the
directory and make sure your normal user account can write to it. For
demonstration purposes, it is assumed that the non-root login is `carlo`.
Please replace it with a valid login name on your system:

    $ su
    Password:
    # mkdir /usr/src
    # chown <carlo> /usr/src

Also, if you want X11R6 sources, you can prepare `/usr/xsrc`:

    # mkdir /usr/xsrc
    # chown <carlo> /usr/xsrc

*Note*: Please note that for the subsequent steps, root access is neither needed
nor recommended, so this preparation step should be done first. All CVS
operations can (and should) be done as normal user and you don't need root
privileges any more:

    # exit
    $

## Terminology

**Before starting to fetch or download the required files, you may want to know
the definitions of *Formal releases*, *Maintenance branches* and other related
terms**. That information is available under the [NetBSD release glossary and
graphs](http://www.NetBSD.org/releases/release-map.html).

## Downloading tarballs

It is sometimes faster to download a tarball and then continue updating with
[cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-5.0.1+i386). You can
download tarballs (see
[tar(1)](http://netbsd.gw.com/cgi-bin/man-cgi?tar+1+NetBSD-5.0.1+i386)) from
ftp.NetBSD.org (or any other mirror) for a number of releases or branches.

The only drawback is that the tarballs are updated less often. Normally, every
three days.

Also, please note that these tarballs include the `CVS` directories, so you can
download them and then update your source tree using
[cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-5.0.1+i386), as
explained in the CVS section.

### Downloading sources for a NetBSD release

The tarball files for the sources of a specific release are available under
`/pub/NetBSD/NetBSD-<RELEASE-NUMBER>/source/sets/`
on ftp.NetBSD.org (or a mirror), where `<RELEASE-NUMBER>` is the release you
want to fetch (for example, `4.0`).

To fetch the sources of a NetBSD release using tarballs, simply do:

    $ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-4.0/source/sets/
    Trying 2001:4f8:4:7:2e0:81ff:fe21:6563...
    Connected to ftp.NetBSD.org.
    220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20070809) ready.
    331 Guest login ok, type your name as password.
    [...]
    250 CWD command successful.
    250 CWD command successful.
    250 CWD command successful.
    ftp> mget *.tgz
    local: gnusrc.tgz remote: gnusrc.tgz
    229 Entering Extended Passive Mode (|||58302|)
    150 Opening BINARY mode data connection for 'gnusrc.tgz' (79233899 bytes).
    [...]
    ftp> quit
    221-
        Data traffic for this session was 232797304 bytes in 5 files.
        Total traffic for this session was 232803039 bytes in 6 transfers.
    221 Thank you for using the FTP service on ftp.NetBSD.org.

You should now have 5 files:

    $ ls *.tgz
    gnusrc.tgz      sharesrc.tgz    src.tgz         syssrc.tgz      xsrc.tgz

You now must extract them all:

    $ foreach file (*.tgz)
    ?    tar -xzf $file -C /usr/src
    ? end

### Downloading sources for a NetBSD stable branch

    $ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-release-4-0/tar_files/src/
    Trying 2001:4f8:4:7:2e0:81ff:fe21:6563...
    Connected to ftp.NetBSD.org.
    220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20070809) ready.
    331 Guest login ok, type your name as password.
    [...]
    250 CWD command successful.
    250 CWD command successful.
    250 CWD command successful.
    250 CWD command successful.
    ftp> mget *.tar.gz
    local: bin.tar.gz remote: bin.tar.gz
    229 Entering Extended Passive Mode (|||56011|)
    150 Opening BINARY mode data connection for 'bin.tar.gz' (914202 bytes).
    [...]
    ftp> quit
    221-
        Data traffic for this session was 149221420 bytes in 22 files.
        Total traffic for this session was 149231539 bytes in 23 transfers.
    221 Thank you for using the FTP service on ftp.NetBSD.org.

You should now have 22 files:

    $ ls *.tar.gz
    bin.tar.gz          doc.tar.gz          libexec.tar.gz      tools.tar.gz
    config.tar.gz       etc.tar.gz          regress.tar.gz      top-level.tar.gz
    contrib.tar.gz      games.tar.gz        rescue.tar.gz       usr.bin.tar.gz
    crypto.tar.gz       gnu.tar.gz          sbin.tar.gz         usr.sbin.tar.gz
    dist.tar.gz         include.tar.gz      share.tar.gz
    distrib.tar.gz      lib.tar.gz          sys.tar.gz

You now must extract them all:

    $ foreach file (*.tar.gz)
    ?   tar -xzf $file -C /usr/src
    ? end

### Downloading sources for a NetBSD-current development branch

To download the NetBSD-current tarballs, located under
`/pub/NetBSD/NetBSD-current/tar_files/src`, just follow the same steps as in the
previous section, but now on a different directory.

You may also want to fetch the X11 source, available under:
`/pub/NetBSD/NetBSD-current/tar_files/xsrc`.

## Fetching by CVS

CVS (Concurrent Versions System) can be used to fetch the NetBSD source tree or
to keep the NetBSD source tree up to date with respect to changes made to the
NetBSD sources. There are three trees maintained for which you can use
[cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-5.0.1+i386) to obtain
them or keep them up to date:

The list of currently maintained branches is available under
[`src/doc/BRANCHES`](http://cvsweb.NetBSD.org/bsdweb.cgi/src/doc/BRANCHES?rev=HEAD&content-type=text/x-cvsweb-markup)
(see the *Status* entry on *Release branches* section).

Before you can do an initial (full) checkout of the NetBSD sources via
*anonymous CVS*, you first have to set some environment variables. For the
C-Shell, type:

    $ setenv CVS_RSH ssh
    $ setenv CVSROOT anoncvs@anoncvs.NetBSD.org:/cvsroot

Or, the same for the bourne shell:

    $ export CVS_RSH="ssh"
    $ export CVSROOT="anoncvs@anoncvs.NetBSD.org:/cvsroot"

We will also use the `-P` option in the examples below since it is used to prune
empty directories.

### Fetching a NetBSD release

A release is a set of particular versions of source files, and once released
does not change over time.

To get the NetBSD (kernel and userland) sources from a specific release, run the
following command after the preparations done above:

    $ cd /usr
    $ cvs checkout -r <BRANCH> -P src

Where `<BRANCH>` is the release branch to be checked out, for example,
`netbsd-3-1-RELEASE` or `netbsd-4-0-RELEASE`. If you want to fetch a different
patchlevel, you would use `netbsd-3-0-1-RELEASE` or `netbsd-3-0-2-RELEASE`.

For example, in order to fetch `netbsd-4-0-RELEASE` you would use:

    $ cvs checkout -r netbsd-4-0-RELEASE -P src

To fetch the X11R6 source, just `checkout` the `xsrc` module. For example:

    $ cvs checkout -r netbsd-4-0-RELEASE -P xsrc

### Fetching a NetBSD stable branch

NetBSD stable branches are also called *Maintenance branches*. Please consult
the [[Terminology|guide/fetch#term]].

If you want to follow a stable branch, just pass the branch name to the
[cvs(1)](http://netbsd.gw.com/cgi-bin/man-cgi?cvs+1+NetBSD-5.0.1+i386) `-r`
option.

For example, if you want to fetch the most recent version of `netbsd-4`, you
just need to use that tag:

    $ cd /usr
    $ cvs checkout -r netbsd-4 -P src

And for the `xsrc` module:

    $ cvs checkout -r netbsd-4 -P xsrc

If you have checked out sources from a stable branch in `/usr/src` and want to
update them to get the latest security-fixes and bug-fixes, run:

    $ cd /usr/src
    $ cvs update -Pd

The same applies to the `xsrc` module, but in that case you will have to change
your working directory to `/usr/xsrc` first.

*Caution!* Be sure to take care in selecting the correct and desired branch tag
so you don't accidentally *downgrade* your source tree.

### Fetching the NetBSD-current development branch

To obtain the NetBSD-current source just omit `-r` *`<BRANCH>`* and replace it
by `-A`:

    $ cd /usr
    $ cvs checkout -A -P src

The `xsrc` is also available:

    $ cd /usr
    $ cvs checkout -A -P xsrc

To update your NetBSD-current source tree, add the `-A` flag:

    $ cd /usr/src
    $ cvs update -A -Pd

### Saving some cvs options

If you find yourself typing some options to cvs over and over again, you can as
well put them into a file `.cvsrc` in your home directory. It is useful for just
typing `cvs update` on a directory with a branch checked out to update it
(adding `-A` would revert the branch to the -current branch, which is not what
one usually wants!), For unified diffs, transfers should be compressed and `cvs
update` should be mostly quiet:

**Example `.cvsrc`**:

    #update -dPA
    update  -dP
    rdiff   -u
    diff    -u
    cvs     -q

## Sources on CD (ISO)

If you prefer to download (and maybe burn) a CD-ROM image with the NetBSD
source, just fetch `sourcecd-<RELEASE-NUMBER>.iso` from ftp.NetBSD.org or any
other mirror.

The `sourcecd-<RELEASE-NUMBER>.iso` file is located under
`/pub/NetBSD/iso/<RELEASE>`, where `<RELEASE>` is a release of NetBSD,
for example, `5.1`:

    ftp://ftp.NetBSD.org/pub/NetBSD/iso/5.1/sourcecd-5.1.iso

The next step is to burn the ISO image or mount it with the help of
[vnconfig(8)](http://netbsd.gw.com/cgi-bin/man-cgi?vnconfig+8+NetBSD-5.0.1+i386).
Please see [[Using removable media|guide/rmmedia]], as it explains in detail how
to do it.

Assuming you have mounted the CD under `/mnt`, `/mnt/source/sets` should have
everything you need to extract:

    $ ls /mnt/source/sets
    BSDSUM          MD5             gnusrc.tgz      src.tgz         xsrc.tgz
    CKSUM           SYSVSUM         sharesrc.tgz    syssrc.tgz

All tarballs should be extracted to the root file system (`/`). The following
command will do it:

    $ foreach file (*.tgz)
    ?   tar -xzf $file -C /
    ? end

After that, you should have `/usr/src` and `/usr/xsrc` populated with the NetBSD
sources.

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