Chapter 32. Obtaining the sources

Table of Contents

32.1. Preparing directories
32.2. Terminology
32.3. Downloading tarballs
32.3.1. Downloading sources for a NetBSD release
32.3.2. Downloading sources for a NetBSD stable branch
32.3.3. Downloading sources for a NetBSD-current development branch
32.4. Fetching by CVS
32.4.1. Fetching a NetBSD release
32.4.2. Fetching a NetBSD stable branch
32.4.3. Fetching the NetBSD-current development branch
32.4.4. Saving some cvs(1) options

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

32.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
$ 

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

32.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 stable branches are only updated every three days.

32.3.1. Downloading sources for a NetBSD release

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

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, 10.0).

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

$ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-10.0/source/sets/
Trying 2001:470:a085:999::21:21 ...
Connected to ftp.NetBSD.org.
220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20180428) ready.
331 Guest login ok, type your name as password.
[...]
250 CWD command successful.
ftp> mget *.tgz
local: gnusrc.tgz remote: gnusrc.tgz
229 Entering Extended Passive Mode (|||61968|)
150 Opening BINARY mode data connection for 'gnusrc.tgz' (152604808 bytes).
[...]
ftp> quit
221-
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

32.3.2. Downloading sources for a NetBSD stable branch

$ ftp -i ftp://ftp.NetBSD.org/pub/NetBSD/NetBSD-release-10/tar_files/src/
Trying 2001:470:a085:999::21:21 ...
Connected to ftp.NetBSD.org.
220 ftp.NetBSD.org FTP server (NetBSD-ftpd 20180428) ready.
331 Guest login ok, type your name as password.
[...]
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' (996075 bytes).
[...]
ftp> quit
221-
    Data traffic for this session was 429024351 bytes in 25 files.
    Total traffic for this session was 429035139 bytes in 26 transfers.
221 Thank you for using the FTP service on ftp.NetBSD.org.

You should now have 25 files:

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

You now must extract them all:

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

32.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 Section 32.3.2, “Downloading sources for a NetBSD stable branch”, but using this path.

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

32.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 the Release branches section).

Caution!

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

Before you can do an initial (full) checkout of the NetBSD sources via anonymous CVS, you must set the CVSROOT environment variable, which tells cvs(1) where to fetch the files from:

$ export CVSROOT="[email protected]:/cvsroot"

Make sure that the environment variable CVS_RSH is set to ssh.

$ export CVS_RSH="ssh"

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

32.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 <TAG> -P src

Where <TAG> is the release tag to be checked out, e.g., netbsd-10-0-RELEASE. If you want to fetch a later patchlevel, you would use, e.g., netbsd-10-0-RELEASE.

For example, in order to fetch the sources for NetBSD 10.0, you would use the netbsd-10-0-RELEASE tag:

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

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

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

32.4.2. Fetching a NetBSD stable branch

NetBSD stable branches are a flavor of Maintenance branches. Please consult the Section 32.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-9, you just need to use that tag:

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

And for the xsrc module:

$ cvs checkout -r netbsd-9 -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 -dP

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

32.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 -dP

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

32.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 32.1. .cvsrc

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