Updating the NetBSD configuration and startup files after an operating system upgrade

By Martti Kuparinen (published at BSD Today in December 2001)

Last updated: $Date: 2004/03/01 05:22:30 $

I have written a simple script called etcupdate for NetBSD to help users compare, merge and install new configuration and startup files (i.e. files found in the etc.tgz distribution set) in /dev, /etc and /root after performing an operating system upgrade. The upgrade of the operating system could have been performed either by compiling sources or by extracting the distribution binaries.

You might now wonder what are the differences between etcupdate and the FreeBSD mergemaster? etcupdate is a sh(1), not perl(1) script making it usable even in smallest setups without any extra applications like perl(1) installed. etcupdate uses cmp(1) to check if there are changes in the files while mergemaster sometimes uses the CVS version tags to detect changes in files. And finally, etcupdate is able to use binary distribution sets in addition to source files to perform its operations.

Upgrading NetBSD

As mentioned earlier, you can perform an operating system upgrade either by compiling the sources or by fetching and extracting the distribution binaries. To upgrade from the sources, you might type something like this:

# cd /usr/src
# cvs -q update -dP -rnetbsd-1-5
# cd /usr/src/usr.sbin/config
# make dependall install
# cd /usr/src/sys/arch/`uname -m`/conf
# config GENERIC
# cd ../compile/GENERIC
# make dependall install
# reboot

# cd /usr/src
# make build
To upgrade from the distribution sets, you might type something like this:
# cd /some/where
# ftp ftp://ftp.<COUNTRY>.netbsd.org/pub/NetBSD/NetBSD-<VERSION>/<ARCH>/binary/sets/
ftp> mget *.tgz
ftp> bye
# sh
# for i in *.tgz; do
> [ $i = etc.tgz ] && continue
> echo $i
> tar xpzf $i -C /
> done
#
After performing the operating system upgrade, it's time to check and update the configuration and startup files which were not installed by default so that you won't lose your own modifications.

Installing etcupdate

As you would expect, you will need to be root to perform the following steps. Start by updating your pkgsrc (as the etcupdate package was added into pkgsrc on November 19th, 2001). If you already have etcupdate installed, make sure you have the latest version. (At the time of this publication, it is 20011204 or later.) Anonymous CVS users can update the relevant pkgsrc subtree with the following command:

# cd /usr/pkgsrc/sysutils
# cvs -q update -dP etcupdate
Next install the etcupdate package and read the manual page (as you always RTFM before trying the command, right?):
# cd /usr/pkgsrc/sysutils/etcupdate
# make install clean
# man etcupdate
After reading the manual page and the usage examples it is time to perform the actual update. This can be done in two different "modes": I personally install everything from sources but sometimes it might not be possible to have the sources around. The next two sections describe both these methods so don't worry if you don't have the sources.

Using the sources to update the configuration and startup files

So you have the sources where you compiled and installed your new NetBSD? Great! Now it's time to start etcupdate and let it first create a temporary copy of the files in /tmp/temproot. This is done by executing make distribution [1] in /usr/src/etc. Please note that etcupdate performs this for you, you shouldn't do this manually.

In case where the sources are in /usr/src the following command should be enough:

# etcupdate
But what if your NetBSD sources are in an alternative location, such as in /home/jdoe/netbsd/src? Don't worry, tell etcupdate the location of your source tree with -s srcdir and it will work just fine:
# etcupdate -s /home/jdoe/netbsd/src/etc
Please note that this method of updating from sources expects to find etc/Makefile in the source tree.

Using files from etc.tgz to update the configuration and startup files

Sometimes it's not possible have the sources around but you still want to update the configuration and startup files. The solution is to extract the desired distribution files (at least etc.tgz) and use the -b srcdir switch to tell etcupdate that we don't have the sources but only the official distribution sets.

In the following example you will extract only etc.tgz as this file contains the /dev, /etc, /root and /var directories and the configuration and startup files you want to update. Do not extract the etc.tgz to the root directory or you will overwrite your current password and configuration files! Instead extract it into a temporary directory (/tmp/temproot in the following example) and let etcupdate take care of the files.

# mkdir /tmp/temproot
# cd /tmp/temproot
# tar xpzf /some/where/etc.tgz
# etcupdate -b /tmp/temproot

Usage example

You have just started etcupdate and you will see something like this when a new version if found. The output says that the currently installed /dev/MAKEDEV may have to be updated as there are some new lines added to it.

# etcupdate -s /work/src/etc
*** Creating /tmp/temproot
*** Populating /tmp/temproot from /work/src/etc
*** Checking for new directories
*** Checking for added/modified files

--- /dev/MAKEDEV        Sat Nov 24 18:45:12 2001
+++ /tmp/temproot/dev/MAKEDEV   Sat Nov 24 18:45:24 2001
@@ -1,6 +1,6 @@
 #!/bin/sh -
 #
-#      $NetBSD: MAKEDEV,v 1.118.2.6 2001/05/02 22:19:12 he Exp $
+#      $NetBSD: MAKEDEV,v 1.118.2.7 2001/10/25 17:59:11 he Exp $
 #
 # Copyright (c) 1990 The Regents of the University of California.
 # All rights reserved.
@@ -111,6 +111,8 @@
 #      cfs*    Coda file system device
 #      sysmon  System Monitoring hardware
 #      bktr    Brooktree 848/849/878/879 based TV cards
+#      iop*    I2O IOP control interface
+#      mlx*    Mylex DAC960 control interface
 #
 
 dialin=0
@@ -144,7 +146,7 @@
        sh $0 bpf0 bpf1 bpf2 bpf3 bpf4 bpf5 bpf6 bpf7
        sh $0 lpt0 lpt1 lpt2 ttyv0 tun0 tun1 tun2 tun3 ipl
        sh $0 ccd0 ccd1 ccd2 ccd3 md0 ss0 ch0 uk0 uk1 random
-       sh $0 speaker lkm mms0 lms0 pms0 joy0 joy1 apm local satlink0
+       sh $0 speaker lkm mms0 lms0 pms0 joy0 joy1 apm local satlink0 iop0 mlx0
        sh $0 audio
        sh $0 usbs
        sh $0 music rmidi0 rmidi1 rmidi2 rmidi3 rmidi4 rmidi5 rmidi6 rmidi7
@@ -722,6 +724,20 @@
        mknod vbi$unit c 71 $(($unit + 32))
        chown root.wheel bktr$unit tuner$unit vbi$unit
        chmod 444 bktr$unit tuner$unit vbi$unit
+       ;;
+
+iop*)
+       unit=${i#iop};
+       rm -f iop$unit
+       mknod iop$unit c 76 $unit
+       chmod 600 iop$unit
+       ;;
+
+mlx*)
+       unit=${i#mlx};
+       rm -f mlx$unit
+       mknod mlx$unit c 78 $unit
+       chmod 600 mlx$unit
        ;;
 
 local)

File: /dev/MAKEDEV (modified)

Please select one of the following operations:

  d  Don't install the new file
  i  Install the new file (overwrites your modifications!)
  m  Merge the currently installed and new files
  s  Show the differences between the currently installed and new files
  v  Show the new file

What do you want to do? [Leave it for later] i

Remove /tmp/temproot (y/[n]) y
*** Removing /tmp/temproot
Do you want to rebuild the device nodes in /dev (y/[n]) y
*** All done
As this is a configuration file without local modifications, you should install it by typing i and pressing Enter. But should this file have your local modifications (e.g. the /etc/master.passwd might have local accounts) and there is a new version in /tmp/temproot, you might consider merging (m) the files (which is done with sdiff(1)) and thus keeping your own settings and getting the new features from the official NetBSD distribution.

Selecting d removes the temporary copy from /tmp/temproot. It does not modify the currently installed file.

You can also leave the new file into /tmp/temproot for later analysis and manual inspection just by pressing Enter (to select the default "Leave it for later" operation). etcupdate lists such files before asking if you want to remove /tmp/temproot.

As you can see from the previous example, etcupdate will also notice if you change some "special" files and ask if you want to perform some post-installation tasks like rebuilding the device nodes in the /dev directory. Currently the following "special" files are triggering post-installation tasks:

Feedback

If you discover bugs, have new ideas or improvements, please submit a problem report with as much details as possible (patches in 'diff -u' output are really appreciated).

History

The idea for this script (including code fragments, variable names etc.) came from the FreeBSD mergemaster (by Douglas Barton). Why didn't I simply port mergemaster to NetBSD? I have few hosts running the smallest possible configuration (e.g. without perl) where I needed to update the configuration and startup files without manually checking every single file.

Footnotes

[1] The command used to create the temporary copy of the configuration files is: