Chapter 30. Obtaining the sources

Table of Contents

30.1. Preparing directories
30.2. Terminology
30.3. Downloading tarballs
30.3.1. Downloading sources for a NetBSD release
30.3.2. Downloading sources for a NetBSD stable branch
30.3.3. Downloading sources for a NetBSD-current development branch
30.4. Fetching by CVS
30.4.1. Fetching a NetBSD release
30.4.2. Fetching a NetBSD stable branch
30.4.3. Fetching the NetBSD-current development branch
30.4.4. Saving some cvs(1) options
30.5. Sources on CD (ISO)

To read the NetBSD sources from your local disk or to build the system, you need to download the NetBSD sources. This chapter explains a number of different ways to obtain the NetBSD sources, although the preferred method is to download the tarballs and then update via cvs(1).

30.1. Preparing directories

Traditionally, the NetBSD kernel and userland sources are 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

If you want the sources to the X Window System, you should prepare /usr/xsrc as well:

# 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, so relinquish your root privileges:

# exit
$ 

30.2. 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.

30.3. Downloading tarballs

It is sometimes faster to begin by downloading a source tarball. You can download tarballs (see tar(1)) from ftp.NetBSD.org (or any other mirror) for a number of releases or branches. These tarballs include the CVS directories, so you can continue to update your source tree using cvs(1), as explained in the CVS section.

Note that source tarballs for maintenance branches are only updated every three days.

30.3.1. Downloading sources for a NetBSD release

The tarballs 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, 6.1).

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

$ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-6.1/source/sets/
Trying 2001:470:1f05:3d::21:21 ...
Connected to ftp.NetBSD.org.
220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20100320) 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 (|||55933|)
150 Opening BINARY mode data connection for 'gnusrc.tgz' (43068850 bytes).
[...]
ftp> quit
221-
    Data traffic for this session was 452840861 bytes in 5 files.
    Total traffic for this session was 452846550 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:

$ for file in *.tgz
> do
> tar -xzf $file -C /
> done

30.3.2. Downloading sources for a NetBSD stable branch

$ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-release-6/tar_files/src/
Trying 2001:470:1f05:3d::21:21 ...
Connected to ftp.NetBSD.org.
220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20100320) 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' (916134 bytes).
[...]
ftp> quit
221-
    Data traffic for this session was 295051027 bytes in 27 files.
    Total traffic for this session was 295062402 bytes in 28 transfers.
221 Thank you for using the FTP service on ftp.NetBSD.org.

You should now have 27 files:

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

You now must extract them all:

$ for file in *.tar.gz
> do
> tar -xzf $file -C /usr
> done

30.3.3. 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 using this path.

You may also want to fetch the X Window System sources, available under: /pub/NetBSD/NetBSD-current/tar_files/xsrc.

30.4. 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 two main source modules available through cvs(1), src and xsrc.

The list of currently maintained branches is available under src/doc/BRANCHES (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 an environment variable to tell cvs(1) which server to fetch the files from:

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

In the examples below, we use the -P option, which tells CVS to prune empty directories.

30.4.1. Fetching a NetBSD release

The source files to a release do not change after the release has been made.

To get the NetBSD (kernel and userland) sources for a specific release, run the following command after setting CVSROOT as shown above:

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

Where <BRANCH> is the release branch to be checked out, e.g., netbsd-6-1-RELEASE or netbsd-5-2-RELEASE. If you want to fetch a later patchlevel, you would use, e.g., netbsd-6-1-4-RELEASE or netbsd-5-2-2-RELEASE.

For example, in order to fetch netbsd-6-1-4-RELEASE you would use:

$ cvs checkout -r netbsd-6-1-4-RELEASE -P src

To fetch the X Window System source, just checkout the xsrc module. For example:

$ cvs checkout -r netbsd-6-1-4-RELEASE -P xsrc

30.4.2. Fetching a NetBSD stable branch

NetBSD stable branches are also called Maintenance branches. Please consult the Section 30.2, “Terminology”.

If you want to follow a stable branch, just pass the branch name to the cvs(1) -r option.

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

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

And for the xsrc module:

$ cvs checkout -r netbsd-6 -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 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.

30.4.3. Fetching the NetBSD-current development branch

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

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

The xsrc module is obtained the same way:

$ 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

30.4.4. Saving some cvs(1) options

If you find yourself typing the same options to CVS over and over again, you may want to make those options the default by adding them to .cvsrc in your home directory. In the following example, cvs update will add any missing newly-added directories to your tree, as well as delete any newly-empty directories. Also shown are examples of how to make cvs rdiff and cvs diff use the unified diff(1) format. The final line in the example causes CVS to be a bit more quiet in its operation.

Example 30.1. .cvsrc

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

30.5. Sources on CD (ISO)

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

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

ftp://ftp.NetBSD.org/pub/NetBSD/iso/6.1/NetBSD-6.1-source.iso

Sources for releases prior to 6.0

Note that prior to NetBSD 6.0, these images were named sourcecd-<RELEASE-NUMBER>.iso.

The next step is to burn the ISO image or mount it with the help of vnconfig(8). Please see Chapter 13, Using removable media for information about how to do that.

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

$ ls /mnt/source/sets
MD5             gnusrc.tgz      src.tgz         xsrc.tgz
SHA512          sharesrc.tgz    syssrc.tgz

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

$ for file in *.tgz
> do
> tar -xzf $file -C /
> done

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