Showing posts with label 企业应用. Show all posts
Showing posts with label 企业应用. Show all posts

Friday, April 25, 2008

How to patch your OpenBSD

Every OS needs to be patched, even for OpenBSD, either for security reasons, reliability ones, bug fixes or new functions.

To patch OpenBSD, you need first to know whether there are any patches released/applicable for your version of release. For OpenBSd, there are two ways you can check if there are any patches available. First, and recommended, is to check the errata (http://www.openbsd.org/errata.html) page. Second is to subscribe to "announce " and "security-announce" mailing lists. for more details on how, check OpenBSD web page or send a mail to majordomo@openbsd.org with subject "help".


In OpenBSD, there are 3 ways to patch your system with all the patches.
1. upgrade your system to -current branch, since all patches and fixes are incorporated into -current.

This is not suitable for most users because of the ever-changing code for -current.

2. upgrade your system to -stable branch of your your release.

By doing this, you'll need to fetch or update your source tree using the appropriate -stable branch, and recompile the kernel and userland files. While this is the easiest way and is OK for most users, it take quite a while to download source files and recompile the system, especially for these who has limited bandwidth to Internet.

3. Patch, compile and install individual impacted files.

This is what we will use for our example below. While this requires less bandwidth and typically less time than an entire cvs(1) checkout/update and source code compilation, this is sometimes the most difficult option, as there is no one universal set of instructions to follow. Sometimes you must patch, recompile and install one application, other times, you might have to recompile entire sections of the tree if the problem is in a library file.

Once you've identified the patch you need to apply to your system, here are the steps to follow:

++++++++++++++++++Following lines are from www.openbsd.org/faq/faq10.html:

Applying patches.

Patches for the OpenBSD Operating System are distributed as "Unified diffs", which are text files that hold differences to the original source code. They are NOT distributed in binary form. This means that to patch your system you must have the source code from the RELEASE version of OpenBSD readily available. In general, you should have the entire source tree available. If you are running a release from official CDROM, the source trees are available on disk 3, they are also available as files from the FTP servers. We will assume you have the entire tree checked out.

For our example here, we will look at patch 001 for OpenBSD 3.6 dealing with the st(4) driver, which handles tape drives. Without this patch, recovering data from backups is quite difficult. People using a tape drive need this patch, however those without a tape drive may have no particular need to install it. Let's look at the patch:

# more 001_st.patch
Apply by doing:
cd /usr/src
patch -p0 < 001_st.patch

Rebuild your kernel.

Index: sys/scsi/st.c
===================================================================
RCS file: /cvs/src/sys/scsi/st.c,v
retrieving revision 1.41
retrieving revision 1.41.2.1
diff -u -p -r1.41 -r1.41.2.1
--- sys/scsi/st.c 1 Aug 2004 23:01:06 -0000 1.41
+++ sys/scsi/st.c 2 Nov 2004 01:05:50 -0000 1.41.2.1
@@ -1815,7 +1815,7 @@ st_interpret_sense(xs)
u_int8_t skey = sense->flags & SSD_KEY;
int32_t info;

- if (((sense->flags & SDEV_OPEN) == 0) ||
+ if (((sc_link->flags & SDEV_OPEN) == 0) ||
(serr != 0x70 && serr != 0x71))
return (EJUSTRETURN); /* let the generic code handle it */

As you will note, the top of the patch includes brief instructions on applying it. We will assume you have put this patch into the /usr/src directory, in which case, the following steps are used:

# cd /usr/src
# patch -p0 < 001_st.patch
Hmm... Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|Apply by doing:
| cd /usr/src
| patch -p0 < 001_st.patch
|
|Rebuild your kernel.
|
|Index: sys/scsi/st.c
|===================================================================
|RCS file: /cvs/src/sys/scsi/st.c,v
|retrieving revision 1.41
|retrieving revision 1.41.2.1
|diff -u -p -r1.41 -r1.41.2.1
|--- sys/scsi/st.c 1 Aug 2004 23:01:06 -0000 1.41
|+++ sys/scsi/st.c 2 Nov 2004 01:05:50 -0000 1.41.2.1
--------------------------
Patching file sys/scsi/st.c using Plan A...
Hunk #1 succeeded at 1815. <-- Look for this message!
done

Note the "Hunk #1 succeeded" message above. This indicates the patch was applied successfully. Many patches are more complex than this one, and will involve multiple hunks and multiple files, in which case, you should verify that all hunks succeeded on all files. If they did not, it normally means your source tree is not right, you didn't follow instructions carefully, or your patch was mangled. Patches are very sensitive to "white space" -- copying and pasting from your browser will often change tab characters into spaces or otherwise alter the white space of a file, making it not apply.

At this point, you can build the kernel as normal, install it and reboot the system.

Not all patches are for the kernel. In some cases, you will have to rebuild individual utilities. At other times, will require recompiling all utilities statically linked to a patched library. Follow the guidance in the header of the patch, and if uncertain, rebuild the entire system.

Patches that are irrelevant to your particular system need not be applied -- usually.

Tuesday, May 29, 2007

PCBSD内核编译/升级

目的:将PCBSD的内核由FreeBSD 6.1升级至 6.2

步骤:

1. 升级source file至6.2

首先编辑/usr/share/examples/cvsup/standard-supfile文件,修改其中的两个地方:
将其中的*default release=cvs tag=RELENG_6_1一行改为 RELENG_6_2,
将*default host=CHANGE_THIS.FreeBSD.org中的CHANGE_THIS.freebsd.org替换为cvsup.cn.freebsd.org

修改完成後,运行如下命令:
cvsup /usr/share/examples/cvsup/standard-supfile

这个命令将会更新系统源文件至6.2版。

2. 创建内核配置文件MYKERNEL(或任何其他你喜欢的名字)

请以root帐户运行如下的命令:

# cd /usr/src/sys/i386/conf
# mkdir /root/kernels
# cp /PCBSD/conf/PCBSDv1.3 /root/kernels/MYKERNEL
# ln -s /root/kernels/MYKERNEL

这里,你可以编辑MYKERNEL文件,将一些不需要的内核选项去掉,这样编译出的内核将会更简洁,效率更高。比如其中有cpu 486/cpu 586,如果你的CPU是PII以上的,你就可以删除这两行,或者通过在行首加一个#符号来注释掉他们,只保留cpu686就可。

但你一定要清楚每个选项的意思,否则请不要随意更改,不然很可能导致系统无法启动。


3. 编辑/etc/make.conf文件
如果下面的内容不在make.conf文件中,请添加:
CPUTYPE=i686 #i486, i586, i586/mmx, i686, p2, p3, p4, athlon,athlon-xp, athlon64, opteron
RELEASETAG="RELENG_6_2"
SUP_UPDATE=yes
SUP=/usr/local/bin/cvsup
SUPFLAGS=-g -L 2
SUPHOST=cvsup.cn.FreeBSD.org
SUPFILE=/usr/share/examples/cvsup/standard-supfile
PORTSSUPFILE=/usr/share/examples/cvsup/ports-supfile
#DOCSUPFILE=/usr/share/examples/cvsup/doc-supfile
KERNCONF=MYKERNEL

4.编译并安装内核

依次运行如下命令:
#cd /usr/src
#make buildkernel
#make installkernel
#reboot

重启後你的PCBSD系统就是6.2版的内核了。其中buildkernel和installkernel的过程需要很长的时间,尤其是你的CPU和内存不是很多的话。

5. 验证

重启完成後,可以运行如下命令来查看目前的内核版本:

# dmesg | grep RELEASE
FreeBSD 6.2-RELEASE #0: Fri Jan 12 10:40:27 UTC 2007

每个人的输出并不相同,但只要你看到6.2-RELEASE的字样,就表示你已经成功了~

ENJOY!