Table of Contents
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).
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
Please replace it with a valid login name on your system:
If you want the sources to the X Window System, you should prepare
/usr/xsrc as well:
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:
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.
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
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.
The tarballs for the sources of a specific release are
on ftp.NetBSD.org (or a mirror),
<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 *.tgzlocal: gnusrc.tgz remote: gnusrc.tgz 229 Entering Extended Passive Mode (|||55933|) 150 Opening BINARY mode data connection for 'gnusrc.tgz' (43068850 bytes). [...] ftp>
quit221- 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 *.tgzgnusrc.tgz sharesrc.tgz src.tgz syssrc.tgz xsrc.tgz
You now must extract them all:
for file in *.tgz>
tar -xzf $file -C />
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.gzlocal: 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>
quit221- 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.gzbin.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>
tar -xzf $file -C /usr>
To download the NetBSD-current tarballs, located under
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
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”
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:
In the examples below, we use the
which tells CVS to prune empty directories.
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:
cvs checkout -r
<BRANCH> is the
release branch to be checked out, e.g.,
“netbsd-5-2-RELEASE”. If you want to
fetch a later patchlevel, you would use, e.g.,
For example, in order to fetch “netbsd-6-1-5-RELEASE” you would use:
cvs checkout -r netbsd-6-1-5-RELEASE -P src
To fetch the X Window System source, just “checkout” the “xsrc” module. For example:
cvs checkout -r netbsd-6-1-5-RELEASE -P xsrc
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)
For example, if you want to fetch the most recent version of “netbsd-6”, you just need to use that tag:
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:
cvs update -Pd
The same applies to the “xsrc” module, but in
that case you will have to change your working directory to
Be sure to take care in selecting the correct and desired branch tag so you don't accidentally downgrade your source tree.
To obtain the NetBSD-current source just omit
and replace it with “
cvs checkout -A -P src
The “xsrc” module is obtained the same way:
cvs checkout -A -P xsrc
To update your NetBSD-current source tree, add the
cvs update -A -Pd
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
.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.
If you prefer to download (and maybe burn) a CD-ROM image
with the NetBSD source, just fetch
from ftp.NetBSD.org or any other mirror.
file is located under /pub/NetBSD/iso/
<RELEASE-NUMBER> is a release of NetBSD, for example,
Note that prior to NetBSD 6.0, these images were named
Assuming you have mounted the CD under
should have everything you need to extract:
ls /mnt/source/setsMD5 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>
tar -xzf $file -C />
After that, you should have
/usr/xsrc populated with the NetBSD