View Single Post
  #4   (View Single Post)  
Old 6th February 2016
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,983
Default

The OpenBSD GENERIC kernels include an install target for make(1). Here's an excerpt from a kernel Makefile.
Code:
cmp -s bsd /bsd || ln -f /bsd /obsd
        cp bsd /nbsd
        mv /nbsd /bsd
If the newly built kernel is different from the one in the root directory, it creates a linked directory entry under the new name /obsd. Then it copies the new kernel to the root directory with the temporary name /nbsd, and only after the copy has completed does it issue the move.

At every step, the old kernel is recoverable, though the admin may need to refer to it by the name /obsd. The copy command may fail, or the OS may fail. If so, the /bsd file is left unaltered.

The move command afterwards is on the same filesystem and as albator stated is relatively brief, since it only touches metadata. As the original kernel file /bsd was linked as /obsd, none of that file's sectors will be touched at all during the move process. The move command will merely unlink the name /bsd from that file, and apply it instead to the /nbsd file which was already safely copied. This is because the /bsd file and /obsd file were linked -- these directory entries point to the same file on disk.

--

There are other options to consider for increasing data integrity. Consider enabling sync and disabling softdep, if optionally used on the filesystem in question. See mount(8).

Last edited by jggimi; 6th February 2016 at 01:00 AM. Reason: clarity
Reply With Quote