File:  [NetBSD Developer Wiki] / wikisrc / guide / updating.mdwn
Revision 1.2: download - view: text, annotated - select for diffs
Fri Mar 1 11:49:18 2013 UTC (8 years, 3 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
Some wording/cosmetics.

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

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb