LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: rainren

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

[复制链接]
发表于 2003-10-18 09:50:38 | 显示全部楼层
上面这个是东方快车弄的!
发表于 2003-10-18 11:20:48 | 显示全部楼层
已经翻到3了,累~~~~
发表于 2003-10-18 11:25:37 | 显示全部楼层
休息一会
发表于 2003-10-18 14:04:26 | 显示全部楼层
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.



这篇文章描述了我在FreeBSD From Scrath方面的努力:从源码编译一个全自动的个人化的FreeBSD,包括你最喜爱的ports和配置。如果

你认为make world是一种很棒的概念(方法),FreeBSD From Scratch将它作了很大拓展
--------------------------------------------------------------------------------

1.介绍

你是否曾经用make world 升级过你的系统?当你只有一个系统的时候有一个问题。如果升级到一半的时候失败了,你的系统将变得因残

缺不全而无法启动。或者是你的升级很顺利,但是新的内核无法启动。这时你不得不用你的修复CD和你半年以前做的备份来修复了。


我更喜欢用“重写硬盘(wipe disks)当升级系统的时候”的方法。重写硬盘,或者说重新分区(??),确保了没有旧的东西(通常升

级过程并不关心这些旧的东西)留在那里。但是重写硬盘你不得不重新编译和安装你所有的ports和packages,并且十分细致的重新设置

你的系统。如果你认为这项工作应该自动完成,请继续读下去


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

2.为什么我(不)想FreeBSD From Scratch?


这的确是一个问题。我们已经有了sysinstall(系统安装配置工具)和那些编译内核和the userland(??)的工具

对于sysinstall来说,问题在于它严格限制了那些被安装,在那里和如何安装。

它通常用来从某些途径(cd,dvd,ftp)安装一些预先建好的distribution和packages。它不能安装make buildworld的结果。

它也不能再一个运行的系统的目录中安装第二个系统。

它也不能在Vinum分区中安装

它不能编译ports,只能安装预先编译过的packages

它很难通过写脚本来修改或在安装后作随意的修改

最后但是最重要的事,sysinstall是半官方的。(注:作者似乎认为这有些不自由)

我们通常的建立和安装the world的方法,像手册中所说的默认的替换旧有的系统。只有内核和模块(modules)被保存下来了。心痛的二

进制文件,头文件和许多其它的文件被重写。未被删除的文件人在那里并可能导致问题的出现。如果升级因此而失败,很难甚至不可能

恢复系统以前的状态。


FreeBSD From Scratch解决了以上所说的所有的问题。从想法上说很简单:当新的分区被加载(mounted)在某个目录时,用一个运行的系

统在一个此目录中安装一个新的系统.许多设置文件会被复制到适当的位置而mergemaster(8)会处理那些其他的。任意的安装后配置可在

旧有系统中完成,知道你的新系统能正常启动。我们将分三步来实现,每一步都将包括编写shell脚本或调用make :


第一步(stage_1.sh),在一个空的目录中创建一个可启动的系统,导入或复制尽可能多的有用的文件。然后重启

第二步(stage_2.sh),安装你想安装的ports

第三步(stage_3.mk),在前一步的基础上作后期配置


一旦你使用FreeBSD From Scratch创立了第二个系统并发现了它顺利的运行了几个星期,你可以再次用它装上你原有的系统。从此一旦

你将觉得有必要升级,你就会直接创建一个分区并重新安装。

也许你听说过甚至试过Linux From Scratch(LFS).LFS同样描述了如何有一个运行的系统在一个空的分区中创建并安装新的系统。LFS关

注的是展示系统的各部分(像内核,编译器,设备(devices), shell, 终端数据库(terminal database)等)和各部分安装时的细节。

FreeBSD From Scratch并不会那么关注细节。我的目标是提供一个完整的自动的安装,而不是解释make world时的所有琐碎的细节。如

果你想那么细致的研究FreeBSD,看看 /usr/src/Makefile 并按其所说的作。


你必须记住的一点时, FreeBSD From Scratch也有缺点。

当在第二步编译ports时,系统不能被赋予日重的工作。如果你在运行商业服务器,你必须考虑到为第二步留出停止服务的时间。在一个

AMD1800+ SCSI的系统(10krpm的硬盘和 1GB的内存)上在第二步编译ports时需要大约四个小时。


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

3 先决条件

想 FreeBSD From Scratch,你必须有:

一部拥有源码和ports树的运行的FreeBSD

至少一个未用的分区(安装新系统用)

运行mergemaster(8)的经验,或至少不害怕

如果你不能上网或网速很慢,你需有你喜爱的ports的文件

关于Bourne shell脚本变成的基础知识


最后,你应该能告诉你的boot loader怎样启动新的系统,或交互的,或通过复制配置文件

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

4 第一步:系统安装

下面就是我的stage_1.sh。你需要做一些修改以适应你的系统。我已经添加了一些注释以便于你的工作。你需要仔细考虑一下:

分区的布局

我不同意用在一个大的分区上安装整个系统。我的系统至少有一个分区给/,/usr 和 /var ( /tmp 系统自动连接到/var/tmp).此外,

我把/home (用户目录), /home/ncvs (FreeBSD CVS仓库复制 (repository replica)), /usr/ports (the ports树), /src (各种源码

树) 和 /share (其它不需备份的共享数据, 像 the news spool).

"奢侈品"

在启动新系统之后甚至进行第二步之前你需要些什么。对我来说是shell /zsh,因为这是在/etc/passwd为我的账户指定的登陆shell。严

格的说你可以不需要这些"奢侈品",因为你所需要做的知识以root 的身份登陆并开始第二步

我不直接在第一步中安装我喜爱的那些ports的原因是从理论和实践上来看,有引导和一致性的问题:在第一步你的旧内核在运行,但是

新的系统包含新的二进制文件和新的头文件。比如说如果新的系统支持新的系统呼叫(system call)(按它的头文件),一些配置类型

的脚本也许会试着运行它并被旧的内核杀掉了(因为在旧的内核中运行)我曾经看见过其它的问题当我建立lang/perl5时

在你运行stage_1.sh之前,确保你已经完成了通常的安装world 和安装内核的准备工作,像:

摄制你的内核配置文件

成功的完成make buildworld

成功的完成make buildkernel KERNCONF=whatever


当你第一次运行stage_1.sh,并且从旧有系统复制到新系统的配置文件比/usr/src下的旧的时候,mergemaster会像你询问怎样进行。哦

建议选择merging the changes .如果你厌倦了那一个个的对话框,你可以简单的在运行系统(新系统??)时更新这些文件。(只有当

这是一个选项是.你也许并不像在一个系统运行-STABLE和其他的 -CURRENT时这样做.这些改变可能导致不兼容).接下来mergemaster

invocations将检测the RCS version IDs与在/usr/src下匹配的文件并跳过这些文件


脚本stage_1.sh将在第一个发生错误的命令(返回一个非零状态)那里停下来(因为设置了 -e),所以你不应遗漏任何错误。你应该在继

续进行前修正所有的错误

在 stage_1.sh我们将调用mergemaster。甚至当没有需要merge的文件时,它将显示:
<<
*** Comparison complete

Do you wish to delete what is left of /var/tmp/temproot.stage1? [no] no
>>
请回答no 或直接敲Enter。原因是mergemaster在/var/tmp/temproot.stage1下留几个空文件,这些文件将被拷到新的系统中(除非他们

已经在那里了)

在这之后将列出它安装的文件,请用分页命令(默认的more(1) 或可选的 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)
>>

敲入q推出分页。然后你将回答关于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]
>>

你的回答并不重要,因为我们将运行cap_mkdb(1)

stage_1.sh所作的时连到stage_1.log文件上以便你检查如果你想这样做


下面就是作者的stage_1.sh, 你需要做足够的修改,尤其是第1,2,5,6步

警告:请注意命令newfs(8)。当你不能再加载的分区中创建新的文件时,脚本将会抹去所有未被加载的 /dev/da3s1a, /dev/vinum/var_a

and /dev/vinum/usr_a.这将导致指名的错误.请确保编辑device的名字


文件开始(stage_1.sh)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#!/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

# 先决条件
#
# a) 成功完成 "make buildworld" , "make buildkernel"
# b) 未用的分区 (至少一个留给root文件系统,或更多的给/usr , /var)

# 设置加载点(mount point)在你创建新系统的地方,因为只是加载点,那个文件夹
#的空间不会因向加载的文件系统中写文件而被用掉

DESTDIR=/newroot
SRC=/usr/src # 你的源码树

# ---------------------------------------------------------------------------- #
# 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: 安装 world.
# ---------------------------------------------------------------------------- #

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

# ---------------------------------------------------------------------------- #
# Step 4: 安装 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: 安装或编辑一些基本文件
# ---------------------------------------------------------------------------- #

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:对我来说重要的时我第一次登陆到新的系统
# 注意: 不要在这安装太多的二进制文件. 在旧有系统运行新的二进制文件你也许会碰到引导问题
# 你也许会碰到引导问题。Ports将新系统启动后在编译
# ---------------------------------------------------------------------------- #

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:


<<<<<<<<<<<<<<<<<<<<<<<<<<文件结束


运行这个脚本安装系统将在启动时提供:

原有的用户和群
防火墙保护下通过以太网和PPP的Internet连通性
正确的时区和NTP
一些小的配置,像/etc/ttys,inetd


其它方面的配置,但是不会在第二步以前工作。例如我们已经复制了打印和X11的配置。但是打印需要基层系统中步提供的程序,像Post

Script?。X11不会在我们编译它的服务器,库,和程序前运行
发表于 2003-10-18 14:06:13 | 显示全部楼层
今天先到这里,剩下的以后再说
发表于 2003-10-18 14:44:47 | 显示全部楼层
谢谢,谢谢等你翻译完我打印出来来定制我的系统!

非常感谢!
发表于 2003-10-18 21:05:00 | 显示全部楼层
这份资料不错啊.
 楼主| 发表于 2003-11-1 08:21:09 | 显示全部楼层
再把这个文章顶上去!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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