Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2063432
  • 博文数量: 32
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 8577
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-18 18:22
文章分类

全部博文(32)

文章存档

2011年(1)

2010年(3)

2008年(28)

我的朋友

分类: WINDOWS

2008-04-13 22:44:25

FreeBSD6.2架设之内核编译



Mongolia




Index:
  • 简介
  • Requirements
  • Step 1 查看当前机器自检信息.
  • Step 2备份原内核文件.
  • Step 3 编辑新内核描述文件.
  • Step 4 启用磁盘配额.
  • Step 5 控制台中禁用热启动
  • Step 6 内核编译前后对比.
  • Step 2 编译后的清理工作.
  • F.A.Q.
  • Links to other sources



简介






为你自己定制专用的内核,加入一些特定功能如QUOTA,禁止控制台重启,声卡,防火墙等,总之可以自己做到很多适合自己机器的配置。

Step 1 查看当前机器的自检信息.






内核编译最好本地操作,不要远程编译。


要是你修改过/etc/make.conf文件,一定要还原此文件。


确保/etc/make.conf文件如下


Shell:

cat /etc/make.conf


# added by use.perl 2007-11-24 22:06:09


PERL_VER=5.8.8


PERL_VERSION=5.8.8


查看当前机器的自检信息,取得CPU 内存 显示卡 硬盘 网卡等信息

Shell:

dmesg | less


查看/usr/src/Makefile文件,此文件说明注意事项和具体操作步骤


Shell:

cd /usr/src/


less /usr/src/Makefile


# For individuals wanting to build from the sources currently on their

# system, the simple instructions are:

#

# 1.`cd /usr/src'
(or to the directory containing your source tree).

# 2.`make world'

#

# For individuals wanting to upgrade their sources (even if only a

# delta of a few days):

#

# 1.`cd /usr/src' (or to the directory containing your source tree).

# 2.`make buildworld'

# 3.`make buildkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).

# 4.`make installkernel KERNCONF=YOUR_KERNEL_HERE' (default is GENERIC).

# 5.`reboot' (in single user mode: boot -s from the loader prompt).

# 6.`mergemaster -p'

# 7.`make installworld'

# 8.`make delete-old'

# 9.`mergemaster'

# 10.`reboot'

# 11.`make delete-old-libs' (in case no 3rd party program uses them anymore)


Step 2 备份当前内核描述文件.






查看当前机器内核描述文件


Shell:

uname -a


FreeBSD WOW.freemongolia.cn 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Fri Jan 12 10:40:27 UTC 2007
:/usr/obj/usr/src/sys/GENERICi386[/email]



备份当前机器内核描述文件
复制/usr/src/sys/i386/conf/GENERIC文件到/etc/WOW (WOW表示你自定义的名称)


Shell:

cp /usr/src/sys/i386/conf/GENERIC /etc/WOW


创建一个链接到/usr/src/sys/i386/conf/GENERIC/目录


Shell:

cd /usr/src/sys/i386/conf/


ln -s /etc/WOW /usr/src/sys/i386/conf/



Step 3 编辑内核描述文件.







编辑内核描述文件


添加磁盘配额、禁用控制台中的热启动、等功能



编辑内核描述文件,vi /usr/src/sys/i386/conf/WOW


Shell:

vi /usr/src/sys/i386/conf/WOW



Editor:

# 具体选项请参考
ident             WOW       #内核标记名称

增加以下内容
options         QUOTA                      #启用磁盘配额
options         SC_DISABLE_REBOOT    #在控制台禁用CTRL+ALT+DEL

存盘退出


以下2项不要注销


device scbus      # SCSI bus (required for SCSI)

device da     # Direct Access (disks)




Step 4 编译内核.







编译内核


根据/usr/src/Makefile文件方法,进行编译内核


1cd /usr/src (进入编译核心目录)


Shell:

cd /usr/src


2make buildworld(很漫长的等待大约1小时左右,有没有更漫长的事情?有。Ports安装XorgGnome33夜,33夜。嗯?好熟悉的旋律……..) (更新版本)


Shell:

make buildworld


3make buildkernel KERNCONF=你的内核描述文件名(default is GENERIC)(下面的WOW是我的内核描述文件名称)
(正式编译核心大约用时20分钟)


Shell:

make buildkernel KERNCONF=WOW


4make installkernel KERNCONF=你的内核描述文件名(default is GENERIC) (安装核心大约用时1分钟)


Shell:

make installkernel KERNCONF=WOW


5reboot (重新启动进入单人模式,重启选择4;具体操作可以查看第1章忘记root密码怎么办)


Shell:

reboot


以下几步为在单人模式下操作mount -u (重新挂载,参数-u表示挂载后可读写)


Shell:

单人模式#mount -u


mount -a (挂载全部磁盘,参数-a表示全部磁盘)


Shell:

单人模式#mount -a


cd /usr/src (进入编译核心目录)


Shell:

单人模式#cd /usr/src


mergemaster -p (此命令用来检验内核描述文件正确性)


Shell:

单人模式#mergemaster -p

*** Comparison complete

Do you wish to delete what is left of /var/tmp/temproot?[no]


make installworld(安装所有新的系统源代码,大约用时3分钟)


Shell:

单人模式#make installworld


mergemaster
系统询问是否删除/var/tmp/temproot目录时,按d键进行删除(用来更新或修改/etc的配置文件)


Shell:

单人模式#mergemaster

How should I deal with this? [Use the existing /var/tmp/temproot]d


系统提示发现/etc/rc.d/jail文件与旧的对比有变化,按键盘q键退出查看。询问对新文件怎么处理?按i键安装?还是按d键删除?还是按m键?我们没有编辑过的文件就选择新的,所以按i键选择安装。


Shell:

*** Displaying differences between ./etc/rc.d/jail and installed version

--- /etc/rc.d/jail
Fri Jan 12 15:42:21 2007

q

How should I deal with this? [Leave it for later]i


系统提示发现/etc/hosts文件与旧的对比有变化,按键盘q键退出查看。询问对新文件怎么处理?按i键安装?还是按d键删除?还是按m键?我们编辑过的文件就保留旧的配置,所以按d键选择删除新的。


Shell:

*** Displaying differences between ./etc/hosts and installed version

--- /etc/hosts
Sun Nov 25 05:21:04 2007

+++./etc/hosts Sun Nov 25 20:29:23 2007

q

How should I deal with this? [Leave it for later]d


系统提示发现/etc/mote文件与旧的对比有变化,按键盘q键退出查看。询问对新文件怎么处理?按i键安装?还是按d键删除?还是按m键?motd的作用就是你登入系统时出现的那个欢迎词,我们看看新的欢迎词有没有变化,所以按i键选择安装新的。


Shell:

*** Displaying differences between ./etc/motd and installed version

--- /etc/motd
Sun Nov 24 21:22:58 2007

+++./etc/motd
Sun Nov 25 20:29:23 2007

q

How should I deal with this? [Leave it for later]i


要不要删除/var/tmp/temproot目录,直接回车就行。


Shell:

Do you wish to delete what is left of /var/tmp/temproot? [no]


reboot(重启服务器)


Shell:

单人模式#reboot



Step 5 内核编译前后对比.






激动人心的时刻来临了,等了好几个小时后,我们现在要看看是否新内核安装成功了。


内核文件大小对比


编译后:


Shell:

du -h /boot/kernel


18M /boot/kernel


du -h /boot/kernel/kernel


2.7M /boot/kernel/kernel



编译前:


Shell:

du -h /boot/kernel.old/


23M /boot/kernel.old/


du -h /boot/kernel.old/kernel


6.8M /boot/kernel.old/kernel


内核配置文件名称对比


编译前:


Shell:

uname -a


FreeBSD ohaha.3322.org 6.2-RELEASE FreeBSD 6.2-RELEASE #0: Fri Jan 12 10:40:27 UTC 2007
[email=root@dessler.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC]root@dessler.cse.buffalo.edu:
/usr/obj/usr/src/sys/GENERIC[/email] i386




编译后:


Shell:

uname -a


FreeBSD ohaha.3322.org 6.2-RELEASE-p8 FreeBSD 6.2-RELEASE-p8 #0: Sun Nov 25 12:04:05 CST 2007
[email=root@WOW.ohaha.3322.org:/usr/obj/usr/src/sys/WOW i386]root@WOW.ohaha.3322.org:
/usr/obj/usr/src/sys/WOW i386[/email]



内核编译前后SSH侦听端口协议对比


编译后(去除IPV6支持)


Shell:

netstat -an


tcp4 0 0 *.22 *.* LISTEN



编译前:


Shell:

netstat -an


tcp4 0 0 *.22 *.* LISTEN


tcp6 0 0 *.22 *.* LISTEN


登入时欢迎信息的对比


编译后(显示更人性化,居然会有一些操作技巧提示^_^)


Shell:

FreeBSD 6.2-RELEASE-p8 (WOW) #0: Sun Nov 25 12:04:05 CST 2007

Welcome to FreeBSD!

Before seeking technical support, please use the following resources:


>.............


You may also use sysinstall( to re-enter the installation and

configuration utility.
Edit /etc/motd to change this login announcement.

To obtain a neat PostScript rendering of a manual page, use ``-t'' switch

of the man(1) utility: ``man -t ''.
For example:

man -t grep > grep.ps
# Save the PostScript version to a file

or
man -t printf | lp
# Send the PostScript directly to printer



编译前:


Shell:

Welcome to FreeBSD!

Before seeking technical support, please use the following resources:


>………………



注:文中所说大约XX时间,是根据不同的机器配置会有出入。主要是看你的CPUCPU够强劲,速度就够快,时间也就会少。


编译内核时CPU和内存占用


Shell:

top


CPU states: 92.9% user,0.0% nice,6.7% system,0.4% interrupt,0.0% idle


Mem: 26M Active, 721M Inact, 141M Wired, 200K Cache, 111M Buf, 107M Free





Step 4 内核编译完后的清理.





内核编译完成后,需要进行清理为下次编译做准备:


清理编译内核后的临时文件
Shell:


cd /usr/obj/


chflags -R noschg *


rm -rf *


至此内核编译安装完成。






Step 6 F.A.Q.









阅读(1992) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~