Опубликован: 06.08.2012 | Уровень: специалист | Доступ: платный
Лекция 32:

Updating the system software

< Лекция 31 || Лекция 32: 1234 || Лекция 33 >
Аннотация: Upgrading kernel and userland; Upgrading the kernel Upgrading the boot files; Upgrading the configuration files Merging /etc/group Mergemaster, second time around.
Ключевые слова: previous, chapter, GET, DATE, tree, CAN, build, system, this, change file, divide, system software, configuration file, planning, system file, prove, root, AND, upgrade, overview, WHERE, FROM, executable program, object file, source file, core, part, UPDATE, kernel, speed, computer, busy, general, install, First, operation, pass, inconsistency, occasional, find, useful, pose, problem, if, new, typical, situational, system call, CASE, with, invalid, perform, SEQUENCE, information, requirements, glue, reinstall, loadable module, issue, configuration, example, Default Configuration, daemon, USER, group, script, look, point, option, AS, target, OLD, remove, Replace, result, end, long, ONE, Last, modification, SEE, clear, NOT, DELETE, Command, ALL, current directory, course, method, directory, hierarchy, private, space, PARAMETER, current source, Add, functionality, aspect, custom, trouble, strategy, addition, release, Copy, error, LIKE, undefined, REFERENCES, mean, synchronization, store, TIME, still, go, boot, boot disk, system disk, SCSI, disk, dedicated, platform, invocation, bootstrap, slice, boot manager, procedure, ASK, output, important, save, try, continue, installation, DUE, real, SAW, mail, security problem, merge, editing, Basic, editor, exposure, directory entry, distribution, security, used, postfix, special, running, EXISTS, set, immutable, change, let, fact, track, safety, MOST, Compare, CVS, ID, periodic, maintenance, bottom, Left, housekeeping, list

In the previous chapter, we looked at how to get an up-to-date FreeBSD source tree. Once you have the sources, you can build various components of the system. The main tool we use for this purpose is make, which we looked at on page 168. The best way to think of upgrading the system is that everything is a matter of changing files. For the purposes of this discussion, you can divide the files on your system into the following categories:

  • The userland, that part of the system software that is not the kernel. Unlike some other operating systems, FreeBSD expects to keep userland and kernel at the same release level. We'll look at the interaction between kernel and userland below.
  • The kernel. You may build a new kernel without updating the sources, of course, if you want to add functionality to the kernel. In this chapter we'll look at upgrading the kernel in the context of a complete system upgrade. We'll consider building a custom kernel in the next chapter, "Chapter 33" , Custom kernels.
  • Support for booting the machine, which is currently performed as a separate step.
  • Configuration files relating to your system. Some of them, such as etc/fstab and etc/rc.conf, overlap with the previous category.
  • The Ports Collection. This doesn't have to be done at the same time as userland and kernel, though if you upgrade to a significant new version of FreeBSD, it's a good idea to upgrade the ports as well. We looked at upgrading ports on page 178.
  • Your own files. They have nothing to do with a software upgrade.

You can make upgrading less onerous by planning in advance. Here are some suggestions:

  • Keep system files and user files on different file systems.
  • Keep careful records of which configuration files you change, for example with RCS, the Revision Control System. This proves to be the most complicated part of the entire upgrade process.

The only files that are upgraded are on the traditional root file system and /usr. No others are affected by an upgrade. Table 32-1 , an abridged version of Table 10-2 on page 188, gives an overview of where the system files come from.

Таблица 32.1. FreeBSD directory hierarchy
Directory name Usage Populated by
/bin Executable programs of general use. make world
/boot Files used when booting the system. make install in /usr/src/sys.
/dev Directory of device nodes. System startup (devfs)
/etc Configuration files used at system startup Install from CD-ROM only, merge master, administrator
/sbin System executables needed at system startup time. make world
/usr/XllR6 X-based programs in the The X11 windowing system. Ports Collection
/usr/bin Standard executable programs that are not needed at system start. make world
/usr/compat A directory containing code for emulated systems, such as Linux. Ports Collection
/usr/games Games. make world
/usr/include Header files for programmers. make world
/usr/lib Library files. make world
/usr/libexec Executable files that are not started directly by the user. make world
/usr/libdata Miscellaneous files used by system utilities. make world
/usr/local Additional programs that are not part of the operating system. Ports collection
/usr/obj Temporary object files created when building the system. make world
/usr/ports The Ports Collection sysinstall, cvs
/usr/sbin System administration programs that are not needed at system startup. make world
/usr/share Miscellaneous read-only files, mainly informative. make world
/usr/src System source files. sysinstall, cvs

Upgrading kernel and userland

The core part of a system upgrade consists of a synchronized update of both kernel and userland. It's relatively simple to do, but depending on the speed of the machine, it may keep the computer busy for several hours. In general, you build and install the userland first, then you build and install the kernel.

The traditional way to build the userland is:

# cd /usr/src
# make world

This operation performs a number of functions, which can be influenced by variables you pass to make. Without any variables, make world performs the following steps:

  • It removes the old build directories and creates new ones. You can skip this step by setting the NOCLEAN variable. Don't set NOCLEAN unless you know exactly why you are doing so, since it can cause inconsistencies that come back to bite you later. In particular, if you do have problcodes after building the world in this manner, you should first go back and perform a complete rebuild without NOCLEAN.
  • It rebuilds and installs build tools, including make, the C compiler and the libraries.
  • It builds the rest of the system, with the exception of the kernel and the boot tools.
  • It installs everything. You can omit this stage by building the buildworld target instead of world.

It does this by building a number of subtargets. Occasionally, you might find it useful to build them individually: make world can pose a chicken-and-egg problem. It creates the userland, and make kernel makes the kernel. Userland and kernel belong together, and if you upgrade the userland first, you may find that the new userland takes advantage of differences in the newer version of the kernel. A typical situation is when a new system call is added to the kernel. In this case, you may find processes exiting with a signal 12 (invalid system call). If this happens, you may have to perform the upgrade with the sequence:

make buildworld
make kernel
(reboot)
make installworld

You'll find information about such requirements in the file /usr/src/UPDATING. Table 32-2 gives an overview of the more useful targets to the top-level Makefile.

Таблица 32.2. Targets for top-level Makefile
Target Purpose
buildworld Rebuild everything, including glue to help do upgrades.
installworld Install everything built by buildworld.
world Perform buildworld and installworld.
update Update your source tree.
most Build user commands, no libraries or include files.
installmost Install user commands, but not libraries or include files.
reinstall If you have a build server, you can NFS mount the source and object directories and do a make reinstall on the client to install new binaries from the most recent build on the server.
buildkernel Build a kernel for your architecture. By default, use the GENERIC kernel configuration file. You can select a different configuration file, say MYKERNEL, with:
# make buildkernel KERNCONF=MYKERNEL

By default, this target builds all the KLDs (Kernel Loadable Modules), which significantly increases the time it takes. If you know that your KLDs will not change, or that you won't be using any, you can skip building them by specifying the -DNO_MODULES flag.

installkernel Install a kernel you have built with buildkernel.
reinstallkernel Install a kernel you have built with buildkernel. Don’t rename the previous kernel directory to kernel.old. Use this target when the previous kernel is not worth keeping.
kernel Build and install a kernel.

Another issue is that the system configuration might have changed. For example, in early 2002 the default configuration for sendmail changed. The process added a daemon user and group, both called smmsp. To install the userland, this user already needed to be present.

The solution to this issue is called mergemaster, a script that helps you to upgrade the configuration files. We'll look at it in more detail below, but at this point you should know that you need to run it with the -p (pre-build) option:

# mergemaster -p

As we've seen in table 32-1 , the installworld target changes a number of directories. Sometimes, though, it leaves old binaries behind: it doesn't remove anything that it doesn't replace. The result can be that you end up using old programs that have long passed their use-by date. One solution to this problem is to look at the last modification date of each program in the directories.

For example, if you see:

$ ls -lrt /usr/sbin
-r-xr-xr-x  1  root  wheel     397  Jul  14  11:36  svr4
-r-xr-xr-x  1  root  wheel     422  Jul  14  11:29  linux
-r-xr-xr-x  1  root  wheel  142080  Jul  13  17:20  sshd
…
-r-xr-xr-x  1  root  wheel   68148  Jul  13  17:16  uuchk
-r-xr-xr-x  1  root  wheel    6840  Jan   5   2002  ispppcontrol
-r-xr-xr-x  1  root  wheel   27996  Apr  21   2001  k5stash
-r-xr-xr-x  1  root  wheel   45356  Apr  21   2001  ktutil
-r-xr-xr-x  1  root  wheel   11124  Apr  21   2001  kdb_util
-r-xr-xr-x  1  root  wheel   6768   Apr  21   2001  kdb init

It's fairly clear that the files dated April 2001 have not just been installed, so they must be out of date. You can use a number of techniques to delete them; one might be:

# find . -mtime +10 | xargs rm

This command removes all files in the current directory (.) that are older than 10 days (+10). Of course, this method will only work if you haven't installed anything in these directories yourself. You shouldn't have done so; that's the purpose of the directory hierarchy /usr/local, to ensure that you keep system files apart from ports and private files.

Be careful with /usr/lib: a number of ports refer to libraries in this directory hierarchy, and if you delete them, the ports will no longer work. In general there's no problem with old libraries in /usr/lib, unless they take up too much space, so you're safer if you don't clean out this directory hierarchy.

Note that you need to specify the KERNCONF parameter to all the targets relating to kernel builds.

< Лекция 31 || Лекция 32: 1234 || Лекция 33 >
Анатолий Федоров
Анатолий Федоров
Россия, Москва, Московский государственный университет им. М. В. Ломоносова, 1989