Using mergemaster to Check for Changed Configuration Files


Using mergemaster to Check for Changed Configuration Files

There's only one step left in the make world process: merging your old /etc hierarchy (and other miscellaneous areas such as /var/log and /usr/share) with the new ones. As you learned earlier, the make world steps don't touch /etc, in order to keep from stomping on heavily customized configurations. In earlier days, the only way to merge changes into /etc was to do it manually, a very painful and error-prone process. The mergemaster utility, a standard part of FreeBSD, makes this process a great deal simpler and safer.

A lot of safeguards are built into mergemaster; it's a very safe tool to use. Nevertheless, there always exists the risk of damaging your configuration, so as a precaution, you should make a backup copy of /etc. Fortunately, this is easy:

# cp -Rp /etc /etc.old


Or:

# tar cvfz /etc-backup.tgz /etc


Running mergemaster

Typically, mergemaster doesn't really need any options; its defaults are set to sensible behaviors. This first time through, you can add the -v (verbose) option to see an explanation of what mergemaster is doing at each step. You can also use the -c option to use contextual diffs instead of unified ones. Here's the command:

# mergemaster cv


The first thing mergemaster does is create a temporary root directory and install everything from the relevant sources into it, including the various trees of files that need to be "installed" (processed through installer scripts) rather than simply copied over. This "staging area," by default, is in /var/tmp/temproot. It shows you a listing of files that only exist in /etc and not in the temporary root directory (generally, these are files you have added yourself, so it won't touch them). Then, mergemaster proceeds to compare all the files in /etc and certain other locations with the new ones in /var/tmp/temproot. Whenever it encounters files that don't match, it displays the diff output in whatever pager you have specified in the PAGER environment variable (or more, by default).

When you scroll to the bottom of the diff display (or press > to jump directly to the bottom), you are given a list of choices for what to do with the new file, similar to Listing 19.3.

Listing 19.3. Options for Merging a File in mergemaster

*************** *** 321,326 **** --- 327,333 ----   kern_securelevel="-1" # range: -1..3 ; '-1' is the most insecure   update_motd="YES"     # update version info in /etc/motd (or NO)   start_vinum=""                # set to YES to start vinum + unaligned_print="YES" # print unaligned access warnings on the alpha (or NO).   ##############################################################   ### Define source_rc_confs, the mechanism used by /etc/rc.* ##   Use 'd' to delete the temporary ./etc/defaults/rc.conf   Use 'i' to install the temporary ./etc/defaults/rc.conf   Use 'm' to merge the old and new versions   Use 'v' to view to the differences between the old and new versions again   Default is to leave the temporary file to deal with by hand How should I deal with this? [Leave it for later]

As you can see, the default behavior is to do nothing, leaving the new file in /var/tmp/temproot for you to consider after you've finished running. This makes mergemaster a very safe utility to run.

If you select m to merge the two files, you are dropped into the sdiff environment. This shows you the old and new versions of the changed file, line by line, allowing you to choose between the left (old) and right (new) versions of each:

   *** Type h at the sdiff prompt (%) to get usage help pccard_beep="1"         # pccard beep | pccard_beep="2"       # pccard beep %


The sdiff command options are available by typing h at the prompt.

Tip

Each changed line is merged individually, so the sdiff method can become tedious if you're using it to merge very long files with lots of scattered changes. You may be better off simply making a backup copy of the existing file, replacing it completely in mergemaster, and then merging in the changes later with a text editor and two parallel terminal windows.


Because each changed line is shown on different halves of the same screen, sometimes the two sides look the same because the only differences might be on the right half of the line. This isn't usually a problem (the only time it tends to crop up is on FreeBSD's standardized header lines in which a modification date appears toward the end of the line). You can get around it, though, by specifying a larger screen width with the -w option to mergemaster:

# mergemaster -cv -w 120


Once you're done picking your way through the lines, you're brought back into mergemaster, where you are given yet another chance to review (or even remerge) your changes before moving the new file into place.

Once you're all done, mergemaster asks whether you want to delete what's left of /var/tmp/temproot. If you've left unmerged files to deal with later, select No. You then exit from mergemaster and have the chance to go to /var/tmp/temproot to merge these remaining files by hand.

Troubleshooting mergemaster

The things that can go wrong with mergemaster, fortunately, aren't destructive to the systemespecially if you have backed up your /etc directory. A few kinds of missteps are common, though, such as the following:

  • I accidentally overwrote a critical file in /etc with the generic new version!

    Not to worry. If you kept a backup (for example, /etc.old), you can simply quit mergemaster with Ctrl+C and copy the file out of the backup directory and back into /etc.

  • mergemaster accidentally deleted the rest of the files in /var/tmp/temproot! I was going to get to those!

    Just run mergemaster again and ignore any files you already replaced or merged. Make sure to select No at the last prompt, where it asks whether you want to delete the remainder of /var/tmp/temproot.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net