LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1807|回复: 17

谁能帮我翻译这篇文章《FreeBSD From Scratch》

[复制链接]
发表于 2003-10-16 09:24:01 | 显示全部楼层 |阅读模式
FreeBSD From Scratch
Jens Schweikhardt
schweikh@FreeBSD.org

Copyright © 2002 by Jens Schweikhardt

$FreeBSD: doc/en_US.ISO8859-1/articles/fbsd-from-scratch/article.sgml,v 1.2 2003/08/14 19:54:04 simon Exp $


FreeBSD is a registered trademark of Wind River Systems, Inc. This is expected to change soon.

Adobe, Acrobat, Acrobat Reader, and PostScript are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States and/or other countries.

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this document, and the FreeBSD Project was aware of the trademark claim, the designations have been followed by the ``™'' or the ``®'' symbol.

[ Split HTML / Single HTML ]

--------------------------------------------------------------------------------

This article describes my efforts at FreeBSD From Scratch: a fully automated installation of a customized FreeBSD system compiled from source, including compilation of all your favorite ports and configured to match your idea of the perfect system. If you think make world is a wonderful concept, FreeBSD From Scratch extends it to make evenmore.


--------------------------------------------------------------------------------

1 Introduction
Have you ever upgraded your system with make world? There is a problem if you have only one system on your disks. If the installworld fails partway through, you are left with a broken system that might not even boot any longer. Or maybe the installworld runs smoothly but the new kernel does not boot. Then it is time to reach for the Fixit CD and dig for those backups you have taken half a year ago.

I believe in the ``wipe your disks when upgrading systems'' paradigm. Wiping disks, or rather partitions, makes sure there is no old cruft left lying around, something which most upgrade procedures just do not care about. But wiping the partitions means you have to also recompile/reinstall all your ports and packages and then redo all your carefully crafted configuration tweaks. If you think that this task should be automated as well, read on.


--------------------------------------------------------------------------------

2 Why would I (not) want FreeBSD From Scratch?
This is a legitimate question. We have sysinstall and the well known way to compile the kernel and the userland tools.

The problem with sysinstall is that it is severely limited in what, where and how it can install.

It is normally used to install pre-built distribution sets and packages from some other source (CD, DVD, FTP). It cannot install the result of a make buildworld.

It cannot install a second system under a directory in a running system.

It cannot install in Vinum partitions.

It cannot compile ports, only install precompiled packages.

It is hard to script or to make arbitrary post-installation changes.

Last but not least, sysinstall is semi-officially at its End-Of-Life.

The well known way to build and install the world, as described in the Handbook, by default replaces the existing system. Only the kernel and modules are saved. System binaries, headers and a lot of other files are overwritten; obsolete files are still present and can cause surprises. If the upgrade fails for any reason, it may be hard or even impossible to restore the previous state of the system.

FreeBSD From Scratch solves all these problems. The strategy is simple: use a running system to install a new system under an empty directory tree, while new partitions are mounted appropriately in that tree. Many config files can be copied to the appropriate place and mergemaster(8) can take care of those that cannot. Arbitrary post-configuration of the new system can be done from within the old system, up to the point where you can chroot to the new system. In other words, we go through three stages, where each stage consists of either running a shell script or invoke make:

stage_1.sh: Create a new bootable system under an empty directory and merge or copy as many files as are necessary. Then boot the new system.

stage_2.sh: Install desired ports.

stage_3.mk: Do post-configuration for software installed in previous stage.

Once you have used FreeBSD From Scratch to build a second system and found it works satisfactorily for a couple of weeks, you can then use it again to reinstall the original system. From now on, whenever you feel like an update is in order, you simply toggle the partitions you want to wipe and reinstall.

Maybe you have heard of or even tried Linux From Scratch, or LFS for short. LFS also describes how to build and install a system from scratch in empty partitions using a running system. The focus in LFS seems to be to show the role of each system component (such as kernel, compiler, devices, shell, terminal database, etc) and the details of each component's installation. FreeBSD From Scratch does not go into that much detail. My goal is to provide an automated and complete installation, not explaining all the gory details that go on under the hood when making the world. In case you want to explore FreeBSD at this level of detail, start looking at /usr/src/Makefile and follow the actions of a make buildworld.

There are also downsides in the approach taken by FreeBSD From Scratch that you should bear in mind.

While compiling the ports during stage two the system can not be used for its usual duties. If you run a production server you have to consider the downtime caused by stage two. The ports compiled by stage_2.sh below require about 4 hours to build on an AMD1800+ SCSI system with 10krpm disks and 1GB of RAM.


--------------------------------------------------------------------------------

3 Prerequisites
For going the FreeBSD From Scratch way, you need to have:

A running FreeBSD system with sources and a ports tree.

At least one unused partition where the new system will be installed.

Experience with running mergemaster(8). Or at least no fear doing so.

If you have no or only a slow link to the Internet: the distfiles for your favorite ports.

Basic knowledge of shell scripting with the Bourne shell, sh(1).

Finally, you should also be able to tell your boot loader how to boot the new system, either interactively, or by means of a config file.


--------------------------------------------------------------------------------

4 Stage One: System Installation
The following is my stage_1.sh. You need to customize it in various places to match your idea of the ``perfect system''. I have tried to extensively comment the places you should adapt. The points to ponder are:

Partition layout.

I do not subscribe to the idea of a single huge partition for the whole system. My systems generally have at least one partition for /, /usr and /var with /tmp symlinked to /var/tmp. In addition I share the file systems for /home (user homes), /home/ncvs (FreeBSD CVS repository replica), /usr/ports (the ports tree), /src (various checked out src trees) and /share (other shared data without the need for backups, like the news spool).

Luxury items.

What you want immediately after booting the new system and even before starting stage two. In my case this is shells/zsh because this is the login shell for my account as specified in /etc/passwd. Strictly speaking you can do without luxury items, because all you need to do is log in as root and run the next stage.

The reason for not simply installing all my beloved ports during stage one is that in theory and in practice there are bootstrap and consistency issues: stage one has your old kernel running, but the chrooted environment consists of new binaries and headers. If the new system for example supports a new system call (according to its headers), some configure-type script might try to use it and get killed because it executes on the old kernel. I have seen other issues when I tried building lang/perl5.

Before you run stage_1.sh make sure you have completed the usual tasks in preparation for make installworld installkernel, like:

configured your kernel config file

successfully completed make buildworld

successfully completed make buildkernel KERNCONF=whatever

When you run stage_1.sh for the first time, and the config files copied from your running system to the new system are not up-to-date with respect to what is under /usr/src, mergemaster will ask you how to proceed. I recommend merging the changes. If you get tired of going through the dialogues you can simply update the files on your running system once (Only if this is an option. You probably do not want to do this if one of your systems runs -STABLE and the other -CURRENT. The changes may be incompatible). Subsequent mergemaster invocations will detect that the RCS version IDs match those under /usr/src and skip the file.

The stage_1.sh script will stop at the first command that fails (returns a non-zero exit status) due to set -e, so you cannot overlook errors. You should correct any errors in your version of stage_1.sh before you go on.

In stage_1.sh we invoke mergemaster. Even if none of the files requires a merge, it will display and ask at the end

*** Comparison complete

Do you wish to delete what is left of /var/tmp/temproot.stage1? [no] no
Please answer no or just hit Enter. The reason is that mergemaster will have left a few zero sized files below /var/tmp/temproot.stage1 which will be copied to the new system later (unless already there).

After that it will list the files it installed, making use of a pager (more(1) by default, optionally less(1)):

*** You chose the automatic install option for files that did not
    exist on your system.  The following were installed for you:
      /newroot/etc/defaults/rc.conf
      ...
      /newroot/COPYRIGHT

(END)
Type q to quit the pager. Then you will be informed about login.conf:

*** You installed a login.conf file, so make sure that you run
    '/usr/bin/cap_mkdb /newroot/etc/login.conf'
    to rebuild your login.conf database

    Would you like to run it now? y or n [n]
The answer does not matter since we will run cap_mkdb(1) in any case.

Everything stage_1.sh does is logged to stage_1.log for you to examine if you wish to do so.

Here is the author's stage_1.sh, which you need to modify substantially, especially steps 1, 2, 5 and 6.

Warning: Please pay attention to the newfs(8) commands. While you can not create new file systems on mounted partitions, the script will happily erase any unmounted /dev/da3s1a, /dev/vinum/var_a and /dev/vinum/usr_a. This can be enough to ruin your day, so be sure to modify the device names.

#!/bin/sh
#
# stage_1.sh - FreeBSD From Scratch, Stage 1: System Installation.
#              Usage: ./stage_1.sh
#
# $FreeBSD: doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_1.sh,v 1.1 2003/03/08 08:26:10 schweikh Exp $

set -x -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin

# Prerequisites:
#
# a) Successfully completed "make buildworld" and "make buildkernel"
# b) Unused partitions (at least one for the root fs, probably more for
#    the new /usr and /var, to your liking.)

# Root mount point where you create the new system. Because it is only
# used as a mount point, no space will be used on that file system as all
# files are of course written to the mounted file system(s).
DESTDIR=/newroot
SRC=/usr/src         # Where your src tree is.

# ---------------------------------------------------------------------------- #
# Step 1: Create an empty directory tree below $DESTDIR.
# ---------------------------------------------------------------------------- #

step_one () {
  # The new root file system. Mandatory.
  # Change device names (DEV_*) or risk foot shooting.
  DEV_ROOT=/dev/da3s1a
  mkdir -p ${DESTDIR}
  newfs ${DEV_ROOT}
  tunefs -n enable ${DEV_ROOT}
  mount -o noatime ${DEV_ROOT} ${DESTDIR}

  # Additional file systems and initial mount points. Optional.
  DEV_VAR=/dev/vinum/var_a
  newfs ${DEV_VAR}
  tunefs -n enable ${DEV_VAR}
  mkdir -m 755 ${DESTDIR}/var
  mount -o noatime ${DEV_VAR} ${DESTDIR}/var

  DEV_USR=/dev/vinum/usr_a
  newfs ${DEV_USR}
  tunefs -n enable ${DEV_USR}
  mkdir -m 755 ${DESTDIR}/usr
  mount -o noatime ${DEV_USR} ${DESTDIR}/usr

  mkdir -m 755 -p ${DESTDIR}/usr/ports
  mount /dev/vinum/ports ${DESTDIR}/usr/ports

  # Now create all the other directories. Mandatory.
  cd ${SRC}/etc; make distrib-dirs DESTDIR=${DESTDIR}
  # My personal preference is to symlink tmp -> var/tmp. Optional.
  cd ${DESTDIR}; rmdir tmp; ln -s var/tmp
}

# ---------------------------------------------------------------------------- #
# Step 2: Fill the empty /etc directory tree and put a few files in /.
# ---------------------------------------------------------------------------- #

step_two () {
  # Add or remove from this list at your discretion. Mostly mandatory.
  for f in \
    /.profile \
    /etc/group \
    /etc/hosts \
    /etc/inetd.conf \
    /etc/ipfw.conf \
    /etc/make.conf \
    /etc/master.passwd \
    /etc/nsswitch.conf \
    /etc/ntp.conf \
    /etc/printcap \
    /etc/profile \
    /etc/rc.conf \
    /etc/resolv.conf \
    /etc/start_if.xl0 \
    /etc/ttys \
    /etc/ppp/* \
    /etc/mail/aliases \
    /etc/mail/aliases.db \
    /etc/mail/hal9000.mc \
    /etc/mail/service.switch \
    /etc/ssh/*key* \
    /etc/ssh/*_config \
    /etc/X11/XF86Config-4 \
    /boot/splash.bmp \
    /boot/loader.conf \
    /boot/device.hints ; do
    cp -p ${f} ${DESTDIR}${f}
  done
  # Delete mergemaster's temproot, if any.
  TEMPROOT=/var/tmp/temproot.stage1
  if test -d ${TEMPROOT}; then
    chflags -R 0 ${TEMPROOT}
    rm -rf ${TEMPROOT}
  fi
  mergemaster -i -m ${SRC}/etc -t ${TEMPROOT} -D ${DESTDIR}
  cap_mkdb ${DESTDIR}/etc/login.conf
  pwd_mkdb -d ${DESTDIR}/etc -p ${DESTDIR}/etc/master.passwd

  # Mergemaster does not create empty files, e.g. in /var/log. Do so now,
  # but do not clobber files that may have been copied in the loop above.
  cd ${TEMPROOT}
  find . -type f | sed 's,^\./,,' |
  while read f; do
    if test -r ${DESTDIR}/${f}; then
      echo "${DESTDIR}/${f} already exists; not copied"
    else
      echo "Creating empty ${DESTDIR}/${f}"
      cp -p ${f} ${DESTDIR}/${f}
    fi
  done
  chflags -R 0 ${TEMPROOT}
  rm -rf ${TEMPROOT}
}

# ---------------------------------------------------------------------------- #
# Step 3: Install world.
# ---------------------------------------------------------------------------- #

step_three () {
  cd ${SRC}
  make installworld DESTDIR=${DESTDIR}
}

# ---------------------------------------------------------------------------- #
# Step 4: Install kernel and modules.
# ---------------------------------------------------------------------------- #

step_four () {
  cd ${SRC}
  # The loader.conf and device.hints are required by the installkernel target.
  # If you have not copied them in Step 2, cp them as shown in the next 2 lines.
  #   cp sys/boot/forth/loader.conf ${DESTDIR}/boot/defaults
  #   cp sys/i386/conf/GENERIC.hints ${DESTDIR}/boot/device.hints
  make installkernel DESTDIR=${DESTDIR} KERNCONF=HAL9000
}

# ---------------------------------------------------------------------------- #
# Step 5: Install or modify a few essential files.
# ---------------------------------------------------------------------------- #

step_five () {
  # Create /etc/fstab; mandatory. Modify to match your devices.
  cat <<EOF >${DESTDIR}/etc/fstab
# Device         Mountpoint          FStype    Options              Dump Pass#
/dev/da3s1b      none                swap      sw                   0    0
/dev/da4s2b      none                swap      sw                   0    0
/dev/da3s1a      /                   ufs       rw                   1    1
/dev/da1s2a      /src                ufs       rw                   0    2
/dev/da2s2f      /share              ufs       rw                   0    2
/dev/vinum/var_a /var                ufs       rw                   0    2
/dev/vinum/usr_a /usr                ufs       rw                   0    2
/dev/vinum/home  /home               ufs       rw                   0    2
/dev/vinum/ncvs  /home/ncvs          ufs       rw,noatime           0    2
/dev/vinum/ports /usr/ports          ufs       rw,noatime           0    2
#
/dev/cd0         /dvd                cd9660    ro,noauto            0    0
/dev/cd1         /cdrom              cd9660    ro,noauto            0    0
proc             /proc               procfs    rw                   0    0
EOF

  # More directories; optional.
  mkdir -m 755 -p ${DESTDIR}/src;       chown root:wheel ${DESTDIR}/src
  mkdir -m 755 -p ${DESTDIR}/share;     chown root:wheel ${DESTDIR}/share
  mkdir -m 755 -p ${DESTDIR}/dvd;       chown root:wheel ${DESTDIR}/dvd
  mkdir -m 755 -p ${DESTDIR}/home;      chown root:wheel ${DESTDIR}/home
  mkdir -m 755 -p ${DESTDIR}/usr/ports; chown root:wheel ${DESTDIR}/usr/ports
  # Setup time zone info; pretty much mandatory.
  cp ${DESTDIR}/usr/share/zoneinfo/Europe/Berlin ${DESTDIR}/etc/localtime
  if test -r /etc/wall_cmos_clock; then
     cp -p /etc/wall_cmos_clock ${DESTDIR}/etc/wall_cmos_clock
  fi
}

# ---------------------------------------------------------------------------- #
# Step 6: Things important to me when I first login to a new system.
# NOTE: Do not install too many binaries here. With the old system running and
# the new binaries and headers installed you are likely to run into bootstrap
# problems. Ports should be compiled after you have booted in the new system.
# ---------------------------------------------------------------------------- #

step_six () {
  chroot ${DESTDIR} sh -c "cd /usr/ports/shells/zsh; make clean install clean"
  chroot ${DESTDIR} sh -c "cd /etc/mail; make install"  # configure sendmail

  # Without the compat symlink the linux_base files end up on the root fs:
  cd ${DESTDIR}; mkdir -m 755 usr/compat
  chown root:wheel usr/compat; ln -s usr/compat
  mkdir -m 755 usr/compat/linux
  mkdir -m 755 boot/grub

  # Make spooldirs for the printers in my /etc/printcap.
  cd ${DESTDIR}/var/spool/output/lpd; mkdir -p as od ev te lp da
  touch ${DESTDIR}/var/log/lpd-errs

  # More files I want to inherit from the old system.
  for f in \
    /var/cron/tabs/root \
    /var/mail/* \
    /boot/grub/*; do
    cp -p ${f} ${DESTDIR}${f}
  done

  # If you do not have /home on a shared partition, you may want to copy it:
  # mkdir -p ${DESTDIR}/home
  # cd /home; tar cf - . | (cd ${DESTDIR}/home; tar xpvf -)

  # Starting with FreeBSD 5.x, perl lives in /usr/local/bin but many scripts
  # use a hardcoded #!/usr/bin/perl; use a symlink to make them work.
  cd ${DESTDIR}/usr/bin; ln -s ../local/bin/perl
  cd ${DESTDIR}/usr; rmdir src; ln -s ../src/current src
}

do_steps () {
  step_one
  step_two
  step_three
  step_four
  step_five
  step_six
}

do_steps 2>&1 | tee stage_1.log

# EOF $RCSfile: stage_1.sh,v $    vim: tabstop=2:expandtab:
Download stage_1.sh.

Running this script installs a system that when booted provides:

Inherited users and groups.

Firewalled Internet connectivity over Ethernet and PPP.

Correct time zone and NTP.

Some more minor configuration, like /etc/ttys and inetd.

Other areas are prepared for configuration, but will not work until stage two is completed. For example we have copied files to configure printing and X11. Printing however is likely to need applications not found in the base system, like PostScript&reg; utilities. X11 will not run before we have compiled the server, libraries and programs.


--------------------------------------------------------------------------------

5 Stage Two: Ports Installation
Note: It is also possible to install the (precompiled) packages at this stage, instead of compiling ports. In this case, stage_2.sh would be nothing more than a list of pkg_add commands. I trust you know how to write such a script. Here we concentrate on the more flexible and traditional way of using the ports.

The following stage_2.sh script is how I install my favorite ports. It can be run any number of times and will skip all ports that are already installed. It supports the dryrun option (-n) to just show what would be done. You will certainly want to edit the list of ports, and possibly change a few environment variables.

The list of ports consists of lines with two or more space separated words: the category and the port, optionally followed by an installation command that will compile and install the port (default: make install). Empty lines and lines starting with # are ignored. Most of the time it suffices to only name category and port. A few ports however can be fine tuned by specifying make variables, e.g.:

www mozilla make WITHOUT_MAILNEWS=yes WITHOUT_CHATZILLA=yes install
mail procmail make BATCH=yes install
In fact you can specify arbitrary shell commands, so you are not restricted to simple make invocations:

java linux-sun-jdk13 yes | make install
news inn-stable CONFIGURE_ARGS="--enable-uucp-rnews --enable-setgid-inews" make install
Note that the line for news/inn-stable is an example for a one-shot shell variable assignment to CONFIGURE_ARGS. The port Makefile will use this as an initial value and augment some other essential args. The difference to specifying a make variable on the command line with

news inn-stable make CONFIGURE_ARGS="--enable-uucp-rnews --enable-setgid-inews" install
is that the latter will override instead of augment. It depends on the particular port which method you want.

Be careful that your ports do not use an interactive install, i.e. they should not try to read from stdin other than what you explicitly give them on stdin. If they do, they will read the next line(s) from your list of ports in the here-document and get confused. If stage_2.sh mysteriously skips a port or stops processing, this is likely the reason.

Here is stage_2.sh. It creates a log file named LOGDIR/category+port for each port it actually installs. If you do not have stage_2.sh on a shared partition make sure you copy it to the new system before you boot it.

#!/bin/sh
#
# stage_2.sh - FreeBSD From Scratch, Stage 2: Ports Installation.
#              Usage: ./stage_2.sh
#
# $FreeBSD: doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_2.sh,v 1.1 2003/03/08 08:26:10 schweikh Exp $

DBDIR=/var/db/pkg
PORTS=/usr/ports
LOGDIR=/home/root/setup/ports.log; mkdir -p ${LOGDIR}

# Set some variables used by more than one port.
PAPERSIZE=a4;    export PAPERSIZE
USA_RESIDENT=NO; export USA_RESIDENT

MYNAME=$(basename $0)
usage () {
    exec >&2
    echo "usage: ${MYNAME} [-hn]"
    echo ""
    echo "  Options:"
    echo "  -h    Print this help text."
    echo "  -n    Dryrun: just show what would be done."
    echo ""
    exit 1
}

args=`getopt hn $*`
if test $? != 0; then
    usage
fi
set -- $args
DRYRUN=
for i; do
    case "$i" in
    -n) DRYRUN=yes;;
    --) break;;
    *) usage;;
    esac
done

cat << EOF |
lang perl5
security sudo
x11-servers XFree86-4-Server
x11 wrapper
x11 XFree86-4-libraries
x11 XFree86-4-clients
x11-fonts XFree86-4-font75dpi
x11-fonts XFree86-4-font100dpi
x11-fonts XFree86-4-fontScalable
x11-fonts urwfonts
x11-fonts webfonts
x11-toolkits open-motif
x11 rxvt
x11-wm ctwm
security openssh-askpass
astro xplanet
astro setiathome make BATCH=yes install
astro xephem
editors vim
print ghostscript-gnu make A4=yes BATCH=yes install
print a2ps-a4
print psutils-a4
print gv
print acroread5
print transfig
archivers zip
archivers unzip
java linux-sun-jdk13 yes | make install
java jdk13
www apache2
www weblint
www amaya
www mozilla make WITHOUT_MAILNEWS=yes WITHOUT_CHATZILLA=yes install
www netscape48-navigator
www checkbot
www privoxy
graphics xfig
graphics xv
graphics fxtv
lang expect
news tin
net freebsd-uucp
net cvsup-without-gui
net pathchar make NO_CHECKSUM=yes install
ftp wget
ftp ncftp3
textproc ispell
german ispell-neu
german ispell-alt
textproc docproj make JADETEX=yes HAVE_MOTIF=yes install
sysutils samefile
sysutils pstree
sysutils mkisofs
sysutils cdrtools
sysutils grub
devel ddd
devel ctags
devel ElectricFence
mail procmail make BATCH=yes install
mail metamail
mail mutt
mail spamoracle
emulators mtools
sysutils portupgrade
news inn-stable CONFIGURE_ARGS="--enable-uucp-rnews --enable-setgid-inews" make install
misc figlet-fonts
textproc gmat
EOF
while read CATEGORY NAME CMD; do
    case "${CATEGORY}" in
    \#*) continue;;
    '') continue;;
    esac
    DIR="${PORTS}/${CATEGORY}/${NAME}"
    if ! test -d "${DIR}"; then
        echo "$DIR does not exist -- ignored"
        continue
    fi
    cd ${DIR}
    PKGNAME=`make -V PKGNAME`
    if test -d "${DBDIR}/${PKGNAME}"; then
        echo "${CATEGORY}/${NAME} already installed as ${PKGNAME}"
        continue
    fi
    LOG="${LOGDIR}/${CATEGORY}+${NAME}"
    echo "===> Installing ${CATEGORY}/${NAME}; logging to ${LOG}"
    test -n "${CMD}" || CMD="make install"
    if test -n "${DRYRUN}"; then
        echo "${CMD}"
        continue
    fi
    date "++++++++++ %v %T +++++++++" > ${LOG}
    echo "CMD: ${CMD}" >> ${LOG}
    (
        make clean
        eval "${CMD}"
        # make clean # Uncomment if diskspace is tight under ${PORTS}.
    ) 2>&1 | tee -a ${LOG}
done

# Install StarOffice as a package, created on old the system with
# "make package", because the port uses an interactive X11 install.
#pkg_add ${PORTS}/editors/staroffice52/staroffice-*.tbz

# EOF $RCSfile: stage_2.sh,v $    vim: tabstop=4:
Download stage_2.sh.


--------------------------------------------------------------------------------

6 Stage Three
You have installed your beloved ports during stage two. Some ports require a little bit of configuration. This is what stage three, the post-configuration is for. I could have integrated this post-configuration at the end of the stage_2.sh script. However, I think there is a conceptual difference between installing a port and modifying its out-of-the-box configuration that warrants a separate stage.

I have chosen to implement stage three as a Makefile because this allows easy selection of what you want to configure simply by running:

# make -f stage_3.mk target
As with stage_2.sh make sure you have stage_3.mk available after booting the new system, either by putting it on a shared partition or copying it somewhere on the new system.

# stage_3.mk - FreeBSD From Scratch, Stage 3: Ports Post-Configuration.
#              Usage: make -f stage_3.mk all     (config everything)
#                or   make -f stage_3.mk target  (to just config target)
#
# It is a good idea to make sure any target can be made more than
# once without ill effect.
#
# $FreeBSD: doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_3.mk,v 1.1 2003/03/08 08:26:10 schweikh Exp $

.POSIX:

message:
    @echo "lease use one of the following targets:"
    @echo "config_apache"
    @echo "config_inn"
    @echo "config_javaplugin"
    @echo "config_privoxy"
    @echo "config_setiathome"
    @echo "config_sgml"
    @echo "config_sudo"
    @echo "config_TeX"
    @echo "config_tin"
    @echo "config_uucp"
    @echo "all -- all of the above"

all: config_apache \
    config_inn \
    config_javaplugin \
    config_privoxy \
    config_setiathome \
    config_sgml \
    config_sudo \
    config_TeX \
    config_tin \
    config_uucp

config_apache:
    # 1. Modify httpd.conf.
    perl -pi \
    -e 's/#ServerName new.host.name/ServerName hal9000.s.shuttle.de/;' \
    -e 's/^ServerAdmin.*/ServerAdmin schweikh\@schweikhardt.net/;' \
    -e 's,/usr/local/www/cgi-bin/,/home/opt/www/cgi-bin/,;' \
      /usr/local/etc/apache2/httpd.conf
    # 2. Restore symlinks to web pages.
    cd /usr/local/www/data; \
    ln -fs /home/schweikh/prj/homepage schweikhardt.net; \
    ln -fs /home/opt/www/test .

config_inn:
    pw usermod -n news -d /usr/local/news -s /bin/sh
    # Give the news system its initial configuration.
    cd /home/root/setup; \
    install -C -o news -g news -m 664 active newsgroups /usr/local/news/db
    # The innd.sh that comes with the port is broken, it
    # checks for history.pag which does not exist.
    cd /home/root/setup; \
    install -C -o root -g wheel -m 555 innd.sh /usr/local/etc/rc.d
    # Configure storage method.
    cd /home/root/setup;      \
    printf "%s\n%s\n%s\n%s\n" \
        "method tradspool {"  \
        "  newsgroups: *"     \
        "  class: 0"          \
        "}"                   \
    >storage.conf;            \
    install -C -o news -g news -m 664 storage.conf /usr/local/news/etc
    # Configure newsfeeds.
    printf "%s\n%s\n" \
        "ME:*::"      \
        "shuttle/news2.shuttle.de:!junk,!control:B32768/512,Tf,Wfb:" \
    >/usr/local/news/etc/newsfeeds
    # Configure inn.conf.
    perl -pi                                                   \
    -e 's/^(organization:\s*).*/$$1 An Open Pod Bay Door/;'    \
    -e 's/^(pathhost:\s*).*/$$1 hal9000.schweikhardt.net/;'    \
    -e 's/^(server.*/$$1 localhost/;'                        \
    -e 's/^(domain.*/$$1 schweikhardt.net/;'                 \
    -e 's/^(fromhost.*/$$1 schweikhardt.net/;'               \
    -e 's,^(moderatormailer.*,$$1 \%s\@moderators.isc.org,;' \
    -e 's,/usr/local/news/spool,/share/news/spool,;'           \
    /usr/local/news/etc/inn.conf

config_javaplugin:
    cd /usr/local/lib/netscape-linux/plugins; \
    if ! test -h javaplugin.so; then \
        ln -s ../../../linux-sun-jdk1.3.1/jre/plugin/i386/ns4/javaplugin.so; \
    fi; \
    ls -l javaplugin.so

config_privoxy:
    install -C -o root -g wheel -m 644 config /usr/local/etc/privoxy

config_setiathome:
    perl -pi \
    -e 's,^.*seti_wrkdir.*#,seti_wrkdir=/home/nobody/setiathome #,;' \
    /usr/local/etc/rc.setiathome.conf

config_sgml:
    cp -p /usr/local/share/gmat/sgml/ISO_8879-1986/entities/* \
          /usr/local/share/sgml/docbook/4.1

config_sudo:
    if ! grep -q schweikh /usr/local/etc/sudoers; then \
        echo 'schweikh ALL = (ALL) NOPASSWD: ALL' >> /usr/local/etc/sudoers; \
    fi

config_TeX:
    # textproc/docproj advises: to typeset the FreeBSD Handbook with JadeTeX,
    # change the following settings to the listed values:
    perl -pi                                   \
    -e 's/^% original texmf.cnf/% texmf.cnf/;' \
    -e 's/^(hash_extra\s*=).*/$$1 60000/;'     \
    -e 's/^(pool_size\s*=).*/$$1 1000000/;'    \
    -e 's/^(max_strings\s*=).*/$$1 70000/;'    \
    -e 's/^(save_size\s*=).*/$$1 10000/;'      \
    /usr/local/share/texmf/web2c/texmf.cnf

config_tin:
    # Point tin to our files.
    printf "%s\n%s\n%s\n"                              \
        "activefile=/usr/local/news/db/active"         \
        "newsgroupsfile=/usr/local/news/db/newsgroups" \
        "spooldir=/share/news/spool/articles"          \
    >/usr/local/etc/tin.defaults

config_uucp:
    # UUCP expects to find /usr/bin/rnews.
    cd /usr/bin; ln -fs ../local/news/bin/rnews .
    # Actual UUCP configuration.
    echo nodename js2015           > /usr/local/etc/uucp/config
    echo shuttle js2015 `cat uucp` > /usr/local/etc/uucp/call
    printf 'port tcp\ntype tcp\n'  > /usr/local/etc/uucp/port
    printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
        "call-login    *"                 \
        "call-password *"                 \
        "time          any"               \
        "system        shuttle"           \
        "address       mail.s.shuttle.de" \
        "commands      rmail rnews"       \
        "port          tcp"               \
    >/usr/local/etc/uucp/sys
    cd /usr/local/etc/uucp; chown uucp:uucp *; chmod o-rwx *
    # Trigger uucico after booting.
    mkdir -p /usr/local/etc/rc.d; cp uucp.sh /usr/local/etc/rc.d

# EOF $RCSfile: stage_3.mk,v $    vim: tabstop=4:
Download stage_3.mk.


--------------------------------------------------------------------------------

7 Limitations
The automated installation of a port may prove difficult if it is interactive and does not support make BATCH=YES install. For a few ports the interaction is nothing more than typing yes when asked to accept some license. If such input is read from the standard input, we simply pipe the appropriate answers to the installation command (usually make install; this is how we deal with java/linux-sun-jdk13 in stage_2.sh).

This strategy for example does not work for editors/staroffice52, which requires that X11 is running. The installation procedure involves a fair amount of clicking and typing, so it cannot be automated like other ports can. However the following workaround does the trick for me: first I create a staroffice package on the old system with

# cd /usr/ports/editors/staroffice52
# make package
===>  Building package for staroffice-5.2_1
Creating package /usr/ports/editors/staroffice52/staroffice-5.2_1.tbz
Registering depends:.
Creating bzip'd tar ball in '/usr/ports/editors/staroffice52/staroffice-5.2_1.tbz'
and during stage two I simply use:

# pkg_add /usr/ports/editors/staroffice52/staroffice-5.2_1.tbz
You should also be aware of upgrade issues for config files. In general you do not know when and if the format or contents of a config file changes. A new group may be added to /etc/group, or /etc/passwd may gain another field. All of this has happened in the past. Simply copying a config file from the old to the new system may be enough most of the time, but in these cases it was not. If you update a system the canonical way (by overwriting the old files) you are expected to use mergemaster to deal with changes where you effectively want to merge your local config with potentially new items. Unfortunately, mergemaster is only available for base system files, not for anything installed by ports. Some third party software seems to be especially designed to keep me on my toes by changing the config file format every fortnight. All you can do is be alert, especially when the major version number bumps. In the past I had to tweak or rewrite files for web servers, news servers and readers. All software actively maintained is a prime candidate for config file scrutiny.

I have used FreeBSD From Scratch several times to update a 5-CURRENT to 5-CURRENT, i.e. I have never tried to install a 5-CURRENT from a 4-STABLE system or vice versa. Due to the number of changes between different major release numbers I would expect this process to be a bit more involved. Using FreeBSD From Scratch for upgrades within the realm of 4-STABLE should work painlessly (although I have not yet tried it.) Users of 4-STABLE may want to consider the following areas:

If you do not use the device file system (devfs) you may want to create devices for some of your hardware with MAKEDEV(8) in stage one, step six.


--------------------------------------------------------------------------------

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.
 楼主| 发表于 2003-10-16 09:26:10 | 显示全部楼层
我的信箱:renhw895@sohu.com, 谢谢!

文章出处:
http://www.freebsd.org/doc/en_US ... cratch/article.html
发表于 2003-10-16 12:20:23 | 显示全部楼层
大家伙在翻译handbook吗,handbook不是有中文版的吗?
发表于 2003-10-16 12:26:03 | 显示全部楼层
很好一篇文章, 以后用它在硬盘上装两个系统换着用!
发表于 2003-10-16 14:59:26 | 显示全部楼层
我帮你转到英文精品栏去了,看看谁有空帮你一下!
发表于 2003-10-16 15:39:10 | 显示全部楼层
也太长了吧,一看就没了翻译的信心,打字也是很累的哦!
发表于 2003-10-16 18:00:42 | 显示全部楼层
这里面有几个脚本文件, 取出来文章就很短了, 没多长的!
发表于 2003-10-18 09:42:30 | 显示全部楼层
我接了
发表于 2003-10-18 09:48:22 | 显示全部楼层
谢谢 !! 非常感谢!
发表于 2003-10-18 09:49:19 | 显示全部楼层
FreeBSD来自抓
Jens Schweikhardt
schweikh@FreeBSD.org

版权 &复制 ;2002由 Jens Schweikhardt

$FreeBSD : doc/en_US.ISO8859-1/articles/fbsd-from-scratch/article.sgml,v 1.22003/08/1419:54:04 simon终止$


FreeBSD是这不久被期望到改变的风河系统公司的一登记的商标 .

Adobe,杂技演员, Acrobat Reader,并且 postscript是系统在美国并且/或合并了的 Adobe的任何一个注册商标或商标另外的国家.

制造商和卖主使用了区分他们的产品的许多指明作为商标被宣称.那些指明在哪儿在这似乎文档,并且 FreeBSD工程知道商标主张,指明被“&#8482;”跟随了或“& reg ;”符号 .

[分离超文本 /挑选超文本 ]

--------------------------------------------------------------------------------

这篇文章在 FreeBSD来自抓描述我的努力:一充分自动化了编的一个设定的 FreeBSD系统的安装来自资源 ,所有的你的爱好的包括编译移植并且设置了你的完美的系统的想法到匹配 .如果你认为制造,世界是一个奇妙的概念, FreeBSD来自抓扩大它到制造 evenmore .


--------------------------------------------------------------------------------

1介绍
假如你曾经与制造世界升级了系统?如果你仅仅有一系统在...之上,有一个问题你的磁盘.如果 installworld失败 partway通过 ,你是有可能不甚至再启动的一个打破的系统的左边的 .也许 installworld顺利运用的或但是新建核不启动.然后它是到延伸适合于的时间 Fixit CD并且挖那些备份你的适合于半年以前拿了.

我相信“当升级系统时,擦去你的磁盘”范例.擦去磁盘,或相当划分,保证有否躺在附近的旧的 cruft左边的 ,哪个大多数升级过程的一些东西就不在乎关于 .但是擦去分区意味着你有到另外重新编译/重新安装所有的你的端口和包裹并且然后重做所有你的小心地 crafted配制捏.如果你认为这项任务应该也被自动化,读在...之上 .


--------------------------------------------------------------------------------

2为什么将我(不)想要来自抓的 FreeBSD?
这是我们有到编译的 sysinstall和众所周知的方法的一个合法的问题核和 userland工具 .

有 sysinstall的问题是它是严重地有限的在什么,在哪儿并且怎么它能安装 .

它是通常过去常造得前的分发设置并且包装来自的安装一些另外的资源 ( CD , DVD , FTP ).它不能安装一制造 buildworld的结果.

它不能在在一个跑的系统的一目录下面的安装一秒系统.

它不能在 Vinum的安装划分.

它不能编译移植,仅仅预编译的安装包装.

它对到任意的柱子安装改变的制造的手迹或难.

后面然而并非最少, sysinstall是半正式在它的 End-Of-Life .

造的众所周知的方法和安装世界,当在手册描述了,旁边默认代替现有系统.仅仅核和模块被节省.系统二进制代码,头和很多另外的文件被覆盖;过时的文件仍然是在场的并且能引起吃惊.如果升级失败适合于任何东西原因,它可以是到恢复甚至不可能的难的或系统的上一步状态.

FreeBSD来自抓解决所有的这些问题.策略是简单的:使用一个跑的系统到安装在一棵空目录树下面的一个新建系统,当新建分区适当地在那棵树里被装时.许多设置文件能被拷贝到适当的地方和(8)能照顾那些的 mergemaster 那不能.新建系统的任意的 post-配制能在旧系统以内被做来自 ,直到点在哪儿你能到新建系统的 chroot .换句话说,我们定位通过 3个舞台,每个舞台在此由运用一外壳手迹或的任何一个组成调用制造:

stage_1.sh:创建一新建在一空目录和是必要的同样多文件然后启动的合并或复制下面的可启动的系统新建系统.

stage_2.sh:安装需要了港口.

stage_3.mk:做 post-配制软件在上一步舞台安装了的适合于 .

一旦你使用了 FreeBSD来自,抓造第2个系统并且令人满意发现它工作适合于一些星期,你能然后再使用它重新安装原来的系统.来自现在在...之上 ,无论何时你看上去象一更新在命令 ,你简单地翻转你想要擦去并且重新安装的分区.

也许你甚至听说了或试用的 Linux来自抓,短的或 LFS适合于 .LFS也描述怎么造并且在空的系统来自抓划分使用一个跑的系统的安装 .在 LFS的焦点似乎是每个系统组件的角色到显示 (例如核,编译器,设备,外壳 ,终端数据库 ,等等)并且每个 Zaahz的安装的详细资料 .FreeBSD来自抓不做定位进那么详细说明.我的目标到准备一自动化并且完成安装,不解释所有的血污的详细资料在兜帽下面的定位在...之上当做世界时.以防你想要在详细的这水平探索 FreeBSD,看 /usr/src/Makefile并且跟随一制造 buildworld的操作的开始 .

也在你应该记住的 FreeBSD来自抓拿的途径有缺点.

当在舞台 2期间编端口时,系统不能是使用的适合于它的通常的责任.如果你你有考虑空闲时间的一个生产服务者在舞台 2引起了的运行 .stage_2.sh下面编了的端口要求关于 4造在...之上的小时有随机存取存储器的 1800krpm磁盘和 10GB的一个AMD1+ SCSI系统.


--------------------------------------------------------------------------------

3前提
去的适合于 FreeBSD来自抓方法,你有的需要:

有来源和一棵港口树的一个跑的 FreeBSD 系统.

新建系统将被安装的至少一个闲置的分区.

有运用 mergemaster (8)的经验.或这样做的至少否害怕.

如果你仅仅有否或到互联网的一个慢连接:你的爱好移植的 distfiles适合于 .

有 Bourne外壳的外壳脚本的基本的知识,嘘(1).

最后,你应该也能告诉你的引导装载器怎么启动新建系统,也交互地,或借助于一设置文件 .


--------------------------------------------------------------------------------

4舞台一:系统安装
下列是我的 stage_1.sh.你到它在多方面把你的“完美的系统”的想法放到匹配的定制的需要“.我试着了广泛地评价你应该改编点思考的地方:

划分设计 .

我不订阅一单个的巨大的分区适合于的想法全部系统.我的系统通常让至少一个划分适合于 /,有到 /var/tmp的 /tmp symlinked的 /usr和 /var .另外我共享文件系统适合于 /home (用户家), /home/ncvs ( FreeBSD CVS仓库复制品), /usr/ports (端口树), /src (,喜欢新闻线轴).

奢侈品项目.

你很快地在启动以后想要什么新建系统并且甚至在开始前上演 2 .因为这是登录外壳适合于,在我的情况中这是壳/zsh我的帐目当在 /etc/passwd指定了.严格地说你能没有奢侈品项目做,因为都你做的需要是作为根和运行登录下一条舞台.

原因适合于不在舞台一个期间安装所有的我的敬爱的港口的简单地在理论并且在实践是那在那里是 bootstrap和一致性问题:舞台一个让你的旧核跑,但是 chrooted环境由新建二进制代码和头组成s .如果新建系统适合于实例支持新建系统呼叫(根据它的头),一些 configure-类型手迹可能试着使用它并且因为它执行在...之上,得到杀死旧核.我看见了另外的问题我是否试着造lang/perl5.

在你前没问题你完成了的运行 stage_1.sh制造在准备适合于制造 installworld installkernel的通常的任务,喜欢:

设置了你的核设置文件

成功地被完成了的制造 buildworld

成功地被完成了的制造 buildkernel KERNCONF=whatever

什么时候你运行 stage_1.sh适合于第一个时间 ,并且设置拷贝的文件来自你的跑的系统新建系统不是关于在 /usr/src下面的 up-to-日期 , mergemaster将问你怎么继续.我推荐吞没变化.如果你对去的通过感到疲倦对话你能简单地更新文件在...之上你曾经运用系统(只要这是一选项 .如果你的系统之一跑,你可能不想要做这-马厩和其它-当前.变化可以是不兼容的).祈祷将检测的随后的 mergemaster在 /usr/src下面的 RCS版本 IDs匹配那些并且跳过文件 .

在失败的第一命令的 stage_1.sh手迹愿望停止 (归还非--零退出状况 )由于集合- e ,因此你不能俯看错误你应该在你前在你的 stage_1.sh的版本改正任何错误定位在...之上 .

就算,在 stage_1.sh我们调用 mergemaster文件需要的没有一合并 ,它愿望显示并且在结束问

***比较完成

做你请求到是 /var/tmp/temproot.stage1?的左边的的删除 [没有]否
请答案否或就压回车键原因是 mergemaster将有左边的一些在将以后被拷贝到新建系统的 /var/tmp/temproot.stage1下面的零个大小的文件(除非已经在那里).

在以后它愿望列表它安装了的文件,使用一寻呼机 (由默认的更多 (1),选择性地少些的(1)):

***你选了自动的安装为没做的选项适合于文件
存在你的系统下列被安装的在...之上适合于你:
/newroot/etc/defaults/rc.conf
......
/newroot/版权

(结束)
到退出的类型 q然后你将被通知的寻呼机关于 login.conf:

***你安装了一 login.conf文件 ,这样肯定的制造你运行
'/usr/bin/cap_mkdb /newroot/etc/login.conf'
重建你的 login.conf数据库

假如你将喜欢它到运行现在 ? y或 n [ n ]
答案没有关系自从我们愿望运行 cap_mkdb (1)在任何情况下.

任何事情 stage_1.sh被记载到 stage_1.log适合于你检验如果你这样做的请求 .

这是作者的哪个的 stage_1.sh,你到修改的需要实质地,特别走1,2,5并且6.

警告:请注意(8)命令的 newfs .当时你不能系统在...之上装了的创建新建文件划分,手迹将幸福地擦掉任何不骑马的 /dev/da3s1a, /dev/vinum/var_a和 /dev/vinum/usr_a .这能是破坏你的天的足够,这样对设备命名的修改肯定.

#! /bin/sh
#
# stage_1.sh - FreeBSD来自抓,舞台1:系统安装.
#用法: ./stage_1.sh
#
# $FreeBSD : doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_1.sh,v 1.12003/03/0808:26:10 schweikh终止$

设定- x - e
路径=/bin:/usr/bin:/sbin:/usr/sbin

#前提:
#
#一)成功地完成了“制造 buildworld和“制造 buildkernel””
# b )闲置的分区(至少一适合于根 fs ,可能更多适合于
#新建 /usr和 /var ,合你的意.)

#在哪儿的根山点你创建新建系统因为它仅仅是
#作为一个山点使用了,否空间将被使用在...之上作为所有的那个文件系统
#文件当然被写给装的文件 system(s).
DESTDIR=/newroot
SRC=/usr/src #你的 src 树在哪儿.

# ---------------------------------------------------------------------------- #
#走1:创建在 $DESTDIR下面的一棵空目录树.
# ---------------------------------------------------------------------------- #

step_one (){
#强制的新建根文件系统.
#改变设备名字(DEV_*)射击的或风险脚.
DEV_ROOT=/dev/da3s1a
mkdir - p ${DESTDIR }
newfs ${DEV_ROOT }
tunefs - n使能够 ${ DEV_ROOT }
增长- o noatime ${DEV_ROOT }${DESTDIR }

#另外的文件系统和可选的起始的山点.
DEV_VAR=/dev/vinum/var_a
newfs ${DEV_VAR }
tunefs - n使能够 ${ DEV_VAR }
mkdir - m 755${DESTDIR } /var
增长- o noatime ${DEV_VAR }${DESTDIR } /var

DEV_USR=/dev/vinum/usr_a
newfs ${DEV_USR }
tunefs - n使能够 ${ DEV_USR }
mkdir - m 755${DESTDIR } /usr
增长- o noatime ${DEV_USR }${DESTDIR } /usr

mkdir - m 755- p ${DESTDIR } /usr/ports
装 /dev/vinum/ports ${DESTDIR } /usr/ports

#现在创建强制的所有的另外的目录.
cd ${ SRC } /etc ;制造 distrib-dirs DESTDIR=${ DESTDIR }
#我的私人参数到 symlink tmp -可选的>var/tmp..
cd ${DESTDIR };rmdir tmp;ln - s var/tmp
}

# ---------------------------------------------------------------------------- #
#走2:填充空 /etc目录树和放的一些文件在/.
# ---------------------------------------------------------------------------- #

step_two (){
#添加或删除来自这列表依据你的见解主要强制.
在\的适合于 f
/.profile \
/etc/组 \
/etc/hosts \
/etc/inetd.conf \
/etc/ipfw.conf \
/etc/make.conf \
/etc/master.passwd \
/etc/nsswitch.conf \
/etc/ntp.conf \
/etc/printcap \
/etc/侧面 \
/etc/rc.conf \
/etc/resolv.conf \
/etc/start_if.xl0 \
/etc/ttys \
/etc/ppp/* \
/etc/邮件/aliases \
/etc/mail/aliases.db \
/etc/mail/hal9000.mc \
/etc/mail/service.switch \
/etc/ssh/*钥匙*\
/etc/ssh/* _config \
/etc/X11/XF86Config-4 \
/boot/splash.bmp \
/boot/loader.conf \
/boot/device.hints ;
cp - p ${f }${DESTDIR }${f }

#删除 mergemaster的 temproot ,如果有的话.
TEMPROOT=/var/tmp/temproot.stage1
如果测试 - d ${ TEMPROOT };那时
chflags - R 0${TEMPROOT }
rm - rf ${TEMPROOT }
fi
mergemaster -我- m ${SRC } /etc - t ${TEMPROOT }- D ${DESTDIR }
cap_mkdb ${DESTDIR}/etc/login.conf
pwd_mkdb - d ${ DESTDIR } /etc - p ${DESTDIR}/etc/master.passwd

# Mergemaster不做创建空文件,在/var/log.的 e.g.这样做现在,
#但是别痛打可能在循环被拷贝了在上面的文件.
cd ${TEMPROOT }
查找 .-类型 f | sed 's,^\./,,' |
当读 f;时,做
如果测试 - r ${ DESTDIR }/${ f };那时
回响“${DESTDIR }/${f }已经存在;没拷贝”
另外
回响“创造空 ${ DESTDIR }/${ f }”
cp - p ${f }${DESTDIR }/${f }
fi

chflags - R 0${TEMPROOT }
rm - rf ${TEMPROOT }
}

# ---------------------------------------------------------------------------- #
#走3:安装世界.
# ---------------------------------------------------------------------------- #

step_three (){
cd ${SRC }
制造 installworld DESTDIR=${ DESTDIR }
}

# ---------------------------------------------------------------------------- #
#走4:安装核和模块.
# ---------------------------------------------------------------------------- #

step_four (){
cd ${SRC }
# loader.conf和 device.hints被 installkernel目标要求.
#如果你没在步拷贝他们2, cp他们当在下一条显示出2排队.
# cp sys/boot/forth/loader.conf ${ DESTDIR } /boot/defaults
# cp sys/i386/conf/GENERIC.hints ${DESTDIR}/boot/device.hints
制造 installkernel DESTDIR=${ DESTDIR }KERNCONF=HAL9000
}

# ---------------------------------------------------------------------------- #
#走5:安装或修改一些必要的文件.
# ---------------------------------------------------------------------------- #

step_five (){
#创建 /etc/fstab ;到匹配的强制的修改你的设备.
猫<<EOF>${DESTDIR } /etc/fstab
#设备 Mountpoint FStype选项倾倒Pass#
/dev/da3s1b 没有交换 sw 00
/dev/da4s2b 没有交换 sw 00
/dev/da3s1a / ufs rw 11
/dev/da1s2a /src ufs rw 02
/dev/da2s2f /共享 ufs rw 02
/dev/vinum/var_a /var ufs rw 02
/dev/vinum/usr_a /usr ufs rw 02
/dev/vinum/home /home ufs rw 02
/dev/vinum/ncvs /home/ncvs ufs rw , noatime 02
/dev/vinum/ports /usr/ports ufs rw , noatime 02
#
/dev/cd0 /dvd cd9660 ro , noauto 00
/dev/cd1 /cdrom cd9660 ro , noauto 00
proc /proc procfs rw 00
EOF

#可选的更多目录;.
mkdir - m 755- p ${DESTDIR } /src;chown root:wheel ${DESTDIR } /src
mkdir - m 755- p ${ DESTDIR } /共享 ; chown root:wheel ${ DESTDIR } /共享
mkdir - m 755- p ${DESTDIR } /dvd;chown root:wheel ${DESTDIR } /dvd
mkdir - m 755- p ${DESTDIR } /home;chown root:wheel ${DESTDIR } /home
mkdir - m 755- p ${DESTDIR } /usr/ports;chown root:wheel ${DESTDIR } /usr/ports
#漂亮的安装时间地区信息;强制.
cp ${ DESTDIR } /usr/共享/zoneinfo/Europe/Berlin ${ DESTDIR } /etc/localtime
如果测试 - r /etc/wall_cmos_clock ;那时
cp - p /etc/wall_cmos_clock ${DESTDIR } /etc/wall_cmos_clock
fi
}

# ---------------------------------------------------------------------------- #
#走6:到我重要的事情当我首先登录到一个新建系统时.
# NOTE :别与跑的旧系统这里做安装太多二进制代码并且
#新建二进制代码和头安装了你对进 bootstrap的运行可能
#在你在新建系统启动了以后,问题端口应该被编.
# ---------------------------------------------------------------------------- #

step_six (){
chroot ${ DESTDIR }嘘- c“ cd /usr/ports/shells/zsh ;制造清洗干净的安装”
chroot ${ DESTDIR }嘘- c“ cd /etc/邮件 ;制造安装”#设置 sendmail

#没有 compat symlink linux_base文件在在...之上上面结束根 fs:
cd ${DESTDIR };mkdir - m 755 usr/compat
chown root:wheel usr/compat;ln - s usr/compat
mkdir - m 755 usr/compat/linux
mkdir - m 755靴子/蛴螬

#制造 spooldirs适合于在我的 /etc/printcap的打印机.
cd ${ DESTDIR } /var/spool/输出/lpd ; mkdir -作为 od ev te lp da的 p
触摸${DESTDIR } /var/log/lpd-errs

#我想要继承来自的更多文件旧系统.
在\的适合于 f
/var/cron/tabs/root \
/var/邮件/* \
/boot/grub/*;
cp - p ${f }${DESTDIR }${f }


#如果你没有 /home在...之上一个分享的分区,你可以想要它到复制:
# mkdir - p ${DESTDIR } /home
# cd /home;tar cf -.|( cd ${DESTDIR } /home;tar xpvf -)

#以 FreeBSD 5.x, perl开始生活在 /usr/本地/bin但是许多手迹
#使用一设死#! /usr/bin/perl ;使用到制造的一 symlink他们工作.
cd ${ DESTDIR } /usr/bin ; ln - s .. /本地/bin/perl
cd ${DESTDIR } /usr;rmdir src;ln - s .. /src/current src
}

do_steps (){
step_one
step_two
step_three
step_four
step_five
step_six
}

do_steps 2>&1| T stage_1.log

# EOF $RCSfile : stage_1.sh,v $活力: tabstop=2:expandtab:
下载 stage_1.sh.

运用这个手迹安装一个系统当启动时提供:

继承了用户和组.

在以太网和 PPP上的 Firewalled互联网连接.

正确的时间地区和 NTP .

一些更多未成年者配制,相似的 /etc/ttys和 inetd .

另外的区域是准备的适合于配制,但是将不工作直到 2被完成的舞台.我们拷贝了的适合于实例设置打印的文件和X11.然而打印对应用软件没发现在底系统的需要可能,相似的 postscript & reg ;实用程序.X11将不以前我们编了的运行服务者,图书馆和程序.


--------------------------------------------------------------------------------

5舞台 2 :移植安装
笔记:它也对安装可能(预编译)在这的包裹上演,编的代替移植.在这种情况中,与 pkg_添加的一列表命令比, stage_2.sh将是没有东西更多 .我信任你知道怎么写如此的一个手迹.这里我们集中在...之上更多使用港口的灵活并且传统型的方法.

下列 stage_2.sh手迹是怎么我我的爱好移植的安装 .它能是时间的运行任何东西数字并且将跳过已经被安装的所有的港口.它支持 dryrun选项 (- n )到将被做的只是显示 .你将当然想要港口的列表到编辑 ,并且可能改变一些环境变量.

端口的列表与 2由线组成或更多空格分开了词:范畴和端口 ,选择性地由安装列在后面了命令那个愿望编译和安装端口 (默认 :制造安装 ).空排队并且衬里以开始#被忽略.它足够到仅仅的时间的大多数命名范畴和端口 .一些港口能然而是指定制造变量调节了的罚款, e.g.:

www mozilla制造 WITHOUT_MAILNEWS=是 WITHOUT_CHATZILLA=是安装
邮件 procmail制造 BATCH=是安装
事实上你能指定任意的外壳命令,因此你没被限制为简单的制造祈祷:

java linux-sun-jdk13是 |制造安装
新闻客栈稳定的CONFIGURE_ARGS=“--使能够-uucp-rnews --使能够-setgid-inews”制造安装
注意线适合于新闻/inn-stable是一实例适合于一个一个射击外壳变量到 CONFIGURE_ARGS的任务.端口 Makefile将作为起始的价值使用这并且扩充一些另外的必要的 args .指定一制造的差别可变的在...之上命令行与

新闻客栈稳定的制造 CONFIGURE_ARGS=“--使能够-uucp-rnews --使能够-setgid-inews”安装
是后者将制服代替扩充它看情况在...之上你想要哪个方法的特别的端口 .

小心你的港口不使用一交互的安装 , i.e.他们应该不试着读来自除他们以外你明确地给在...之上 stdin的 stdin .如果他们做,他们将在 here-文档读下一条 line(s)来自你的港口的列表并且得到糊涂.如果 stage_2.sh神秘地跳过一端口,或停止处理 ,这是可能的原因.

这是它创造文件把如果你没有 stage_2.sh在...之上,它实际上安装的 LOGDIR/category+端口适合于每个端口称为了的一个记录文件的 stage_2.sh.肯定的一分享的分区制造你复制它以前到新建系统你启动它.

#! /bin/sh
#
# stage_2.sh - FreeBSD来自抓,舞台2:移植安装.
#用法: ./stage_2.sh
#
# $FreeBSD : doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_2.sh,v 1.12003/03/0808:26:10 schweikh终止$

DBDIR=/var/db/pkg
PORTS=/usr/港口
LOGDIR=/home/root/setup/ports.log; mkdir - p ${ LOGDIR }

#给更多比一个使用了的一些变量端口 .
PAPERSIZE=a4;输出 PAPERSIZE
USA_RESIDENT=否 ;输出 USA_RESIDENT

MYNAME=$( basename $0)
用法(){
exec>&2
应道“用法{MYNAME }[- hn ]”
应道“”
应道“选项 :”
应道“- h打印这篇帮助文章”.
应道“- n Dryrun :将被做的只是显示”.
应道“”
退出 1
}

args='getopt hn $*“
如果测试 $?!=0;那时
用法
fi
设定-- $args
DRYRUN=
适合于我;
大小写“ $i ”在里面
- n ) DRYRUN=是 ;;
--)裂缝;;
*)用法;;
esac


猫<<EOF |
lang perl5
安全Llimitation sudo
x11服务者 XFree86-4-Server
x11包纸
x11 XFree86-4-libraries
x11 XFree86-4-clients
x11字体 XFree86-4-字体75dpi
x11字体 XFree86-4-字体100dpi
x11字体 XFree86-4-fontScalable
x11字体 urwfonts
x11字体 webfonts
x11工具箱打开主题
x11 rxvt
x11-wm ctwm
安全Llimitation openssh-askpass
astro xplanet
astro setiathome制造 BATCH=是安装
astro xephem
编辑活力
打印 ghostscript牛羚制造 A4=是 BATCH=是安装
打印 a2ps-a4
打印 psutils-a4
打印 gv
打印 acroread5
打印 transfig
archivers 压缩
archivers 解压缩
java linux-sun-jdk13是 |制造安装
java jdk13
www apache2
www weblint
www amaya
www mozilla制造 WITHOUT_MAILNEWS=是 WITHOUT_CHATZILLA=是安装
www netscape48导航者
www checkbot
www privoxy
图形 xfig
图形 xv
图形 fxtv
lang 期望
新闻听
赚 freebsd-uucp
赚 cvsup-without-gui
网 pathchar制造 NO_CHECKSUM=是安装
ftp wget
ftp ncftp3
textproc ispell
德国人 ispell-neu
德国人 ispell-alt
textproc docproj制造 JADETEX=是 HAVE_MOTIF=是安装
sysutils samefile
sysutils pstree
sysutils mkisofs
sysutils cdrtools
sysutils 蛴螬
devel ddd
devel ctags
devel ElectricFence
邮件 procmail制造 BATCH=是安装
邮件 metamail
邮件笨蛋
邮件 spamoracle
仿真器 mtools
sysutils portupgrade
新闻客栈稳定的CONFIGURE_ARGS=“--使能够-uucp-rnews --使能够-setgid-inews”制造安装
其他的figlet字体
textproc gmat
EOF
当读范畴命名 CMD ;时,做
大小写“${范畴}”在里面
\#*)继续;;
'“)继续;;'
esac
DIR=“${港口}/${范畴}/${命名 }”
如果!测试 - d“${ DIR }”;那时
回响“ $DIR 不存在--忽略”
继续
fi
cd ${DIR }
PKGNAME='make - V PKGNAME'
如果测试 - d“${ DBDIR }/${ PKGNAME }”;那时
回响“${范畴}/${命名 }已经安装了作为${ PKGNAME }”
继续
fi
LOG=“${ LOGDIR }/${范畴}+${命名 }”
应道“安装的===>${范畴}/${命名 }记载到的;${元木}”
测试 - n“${ CMD }”||CMD=“制造安装”
如果测试 - n“${ DRYRUN }”;那时
应道“${CMD }”
继续
fi
日期“++++++++++% v % T +++++++++”>${元木}
应道“ CMD {CMD }”>>${元木}
(
干净的制造
eval “${CMD }”
#干净的制造 # Uncomment如果 diskspace是紧密的在下面${港口}.
)2>&1| T -一${元木}


#作为一个包裹的安装 StarOffice ,创造了旧的在...之上系统与
#“制造包裹”,因为端口使用一交互的X11安装 .
#pkg_添加 ${PORTS}/editors/staroffice52/staroffice-*.tbz

# EOF $RCSfile : stage_2.sh,v $活力:tabstop=4:
下载 stage_2.sh.


--------------------------------------------------------------------------------

6舞台 3
你在舞台 2 期间安装了你的敬爱的港口.一些港口有点配制要求.这是什么上演 3 , post-配制是适合于 .我能有综合在 stage_2.sh手迹的结束的这 post-配制 .然而,我认为安装一端口并且修改它的保证一个分开的舞台的 out-of-the-box配制之间有概念的差别.

因为这允许你想要由跑设置简单地的容易的选定内容,我选择了实现作为一 Makefile的舞台 3:

#做- f stage_3.mk目标
没问题就象 stage_2.sh制造你在启动以后有 stage_3.mk可用的新建系统,由放它的任何一个在...之上拷贝它某地的一分享的分区或在...之上新建系统.

# stage_3.mk - FreeBSD来自抓,舞台3:移植 Post-配制 .
#用法:做- f stage_3.mk所有(设置任何事情)
#或做- f stage_3.mk目标 (就设置目标 )
#
#它是到没问题任何目标能被成为更多比的制造的一个好主意
#曾经没有有病的效果 .
#
# $FreeBSD : doc/en_US.ISO8859-1/articles/fbsd-from-scratch/stage_3.mk,v 1.12003/03/0808:26:10 schweikh终止$

.POSIX :

消息:
@回响“下列目标的请使用一:”
@回响“ config_apache ”
@回响“ config_inn ”
@回响“ config_javaplugin ”
@回响“ config_privoxy ”
@回响“ config_setiathome ”
@回响“ config_sgml ”
@回响“ config_sudo ”
@回响“ config_TeX ”
@回响“ config_tin ”
@回响“ config_uucp ”
@回响“所有的--上述所有”

所有的: config_apache \
config_inn \
config_javaplugin \
config_privoxy \
config_setiathome \
config_sgml \
config_sudo \
config_TeX \
config_tin \
config_uucp

config_apache :
#1.修改 httpd.conf.
perl - pi \
- e“ s/#ServerName new.host.name/ServerName hal9000.s.shuttle.de/;' \
- e“s/^ ServerAdmin * /ServerAdmin schweikh\@schweikhardt.net/;' \
- e“ s ,/usr/本地/www/cgi-bin/,/home/opt/www/cgi-bin/,;”\
/usr/local/etc/apache2/httpd.conf
#到网页的2.恢复 symlinks .
cd /usr/本地/www/data ;\
ln - fs /home/schweikh/prj/homepage schweikhardt.net; \
ln - fs /home/opt/www/测试 .

config_inn :
pw usermod - n新闻- d /usr/本地/news - s /bin/sh
#给新闻系统它的起始的配制 .
cd /home/root/安装 ;\
安装 - C - o新闻- g新闻- m 664活跃的新闻组 /usr/本地/news/db
#与端口来的 innd.sh被打破,它
#不存在的检查适合于 history.pag .
cd /home/root/安装 ;\
安装 - C - o根- g车轮- m 555 innd.sh /usr/local/etc/rc.d
#设置存储方法.
cd /home/root/安装 ;\
printf "%s\n%s\n%s\n%s\n" \
"方法 tradspool{“\"
"新闻组:*“\"
"班:0“\"
"}“\"
>storage.conf; \
安装 - C - o新闻- g新闻- m 664 storage.conf /usr/本地/news/etc
#设置 newsfeeds .
printf "%s\n%s\n" \
"ME :*::“\"
"shuttle/news2.shuttle.de:!junk,!control:B32768/512,Tf,Wfb:" \"
> /usr/本地/news/etc/newsfeeds
#设置 inn.conf.
perl - pi \
- e 's/^(organization:\s*).*/$$1一打开豆荚海湾门/;“\
- e 's/^(pathhost:\s*).*/$$19000 hal.schweikhardt.net/;' \
- e “s/^(服务者.*/$$1localhost/;”\
- e“s/^(领域.*/$$1 schweikhardt.net/;' \
- e“s/^( fromhost .*/$$1 schweikhardt.net/;' \
- e“ s ,^( moderatormailer .*,$$1 \%s\@moderators.isc.org,;' \
- e“ s , /usr/本地/news/spool , /共享/news/spool ,;”\
/usr/local/news/etc/inn.conf

config_javaplugin :
cd /usr/本地/lib/netscape-linux/plugins ;\
如果!测试 - h javaplugin.so;那么\
ln - s ../.. /../linux-sun-jdk1.3.1/jre/plugin/i386/ns4/javaplugin.so; \
fi;\
ls - l javaplugin.so

config_privoxy :
安装 - C - o根- g车轮- m 644设置 /usr/本地/etc/privoxy

config_setiathome :
perl - pi \
- e “ s ,^.* seti_wrkdir *#, seti_wrkdir=/家/没人/setiathome #,;”\
/usr/local/etc/rc.setiathome.conf

config_sgml :
cp - p /usr/本地/共享/gmat/sgml/ISO_8879-1986/entities/*\
/usr/本地/共享/sgml/docbook/4.1

config_sudo :
如果! grep - q schweikh /usr/本地/etc/sudoers ;那么\
应道“ schweikh所有=(所有的) NOPASSWD :所有的”>> /usr/本地/etc/sudoers ;\
fi

config_TeX :
# textproc/docproj 劝告:与 JadeTeX 排版 FreeBSD 手册,
#到列出的价值的改变下列设置:
perl - pi \
- e“s/^%原版 texmf.cnf/% texmf.cnf/;' \
- e 's/^(hash_extra\s*=).*/$$160000 /;“\
- e 's/^(pool_size\s*=).*/$$11000000 /;“\
- e 's/^(max_strings\s*=).*/$$170000 /;“\
- e 's/^(save_size\s*=).*/$$110000 /;“\
/usr/local/share/texmf/web2c/texmf.cnf

config_tin :
#到我们的文件的点听.
printf "%s\n%s\n%s\n" \
"activefile=/usr/本地/新闻/db/活跃“\"
"newsgroupsfile=/usr/本地/新闻/db/新闻组“\"
"spooldir=/共享/新闻/线轴/文章“\"
>/usr/local/etc/tin.defaults

config_uucp :
# UUCP期望到查找 /usr/bin/rnews .
cd /usr/bin ; ln - fs .. /本地/news/bin/rnews .
#实际 UUCP配制 .
回响 nodename js2015> /usr/本地/etc/uucp/config
回响梭js2015“猫uucp'> /usr/本地/etc/uucp/call
printf“端口 tcp\ntype tcp\n' > /usr/本地/etc/uucp/端口
printf "%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
"叫登录*“\"
"call-口令 *“\"
"时间任何东西“\"
"系统梭“\"
"地址 mail.s.shuttle.de" \"
"命令 rmail rnews “\"
"端口 tcp“\"
> /usr/本地/etc/uucp/sys
cd /usr/本地/etc/uucp ; chown uucp:uucp *; chmod o-rwx *
#在启动以后触发 uucico .
mkdir - p /usr/local/etc/rc.d; cp uucp.sh /usr/local/etc/rc.d

# EOF $RCSfile : stage_3.mk,v $活力:tabstop=4:
下载 stage_3.mk.


--------------------------------------------------------------------------------

7限制
如果它是交互的并且不做支持制造 BATCH=是安装,一端口的自动化的安装可以证明困难.一些移植相互作用的适合于比当要求了接受一些许可时,打是是没有东西更多 .如果如此的输入是,读来自标准输入 ,我们安装的适当的答案命令的简单地管子(通常制造安装 ;这是我们怎么在 stage_13.sh).处理java/linux-sun-jdk2

这策略适合于实例不工作适合于编辑/staroffice52,那X11正在运用哪个需要 .安装过程包含点按并且打的公平的数量,因此它不能象另外的港口罐头一样被自动化.然而下列解决办法做诡计适合于我:第一我创建一 staroffice包裹在...之上旧系统与

# cd /usr/ports/editors/staroffice52
#制造包裹
===>大楼包裹适合于 staroffice-5.2_1
创造包裹 /usr/ports/editors/staroffice52/staroffice-5.2_1.tbz
登记看情况:.
在 '/usr/ports/editors/staroffice52/staroffice-5.2_1.tbz'创造 bzip'd焦油球
并且在舞台 2期间我简单地使用:

# pkg_添加 /usr/ports/editors/staroffice52/staroffice-5.2_1.tbz
你应该也知道升级问题适合于设置文件.在一般你不知道是否并且如果格式或目录一设置文件变化.一新建组可以被加到 /etc/组 ,或 /etc/passwd可以获得另外的田野.这的所有在过去发生了.拷贝的简单地一设置文件来自旧到新建系统可以是时间的足够的大多数,但是在这些情况中它不是.如果你更新一个系统正规的方法(由覆盖旧文件)你被期望使用 mergemaster处理你有效地想要本地到合并的变化设置与潜在地新建项目.不幸地, mergemaster仅仅是可用的适合于底系统文件,不适合于任何东西由端口安装了.软件似乎是的一些第三方特别设计了把我作为在...之上我的由变化的脚趾设置文件格式每双周.你能做的所有是是警报 ,特别当主要的版本数字颠簸时.在过去我不得不捏或重写文件适合于网服务者,新闻服务者和读者.活跃地被维持了的所有的软件是一主要的候选人适合于设置文件细看.

我若干次使用了 FreeBSD来自抓到更新到 5-CURRENT的一 5-CURRENT , i.e.我从来没试用一 5-CURRENT来自到安装一 4-STABLE系统或反过来也如此.由于在不同的主要的版本数字之间的变化的数字我将期望这个过程是深奥的一点的更多 .使用抓适合于在 4-STABLE的领域以内升级的 FreeBSD来自应该无痛苦地工作(尽管我还没试用它) 4-STABLE的用户可以想要考虑下列区域:

如果你不使用设备文件系统( devfs )你可以在舞台一个与 MAKEDEV (8)想要到你的硬件的创建设备适合于一些,步 6 .
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表