升级完了ports和src后,基础搭建就算完成了,现在我们就开始编译内核吧。
进入内核配置文件目录
# cd /usr/src/sys/i386/conf
# mkdir /root/kernels
# cp GENERIC /root/kernels/IM.RD.BJ
# ln -s /root/kernels/IM.RD.BJ
IM.RD.BJ为你新内核配置文件的名字 ,可以自己取个合适的。
编译内核
# cd /usr/src
# make buildkernel KERNCONF=IM.RD.BJ
安装内核
# make installkernel KERNCONF=IM.RD.BJ
编译内核之前可以配置自己的内核文件 IM.RD.BJ ,使她符合自己的要求。
具体的内核配置文件可以参照官方相关文档哦。
编译完成以后,我们现在的工作就是对系统一些参数进行优化调整。
# ee /boot/loader.conf
加入:
kern.ipc.maxsockets=65535
kern.maxusers=256
kern.ipc.nmbclusters=32768
kern.ipc.nsfbufs=2496
# ee /etc/sysctl.conf
加入:
net.inet.ip.sourceroute=0
net.inet.ip.accept_sourceroute=0
net.inet.tcp.drop_synfin=1
kern.maxvnodes=8446
kern.maxfiles=65536
kern.maxfilesperproc=32768
kern.ipc.somaxconn=32768
kern.ipc.shmmax=67108864 # 64MB
kern.ipc.shmall=32768
kern.ipc.shm_allow_removed=0
kern.coredump=1
net.inet.ip.portrange.last=65535
net.inet.tcp.msl=2500
net.inet.udp.blackhole=1
net.inet.udp.log_in_vain=1
net.inet.tcp.always_keepalive=1
net.inet.udp.blackhole=1
net.inet.raw.maxdgram=65536
net.inet.raw.recvspace=65536
net.inet.tcp.blackhole=2
net.inet.tcp.delayed_ack=1
net.inet.tcp.inflight.enable=1
net.inet.tcp.inflight.debug=0
net.inet.tcp.inflight.rttthresh=10
net.inet.tcp.inflight.min=6144
net.inet.tcp.inflight.max=1073725440
net.inet.tcp.inflight.stab=20
net.local.stream.sendspace=65536
net.local.stream.recvspace=65536
net.inet.tcp.sendspace=32768
net.inet.tcp.recvspace=65536
net.inet.udp.maxdgram=24576
net.inet.udp.recvspace=49152
net.inet.ip.rtexpire=3600
net.inet.ip.rtminexpire=2
net.inet.ip.random_id=1
net.inet.icmp.icmplim=100
net.inet.icmp.icmplim_output=1
net.inet.icmp.drop_redirect=1
net.inet.icmp.log_redirect=1
net.inet.tcp.keepidle=600000
net.inet.ip.redirect=0
net.isr.direct=1
net.inet.ip.intr_queue_maxlen=4096
kern.ipc.shm_use_phys=1
net.inet.ip.fastforwarding=1
vfs.hirunningspace=4194304
vfs.ufs.dirhash_maxmem=33554432 # 32MB
vfs.write_behind=0
security.bsd.see_other_uids=1
security.bsd.see_other_gids=1
设置完成以后reboot机器。
如果要不重启机器加载改动的参数还可以使用:
# /etc/rc.d/sysctl reload
好了,参数优化好了以后,我们现在还要考虑到以后要用ports方式安装软件,这些软件都是以源码形式安装的, 所以我们这里得做两方面的优化工作,第一是优化编译器,也就是GCC的编译指令,这样可以提高软件的效率,第二就是为ports下载软件加加速了。
系统安装完成之后,默认是没有make.conf文件的,我们自己新建一个就可以了。(自力更生,丰衣足食,哈!)
首先我们调整一下GCC的编译参数。
# touch /etc/make.conf
# ee /etc/make.conf
加入:
CFLAGS= -march=pentium-m -O2 -pipe -msse2 -mmmx -mfpmath=sse
CXXFLAGS= ${CFLAGS}
其中-march是指你机器的CPU,不知道CPU型号可以用下面的方法来查,我的是IBMT43,结果如下:
# sysctl hw.model
hw.model: Intel(R) Pentium(R) M processor 1.86GHz
以下是对照表,按照你的CPU型号改就OK了(这里只提供了CPU的对照,没有加上参数,网上有很多加好参数的,其实未必适合,所以大家看看这篇文章,自己加吧,这样放心,错了也知道原因。)。
i386 (Intel)
CFLAGS= -march=i386
CXXFLAGS+= -march=i386
i486 (Intel)
CFLAGS= -march=i486
CXXFLAGS+= -march=i486
Pentium 1 (Intel)
CFLAGS= -march=pentium
CXXFLAGS+= -march=pentium
Pentium MMX (Intel)
CFLAGS= -march=pentium-mmx
CXXFLAGS+= -march=pentium-mmx
Pentium PRO (Intel)
CFLAGS= -march=pentiumpro
CXXFLAGS+= -march=pentiumpro
Pentium II (Intel)
CFLAGS= -march=pentium2
CXXFLAGS+= -march=pentium2
Celeron (Mendocino), aka Celeron1 (Intel)
CFLAGS= -march=pentium2
CXXFLAGS+= -march=pentium2
Pentium III (Intel)
CFLAGS= -march=pentium3
CXXFLAGS+= -march=pentium3
Celeron (Coppermine) aka Celeron2 (Intel)
CFLAGS= -march=pentium3
CXXFLAGS+= -march=pentium3
Celeron (Willamette?) (Intel)
CFLAGS= -march=pentium4
CXXFLAGS+= -march=pentium4
Pentium 4 (Intel)
CFLAGS= -march=pentium4
CXXFLAGS+= -march=pentium4
Eden C3/Ezra (Via)
CFLAGS= -march=i586 -m3dnow
CXXFLAGS+= -march=i586 -m3dnow
K6 (AMD)
CFLAGS= -march=k6
CXXFLAGS+= -march=k6
K6-2 (AMD)
CFLAGS= -march=k6-2
CXXFLAGS+= -march=k6-2
K6-3 (AMD)
CFLAGS= -march=k6-3
CXXFLAGS+= -march=k6-3
Athlon (AMD)
CFLAGS= -march=athlon
CXXFLAGS+= -march=athlon
Athlon-tbird, aka K7 (AMD)
CFLAGS= -march=athlon-tbird
CXXFLAGS+= -march=athlon-tbird
Athlon-tbird XP (AMD)
CFLAGS= -march=athlon-xp
CXXFLAGS+= -march=athlon-xp
Athlon 4(AMD)
CFLAGS= -march=athlon-4
CXXFLAGS+= -march=athlon-4
Athlon XP (AMD)
CFLAGS= -march=athlon-xp
CXXFLAGS+= -march=athlon-xp
Athlon MP (AMD)
CFLAGS= -march=athlon-mp
CXXFLAGS+= -march=athlon-mp