$RodHat_/search
Console Tips

etcupdate(8) is the three-way merge your /etc has been missing

Published by

This article may contain Amazon affiliate links. I may earn a commission if you buy through them. Disclosure.

Terminal showing etcupdate status listing conflicts in /etc after a FreeBSD source upgrade
AI illustration: RodHat
On this page · 7 sections
  1. Why three-way matters
  2. Seed the baseline once
  3. The two passes around installworld
  4. Dry run first
  5. Conflicts: status and resolve
  6. See what you have diverged on
  7. The cons

installworld does not touch your /etc. It installs binaries and leaves configuration alone, because the people who wrote it have met system administrators. That leaves a gap: new releases change /etc/rc.d scripts, master.passwd, periodic.conf defaults and sshd_config, and your tree sits there carrying last year’s idea of the world. Two ways to handle that: ignore it until something breaks, or merge properly. etcupdate(8) is the second one, and it replaced mergemaster for good reason.

This applies to building from source. If you use freebsd-update, it merges /etc for you during install and you can stop reading, though the conflict markers below will look familiar.

Why three-way matters

mergemaster compared your live file to the new one and asked you to eyeball the diff. It had no idea which differences were yours and which were upstream’s, so every local edit looked like a conflict. etcupdate keeps a copy of the pristine /etc from the previous build, then does a real three-way merge: old pristine, new pristine, your live file. Lines you changed and upstream did not stay. Lines upstream changed and you did not get updated. Only overlapping edits become conflicts.

Seed the baseline once

On a box that has never run it, you need that “old pristine” copy. Extract it from the source tree that matches the system you are running now, before you upgrade:

etcupdate extract -s /usr/src

That populates /var/db/etcupdate/current. If your source tree is already newer than the running system, you have missed the window; check out the revision you built from, or accept that the first merge will be noisy. Do it on every box that does source upgrades, once, and then forget about it.

The two passes around installworld

The order from the Handbook’s source-upgrade procedure is the part people get wrong:

make buildworld && make buildkernel
make installkernel
shutdown -r now          # boot the new kernel

etcupdate -p             # pre-world: only what installworld needs
make installworld
etcupdate                # the real merge
make check-old && make delete-old

etcupdate -p is the odd one. It updates only the handful of files installworld requires, notably users and groups in /etc/master.passwd and /etc/group, because the new world may install files owned by an account that does not exist yet. Skip it and you can hit a failure partway through the install. Then the full run after installworld handles the rest.

Dry run first

Because it edits a directory the machine boots from, look before you leap:

etcupdate -n

-n is a dry run: it reports what it would merge without changing anything. Run it on the box and read the list. I would rather find out that rc.conf-adjacent files are about to change on my schedule than at the next reboot. If you keep a jail’s or chroot’s /etc somewhere else, -D /path/to/root points the whole thing at that tree, and -s names the source tree if it is not /usr/src.

Conflicts: status and resolve

When a three-way merge cannot decide, etcupdate leaves the file with conflict markers in /var/db/etcupdate/conflicts and keeps your live copy untouched until you say otherwise. List what is outstanding:

etcupdate status

Then walk them:

etcupdate resolve

Each file gets a prompt where you can postpone, view the diff, edit the merged result, or take one side wholesale (mf keeps yours, tf takes the new one; the help option at the prompt prints the full list). Taking “theirs” on master.passwd is how you lose a user, so read before you type. After editing out the markers, mark the file resolved and etcupdate installs it. Conflict markers left in a file that you then install will produce a very educational boot.

Anything you postpone stays on the list. etcupdate status is cheap enough to put in your post-upgrade checklist next to the make delete-old step.

See what you have diverged on

Between upgrades, etcupdate diff shows how your live /etc differs from the pristine baseline. That is a free audit of every local edit on the box, and it pairs well with verifying a tree against an mtree spec when you want to know whether /etc drifted without anyone telling you. If most of the diff is rc.conf lines, you probably wanted sysrc to manage them in the first place.

The cons

  • It needs the baseline. Seed it before the upgrade, not after, or the first merge degrades into guesswork.
  • Conflict resolution is still manual and still yours. A tool that merges cleanly 95 percent of the time makes the other 5 percent easy to rubber-stamp.
  • It only covers /etc. Config living in /usr/local/etc from packages is a separate problem with its own .sample files.
  • Take a boot environment with bectl before you start. A merge that eats master.passwd is much more survivable when rollback is one command.

Whatever you use, do the merge on purpose. A box that is three releases deep with an unmerged /etc is not stable, it is just unexamined.