File:  [NetBSD Developer Wiki] / wikisrc / guide / updating.mdwn
Revision 1.5: download - view: text, annotated - select for diffs
Fri Jun 19 19:18:31 2015 UTC (7 years, 5 months ago) by plunky
Branches: MAIN
CVS tags: HEAD
replace direct links to manpages on with templates

    1: **Contents**
    3: [[!toc levels=3]]
    5: # Updating an existing system from sources
    7: A common mechanism for upgrading a NetBSD system to a newer version is by
    8: rebuilding the system from sources and installing the results. This works both
    9: for stable releases such as [NetBSD 5.0](/releases/formal-5/) and for
   10: NetBSD-current. In particular, if you are running a stable NetBSD release in a
   11: production environment, you are encouraged to perform this procedure regularly
   12: in order to incorporate any security fixes that have been applied to the branch
   13: since its release.
   15: There are a variety of ways of achieving the goal of rebuilding NetBSD from
   16: source, and this chapter will guide you through the variety of options that are
   17: available. The chapter starts by showing first what the manual procedure looks
   18: like, and proceeds to describe some of automation tools that simplify the
   19: process.
   21: **Note**: Please remember to check
   22: [src/UPDATING]( for the latest
   23: changes and special instructions that may be involved in upgrading the system.*
   25: ## Manual build and update procedure
   27: Most of the following steps can be done as ordinary user. Only the installation
   28: of a new kernel and the userland will require root privileges. Although `/usr`
   29: is choosen as the working directory in the following examples, the procedure
   30: can also take place in a user's home directory. Ordinary users have normally
   31: not the permissions to make changes in `/usr`, but this can be changed by root.
   33: Having up-to-date sources is a prerequisite for the following steps.
   34: [[Fetching by CVS|guide/fetch#cvs] informs about the ways to retrieve or update
   35: the sources for a release, stable or current branch (using CVS).
   37: Please always refer to the output of ** -h** and the files `UPDATING`
   38: and `BUILDING` for details - it's worth it, there are *many* options that can
   39: be set on the command line or in `/etc/mk.conf`
   41: ### Building a new userland
   43: The first step is to build the userland:
   45:     $ cd /usr/src
   46:     $ ./ -O ../obj -T ../tools -U distribution
   48: ### Building a new kernel
   50: The next step will build the kernel:
   52:     $ cd /usr/src
   53:     $ ./ -O ../obj -T ../tools kernel=<KERNEL>
   55: ### Installing the kernel and userland
   57: Installing the new kernel, rebooting (to ensure that the new kernel works) and
   58: installing the new userland are the final steps of the updating procedure:
   60:     $ cd /usr/src
   61:     $ su
   62:     # mv /netbsd /netbsd.old
   63:     # mv /usr/obj/sys/arch/<ARCH>/compile/<KERNEL>/netbsd /
   64:     # shutdown -r now
   65:      ...
   66:     $ cd /usr/src
   67:     $ su
   68:     # ./ -O ../obj -T ../tools -U install=/
   70: If the new kernel `netbsd` does not boot successfully, you can fall back on
   71: booting the `netbsd.old` kernel.
   73: ### Updating the system configuration files
   75: Run the `etcupdate` script
   76: ([[!template id=man name="etcupdate" section="8"]])
   77: and follow the instructions in the output for fixing obsolete files:
   79:     # /usr/sbin/etcupdate -s /usr/src
   81: Optionally reboot to ensure all running services are using the new binaries:
   83:     # shutdown -r now
   85: ### Summary
   87:  1. From the root of the source tree:
   89:         $ cd /usr/src
   91:  2. Build the userland:
   93:         $ ./ -O ../obj -T ../tools -U -u distribution
   95:  3. Build the kernel:
   97:         $ ./ -O ../obj -T ../tools -U -u kernel=GENERIC
   99:  4. Install the kernel:
  101:         $ cd ../obj/sys/arch/<ARCH>/compile/GENERIC
  102:         $ su
  103:         # mv /netbsd /netbsd.old
  104:         # cp netbsd /netbsd
  106:  5. Reboot into the new kernel:
  108:         # shutdown -r now
  110:  6. Install the new userland:
  112:         $ cd /usr/src
  113:         $ su
  114:         # ./ -O ../obj -T ../tools -U install=/
  116:  7. Update the system and configuration files;:
  118:         #  /usr/sbin/etcupdate -s /usr/src
  120: **Note**: In the procedure above, the `-u` option indicates an update process,
  121: and that a `make clean` operation should not be run before starting the build.
  122: This is useful when doing an update from a previous build and/or a fresh build.
  123: The `-U` option allows the entire build by a non-root user followed with an
  124: install by root.
  126: ## Using sysinst
  128: It is also possible to use `sysinst` to install a freshly built system. The
  129: steps are as follows:
  131:  1. Build a complete release:
  133:         $ ./ -O ../obj -T ../tools -U -u -x release
  135:  2. The resulting install sets will be in the `/usr/obj/releasedir/` directory.
  136:  3. Copy the install kernel to the root directory of your NetBSD system, reboot
  137:     from it, and upgrade with `sysinst` (see
  138: 	[[Upgrading NetBSD|guide/upgrading]]).
  141: ## Using sysbuild and sysupgrade
  143: The sysbuild and sysupgrade tools (currently available in
  144: `pkgsrc/sysutils/sysbuild` and `pkgsrc/sysutils/sysupgrade` respectively)
  145: automate the full process of rebuilding NetBSD from sources (*including the
  146: retrieval of the sources from a CVS repository*) and installing the results
  147: with minimal effort.
  149: Both of these tools have configuration files to determine how to build a
  150: release and how to install it. Among other things, these specify the CVS
  151: repository to use, what architecture to build for, where to place the build
  152: files and what steps to perform during an upgrade. The files can be found in
  153: `/usr/pkg/etc/sysbuild/default.conf` and `/usr/pkg/etc/sysupgrade.conf`. The
  154: default configuration of both tools should let you get started with minimal
  155: effort.
  157: In their simplest form, you can do a full NetBSD build and upgrade your system
  158: to it by running these commands:
  160:     # sysbuild build
  161:     # sysupgrade auto ~/sysbuild/release/$(uname -m)
  163: And that's all that it takes. These invocations will do the following:
  165:  1. Download the source trees from CVS into `/usr/src` and `/usr/xsrc`. The
  166:     latter is only fetched if your system has X11. And, if you already have
  167:     the sources in your system, this will only update them to the newest
  168: 	version.
  169:  2. Build a new release into `~/sysbuild/<machine>/`. This per-machine
  170:     directory will include subdirectories like `obj`, `destdir`, etc. The
  171:     build results will be left in `~/sysbuild/release/<machine>/`.
  172:  3. Install a new kernel and unpack the new sets using the just-built release
  173:     files.
  174:  4. Run both etcupdate and postinstall to aid you in merging new configuration
  175:     changes into your system.
  177: For more details, please see the included `sysbuild(1)` and `sysupgrade(8)`
  178: manual pages, as well as the comments in the referenced configuration files.
  180: ### Tweak: Building as non-root
  182: The commands above depict the most basic and simple invocation of the tools
  183: using the *default configuration files*. One drawback is that you require root
  184: access during the build of the source tree so that sysbuild can upgrade the
  185: source trees under `/usr/src` and `/usr/xsrc`. It is recommended that you avoid
  186: building as root once you are familiar with the procedure, and this section
  187: show what is needed to do so with sysbuild.
  189: In order to build as non-root, you can either choose to store your source trees
  190: out of `/usr` (easiest) or give permissions to your user to modify the trees
  191: under `/usr` (good if you want to share the source tree with more than one
  192: user).
  194: If you want to store the source trees under your home directory, which is
  195: convenient for development purposes, simply edit `/usr/pkg/etc/sysbuild.conf`
  196: and add these settings:
  198:     SRCDIR="${HOME}/sysbuild/src"
  199:     [ ! -f /etc/mtree/set.xbase ] || XSRCDIR="${HOME}/sysbuild/xsrc"
  201: Once this is done, the `sysbuild build` invocation show above should just work
  202: under your unprivileged user. The upgrade procedure then becomes:
  204:     $ sysbuild build
  205:     ... become root ...
  206:     # sysupgrade auto ~/sysbuild/release/$(uname -m)
  208: The other alternative, in case you want to maintain your source trees in the
  209: locations described by
  210: [[!template id=man name="hier" section="7"]], is
  211: to do the following as root:
  213:     # mkdir -p /usr/src /usr/xsrc
  214:     # chown -R <your-user>:wsrc /usr/src /usr/xsrc
  215:     ... and optionally add <your-user> to wsrc in /etc/group ...
  217: After this, the default configuration file of sysbuild will let you place the
  218: files in these locations and let you do unprivileged builds.
  220: **Note**: If you have an an encrypted home partition, or another "special"
  221: filesystem you store your sources on, you should backup them somehwere you can
  222: easily access them! In case of a failed build you might want to rebuild without
  223: being able to access an encrypted partition.
  225: ### Tweak: Setting up nightly builds
  227: The `pkgsrc/sysutils/sysbuild-user` package can be used to configure and
  228: maintain an unprivileged system user to perform periodic (e.g. nightly) builds
  229: from source. This can come in very handy to closely track NetBSD-current.
  231: The installed user is appropriately named sysbuild, and is configured by
  232: default to run a full system build overnight. The results are left in
  233: `/home/sysbuild/release/<machine>/`, which is the convenient default of
  234: sysupgrade's release directory. Any build failures will be reported to you by
  235: email.
  237: The behavior of sysbuild for this unprivileged user is configured in
  238: `/home/sysbuild/default.conf`.
  240: You can interact with sysbuild under this unprivileged user by running
  241: commands of the form:
  243:     # su - sysbuild /usr/pkg/bin/sysbuild ...
  245: ## More details about the updating of configuration and startup files
  247: [[!template id=man name="etcupdate" section="8"]]
  248: is a script to help users compare, merge and install new configuration and
  249: startup files (files found in the `etc.tgz` distribution set) in `/dev`, `/etc`
  250: and `/root` after performing an operating system upgrade. The upgrade of the
  251: operating system could have been performed either by compiling sources or by
  252: extracting the distribution binaries.
  254: ### Using etcupdate with source files
  256: In case where the sources are in `/usr/src` the following command should be enough:
  258:     # etcupdate
  260: But what if your NetBSD sources are in an alternative location, such as in
  261: `/home/jdoe/netbsd/src`? Don't worry, tell etcupdate the location of your
  262: source tree with `-s srcdir` and it will work just fine:
  264:     # etcupdate -s /home/jdoe/netbsd/src
  266: ### Using etcupdate with binary distribution sets
  268: Sometimes it's not convenient to have the sources around but you still want to
  269: update the configuration and startup files. The solution is to feed `etc.tgz`
  270: (or `xetc.tgz`) to etcupdate via the `-s tgzfile` switch:
  272:     # etcupdate -s /some/where/etc.tgz
  274: ### Using etcmanage instead of etcupdate
  276: The `etcmanage` perl script (available from
  277: [pkgsrc/sysutils/etcmanage]( or as binary
  278: package) is an alternative to etcupdate(8). It should be used in the following
  279: way, in combination with
  280: [[!template id=man name="postinstall" section="8"]]:
  282:     # /usr/pkg/bin/etcmanage
  283:     # /usr/sbin/postinstall

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb