<?xml version="1.0"?>
<!DOCTYPE webpage
PUBLIC "-//NetBSD//DTD Website-based NetBSD Extension//EN"
"http://www.NetBSD.org/XML/htdocs/lang/share/xml/website-netbsd.dtd">

<webpage id="docs-updating">
  <config param="desc" value="Updating a stable NetBSD release" />
  <config param="cvstag"
  value="$NetBSD: updating.xml,v 1.8 2008/06/09 10:10:26 mishka Exp $" />
  <config param="rcsdate" value="$Date: 2008/06/09 10:10:26 $" />
  <head>
    <!-- Copyright (c) 2003-2006
           The NetBSD Foundation, Inc.  ALL RIGHTS RESERVED. -->
    <title>Updating a stable NetBSD release</title>
  </head>
  <sect1 role="toc" id="updating-stable">
    <sect2 id="top">

      <sect3 id="current">
        <title>Tracking -current</title>
        <para>
          See 
          <ulink url="current/">this document</ulink>
          for our documentation on how to track NetBSD-current.
        </para>
      </sect3>

      <sect3 id="update-src">
        <title>Updating the sources</title>
        <para>
          If you are running a stable NetBSD release (such as 
          <ulink url="../releases/formal-3/">NetBSD 3.1</ulink>),
          in a production environment, you should occasionally
          update your sources and rebuild the system or the kernel,
          in order to incorporate any security fixes that have been
          applied to the branch since its release.
       </para>

       <para>Most of the following steps can be done as ordinary user. 
       Only the installation of a new kernel and the userland will require 
       root privileges.
       Although <filename>/usr</filename> is choosen as the working 
       directory in the following examples, the procedure can also 
       take place in a user's home directory. Ordinary users have normally not 
       the permissions to make changes in <filename>/usr</filename>, 
       but this can be changed by root. </para>

     <para> 
         You can retrieve or update the sources for your
         release using 
         <ulink url="current/#using-anoncvs-over-ssh">anoncvs over
          ssh</ulink>
          by specifying the correct branch tag. For example, to
          checkout the sources for the NetBSD 3.1 release, you
          could use:
        </para>
        <programlisting>
$ cd /usr
$ export CVS_RSH=ssh 
$ cvs -d anoncvs@anoncvs.NetBSD.org:/cvsroot co -r netbsd-3-1 -P src</programlisting>

  <note>
  Be sure to take care in selecting the correct and desired branch tag so
  you don't accidently <emphasis>downgrade</emphasis> your source tree.
  </note>

  <para>To update an existing source tree, do:</para>

<programlisting>
$ cd /usr/src
$ export CVS_RSH=ssh 
$ cvs update -dP</programlisting>

</sect3>

<sect3 id="tools">
  <title>Building the tools</title>

  <para>The next step is to build the toolchain. You need to 
  create an <filename>obj/</filename> and a <filename>tools/</filename> 
  directory, followed by a run of <command>build.sh</command>:</para>

  <programlisting>
$ mkdir /usr/obj /usr/tools
$ cd /usr/src
$ ./build.sh -O /usr/obj -T /usr/tools -U -u tools</programlisting>

</sect3>


      <sect3 id="kernel">
        <title>Building a new kernel</title>
        <para>
          Building a new kernel pretty much follows the steps
          as described in 
          <ulink url="kernel/#how_to_build_a_kernel">this
          document</ulink>.
        </para>

<para>The steps to build the kernel are:</para>
<programlisting>
$ cd /usr/src
$ ./build.sh -O ../obj -T ../tools kernel=&lt;KERNEL&gt;
</programlisting>


      </sect3>

      <sect3 id="userland">
        <title>Building a new  userland</title>
        <para>
          Please always refer to <code>build.sh -h</code> and the
          files <emphasis>UPDATING</emphasis> and
          <emphasis>BUILDING</emphasis> for details - it's worth
          it, there are <emphasis>many</emphasis> options that can
          be set on the command line or in
          <filename>/etc/mk.conf</filename>.
        </para>

<para>The build the userland, do:</para>
<programlisting>
$ ./build.sh -O ../obj -T ../tools -U distribution</programlisting>

      </sect3>

<sect3 id="installing">
  <title>Installing the kernel and userland</title>

<para>Installing the new kernel, rebooting (to ensure that the new kernel 
works) and installing the new userland are the final steps of the updating 
procedure:</para>
<programlisting>
$ cd /usr/src
$ su
# mv /netbsd /netbsd.old
# mv /usr/obj/sys/arch/&lt;ARCH&gt;/compile/&lt;KERNEL&gt;/netbsd /
# shutdown -r now
...
$ cd /usr/src
$ su
# ./build.sh -O ../obj -T ../tools -U install=/ </programlisting>

<para>If the new kernel <filename>netbsd</filename> does not boot 
successfully, you can fall back on booting the 
<filename>netbsd.old</filename> kernel.</para>

</sect3>


      <sect3 id="parts">
        <title>Updating only parts of the source tree</title>

        <para>
          If a security advisory has been issued, and you want
          to just rebuild the necessary libraries and applications,
          your best bet is to follow the instructions provided in the
          advisory. An example is given below:
        </para>

<programlisting>
$ cd src
$ export CVS_RSH=ssh cvs update -d -P -r netbsd-3-1 gnu/dist/sendmail/sendmail
$ cd gnu/usr.sbin/sendmail
$ make USETOOLS=no cleandir dependall
$ su
# make USETOOLS=no install</programlisting>

</sect3>

<sect3 id="summary">
  <title>Terse summary of an updating procedure</title>
<itemizedlist>

          <listitem>
            <para>Updating the sources:</para>
            <programlisting>
$ cd /usr/src
$ export CVS_RSH=ssh 
$ cvs update -dP</programlisting>
          </listitem>


  <listitem>
  <para>Building the new kernel and userland:</para>
  <programlisting>
$ cd /usr/src
$ ./build.sh -O ../obj -T ../tools tools
$ ./build.sh -O ../obj -T ../tools kernel=&lt;KERNEL&gt;
$ ./build.sh -O ../obj -T ../tools -U distribution</programlisting>
  </listitem>

  <listitem>
  <para>Installing the new kernel and userland:</para>
  <programlisting>
$ su
# mv /netbsd /netbsd.old
# mv /usr/obj/sys/arch/&lt;ARCH&gt;/compile/&lt;KERNEL&gt;/netbsd /
# shutdown -r now
...
$ cd /usr/src
$ su
# ./build.sh -O ../obj -T ../tools -U install=/ </programlisting>
  </listitem>

</itemizedlist>
</sect3>

    </sect2>
  </sect1>
</webpage>

