|
本地可移植操作系统线程库(NPTL)是由RehHat发起并维护的项目,用以取代落后的linuxthreads(包含在Glibc的源码树里)线程库。
LinuxThreads的问题,特别是兼容性上的问题,严重阻碍了Linux上的跨平台应用(如Apache)采用多线程设计,从而使得Linux上的线程应用一直保持在比较低的水平。
而NPTL有许多超越linuxthreads的优点,尤为聚焦于其优秀的标准兼容性。
NPTL本身从不会以牺牲标准兼容性作为代价换取额外的性能;虽然如此,NPTL却体现出国际级的工作性能,其创建线程的速度为传统线程库的500倍。
在技术实现上,NPTL配合glibc和最新的Linux Kernel2.6在信号处理、线程同步、存储管理等多方面进行了优化。
下面介绍在lfs-cvs实现nptl的方法。
需要的软件:
===================
1.运行内核2.6.x并安装有gcc-3.x的宿主系统
fedora本身自带了gcc-3.3.2,只要升级内核就可以了
要注意的是,在这之前要升级新内核所需求的软件(升级列表见内核源码目录的Documentation/Change文件),尤其是procps(fedora自带的版本太旧)。
2.glibc-cvs
glibc的cvs版本包含有nptl的源码,可用以下脚本下载:- #!/bin/sh
- c_year=`date +%Y`
- c_month=`date +%m`
- c_day=`date +%d`
- cvs -z 9 -d :pserver:anoncvs@sources.redhat.com:/cvs/glibc \
- export -d glibc-2.3.3-"$c_year$c_month$c_day" \
- -D "$c_year-$c_month-$c_day UTC" libc && \
- tar jcvf glibc-2.3.3-"$c_year$c_month$c_day".tar.bz2 \
- glibc-2.3.3-"$c_year$c_month$c_day" && \
- rm -rf glibc-2.3.3-"$c_year$c_month$c_day"
复制代码 3.binutils-2.14.90.8
ftp://ftp.kernel.org/pub/linux/devel/binutils/ (HJL)
这是支持nptl的HJL版本,我们用来替代lfs-book里面的FSF版本,因为binutils-2.14不支持nptl,而且这种版本的支持nptl的cvs源码也很难下载。
4.干净的内核头文件
内核头文件主要是用来编译安装glibc的,鉴于nptl与新内核的紧密关系,并考虑到兼容性(有些软件的当前版本还不能用内核2.6的头文件来编译安装),redhat制作了所谓的Sanitized kernel headers。
http://download.fedora.redhat.co ... /development/SRPMS/
5.兼容新内核以及POSIX标准的若干补丁
binutils-2.14.90.0.7-posix-head-tail.patch(这个补丁也可实施于2.14.90.8版本; 2.14.90.0.8版本的binutils已经修正了assert问题,这里不用打nptl hint上提及的fix-assert补丁)
coreutils-5.0-posixver-2.patch(lfs-book自带)
dejagnu-1.4.3-posix-tail.patch
gcc-3.3.2-posix-head-tail.patch
由于glibc两个lfs-hint上的补丁不能适用于旧的cvs版本,所以我更新了两个补丁的版本信息,并且提供glibc-2.3.3-20040207.tar.bz2方便大家下载(cvs下载很慢)。
http://download.linuxsir.cn/LFS/glibc-2.3.3-20040207.tar.bz2
glibc-2.3.3-20040207-fix-asserts.patch- --- glibc-2.3.3-20040207.orig/elf/rtld.c 2004-01-27 21:28:56.000000000 +0000
- +++ glibc-2.3.3-20040207/elf/rtld.c 2004-02-08 05:46:56.920586720 +0000
- @@ -1288,19 +1288,7 @@
- while (GL(dl_loaded)->l_searchlist.r_list[i] != &GL(dl_rtld_map))
- ++i;
- GL(dl_rtld_map).l_prev = GL(dl_loaded)->l_searchlist.r_list[i - 1];
- - if (__builtin_expect (mode, normal) == normal)
- - GL(dl_rtld_map).l_next = (i + 1 < GL(dl_loaded)->l_searchlist.r_nlist
- - ? GL(dl_loaded)->l_searchlist.r_list[i + 1]
- - : NULL);
- - else
- - /* In trace mode there might be an invisible object (which we
- - could not find) after the previous one in the search list.
- - In this case it doesn't matter much where we put the
- - interpreter object, so we just initialize the list pointer so
- - that the assertion below holds. */
- - GL(dl_rtld_map).l_next = GL(dl_rtld_map).l_prev->l_next;
- -
- - assert (GL(dl_rtld_map).l_prev->l_next == GL(dl_rtld_map).l_next);
- + GL(dl_rtld_map).l_next = GL(dl_rtld_map).l_prev->l_next;
- GL(dl_rtld_map).l_prev->l_next = &GL(dl_rtld_map);
- if (GL(dl_rtld_map).l_next != NULL)
- {
复制代码 glibc-2.3.3-20040207-posix-sort.patch- --- glibc-2.3.3-20040207.orig/manual/Makefile 2003-11-12 00:37:03.000000000 +0000
- +++ glibc-2.3.3-20040207/manual/Makefile 2004-02-08 05:48:09.598537992 +0000
- @@ -85,7 +85,7 @@
- # Generate the summary from the Texinfo source files for each chapter.
- summary.texi: stamp-summary ;
- stamp-summary: summary.awk $(filter-out summary.texi, $(texis))
- - $(AWK) -f $^ | sort -t' ' -df +0 -1 | tr '\014' '\012' > summary-tmp
- + $(AWK) -f $^ | sort -t'^L' -df -k 1,1 | tr '\014' '\012' > summary-tmp
- $(move-if-change) summary-tmp summary.texi
- touch $@
复制代码 ncurses-5.3-posix-head.patch
sysvinit-2.85-posix-chown.patch
util-linux-2.12-2.6-headers.patch
6.所有软件包的wget列表文件lfs-cvs-nptl.wget- ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.59.tar.bz2
- ftp://ftp.gnu.org/gnu/automake/automake-1.8.2.tar.bz2
- ftp://ftp.gnu.org/gnu/bash/bash-2.05b.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/bash-2.05b-2.patch
- ftp://ftp.gnu.org/gnu/bison/bison-1.875.tar.bz2
- http://www.linuxfromscratch.org/patches/lfs/cvs/bison-1.875-attribute.patch
- ftp://ftp.kernel.org/pub/linux/devel/binutils/binutils-2.14.90.0.8.tar.bz2
- http://ttervo.vectorstar.net/nptl/binutils-2.14.90.0.7-fix-static-linking.patch
- http://ttervo.vectorstar.net/nptl/posix-patches/binutils-2.14.90.0.7-posix-head-tail.patch
- ftp://sources.redhat.com/pub/bzip2/v102/bzip2-1.0.2.tar.gz
- ftp://ftp.gnu.org/gnu/coreutils/coreutils-5.0.tar.bz2
- http://www.linuxfromscratch.org/patches/lfs/cvs/coreutils-5.0-uname.patch
- http://www.linuxfromscratch.org/patches/lfs/cvs/coreutils-5.0-posixver-2.patch
- http://www.linuxfromscratch.org/patches/lfs/cvs/coreutils-5.0-hostname-2.patch
- ftp://ftp.gnu.org/pub/gnu/dejagnu/dejagnu-1.4.3.tar.gz
- http://ttervo.vectorstar.net/nptl/posix-patches/dejagnu-1.4.3-posix-tail.patch
- ftp://ftp.gnu.org/gnu/diffutils/diffutils-2.8.1.tar.gz
- http://aleron.dl.sourceforge.net/sourceforge/e2fsprogs/e2fsprogs-1.34.tar.gz
- ftp://ftp.gnu.org/gnu/ed/ed-0.2.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/ed-0.2-mkstemp.patch
- http://freshmeat.net/redir/expect/2476/url_tgz/expect.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/expect-5.40.0-spawn.patch
- ftp://ftp.astron.com/pub/file/file-4.07.tar.gz
- http://freshmeat.net/redir/findutils/15023/url_tgz/findutils-4.1.20.tar.gz
- ftp://ftp.gnu.org/gnu/non-gnu/flex/flex-2.5.4a.tar.gz
- ftp://ftp.gnu.org/gnu/gawk/gawk-3.1.3.tar.bz2
- http://downloads.linuxfromscratch.org/gawk-3.1.3.patch
- http://ttervo.vectorstar.net/nptl/glibc-2.3-20031101-fix-asserts.patch
- http://ttervo.vectorstar.net/nptl/posix-patches/glibc-2.3-20031101-posix-sort.patch
- http://download.fedora.redhat.com/pub/fedora/linux/core/development/SRPMS/glibc-kernheaders-2.4-8.43.src.rpm
- http://ttervo.vectorstar.net/nptl/util-linux-2.12-2.6-headers.patch
- http://www.iagora.com/~espel/rpm2cpio
- ftp://ftp.gnu.org/pub/gnu/gcc/gcc-3.3.2.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/gcc-3.3.2-specs-1.patch
- http://www.linuxfromscratch.org/patches/lfs/cvs/gcc-3.3.2-no_fixincludes-1.patchhttp://ttervo.vectorstar.net/nptl/posix-patches/gcc-3.3.2-posix-head-tail.patch
- ftp://ftp.gnu.org/gnu/gcc/gcc-2.95.3.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/gcc-2.95.3-2.patch
- http://www.linuxfromscratch.org/patches/lfs/cvs/gcc-2.95.3-no-fixinc.patch
- http://www.linuxfromscratch.org/patches/lfs/cvs/gcc-2.95.3-returntype-fix.patch
- ftp://ftp.gnu.org/gnu/gettext/gettext-0.13.1.tar.gz
- http://ftp.uos.ac.kr/p/GNU/gnu/grep/grep-2.5.1.tar.bz2
- http://ftp.uos.ac.kr/p/GNU/gnu/groff/groff-1.19.tar.gz
- ftp://alpha.gnu.org/pub/gnu/grub/grub-0.94.tar.gz
- http://ftp.uos.ac.kr/p/GNU/alpha/gzip/gzip-1.3.5.tar.gz
- ftp://ftp.gnu.org/gnu/inetutils/inetutils-1.4.2.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/inetutils-1.4.2-no_server_man_pages-1.patch
- ftp://ftp.win.tue.nl/pub/linux-local/utils/kbd/kbd-1.12.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/kbd-1.12-more-programs-1.patch
- http://freshmeat.net/redir/less/5583/url_tgz/less-381.tar.gz
- http://downloads.linuxfromscratch.org/lfs-bootscripts-1.12.tar.bz2
- http://www.linuxfromscratch.org/~winkie/downloads/lfs-utils/lfs-utils-0.4.3.tar.bz2
- http://ftp.uos.ac.kr/p/GNU/gnu/libtool/libtool-1.5.tar.gz
- ftp://ftp.gnu.org/gnu/m4/m4-1.4.tar.gz
- ftp://ftp.gnu.org/gnu/make/make-3.80.tar.bz2
- http://downloads.linuxfromscratch.org/MAKEDEV-1.7.bz2
- http://freshmeat.net/redir/man/6177/url_bz2/man-1.5m2.tar.bz2
- http://www.linuxfromscratch.org/patches/lfs/cvs/man-1.5m2-80cols.patch
- ftp://ftp.kernel.org/pub/linux/docs/manpages/man-pages-1.65.tar.bz2
- ftp://ftp.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.0-pre9.tar.bz2
- ftp://ftp.gnu.org/gnu/ncurses/ncurses-5.3.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/ncurses-5.3-etip-2.patch
- http://ttervo.vectorstar.net/nptl/posix-patches/ncurses-5.3-posix-head.patch
- http://www.tazenda.demon.co.uk/phil/net-tools/net-tools-1.60.tar.bz2
- http://www.linuxfromscratch.org/patches/lfs/cvs/net-tools-1.60-miitool-gcc33-1.patch
- ftp://ftp.gnu.org/pub/gnu/patch/patch-2.5.4.tar.gz
- http://freshmeat.net/redir/perl/7742/url_tgz/perl-5.8.3.tar.gz
- http://www.linuxfromscratch.org/patches/lfs/cvs/perl-5.8.3-libc-1.patch
- ftp://ftp.cistron.nl/pub/people/svm/procinfo-18.tar.gz
- http://freshmeat.net/redir/procps/8384/url_tgz/procps-3.1.15.tar.gz
- http://heanet.dl.sourceforge.net/sourceforge/psmisc/psmisc-21.4.tar.gz
- ftp://ftp.gnu.org/gnu/sed/sed-4.0.9.tar.gz
- http://freshmeat.net/redir/shadow/9477/url_bz2/shadow-4.0.4.1.tar.bz2
- http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.4.1.tar.gz
- ftp://ftp.cistron.nl/pub/people/miquels/sysvinit/sysvinit-2.85.tar.gz
- http://ttervo.vectorstar.net/nptl/posix-patches/sysvinit-2.85-posix-chown.patch
- http://ftp.uos.ac.kr/p/GNU/alpha/tar/tar-1.13.25.tar.gz
- http://heanet.dl.sourceforge.net/sourceforge/tcl/tcl8.4.5-src.tar.gz
- http://freshmeat.net/redir/texinfo/10367/url_bz2/texinfo-4.6.tar.bz2
- http://ftp.cwi.nl/aeb/util-linux/util-linux-2.12.tar.gz
- ftp://ftp.vim.org/pub/vim/unix/vim-6.2.tar.bz2
- http://freshmeat.net/redir/zlib/12352/url_bz2/zlib-1.2.1.tar.bz2
- http://umn.dl.sourceforge.net/sourceforge/romfs/genromfs-0.5.1.tar.gz
- http://busybox.net/downloads/busybox-1.00-pre7.tar.bz2
- http://cvs.jg555.com/viewcvs.cgi/*checkout*/scripts/system/mkinitrd?rev=HEAD&content-type=text/plain
复制代码 这里推荐大家使用我的wget下载脚本,它能很方便地管理你的下载过程。- # Wget Script with history-logged feature.
- # Written by home_king <home_king@163.com>
-
- wget_list=$1
-
- if [ -n "$wget_list" ] && [ -e "$wget_list" ];then
- rm -f Error.log
- for i in `grep -E '^*tp://' "$wget_list"`; do
- if [ -n $i ] && [ ! -e ${i##*/} ] || [ -e "${i##*/}.part" ]; then
- wget -c $i -O "${i##*/}.part" && \
- mv "${i##*/}.part" ${i##*/}
- [ $? -gt 0 ] && echo "${i##*/}" >> Error.log
- fi
- done
- [ -e Error.log ] && \
- echo "Unable to download below packages with wrong urls:" && \
- cat Error.log && \
- echo "Also see Error.log in detail."
- fi
复制代码
NOTE:
1.关于文件系统的选择,reiser4还不能支持内核2.6.2,而且还十分不成熟;
另外,与其使用没有针对内核2.6.2进行优化的reiserfs(3.x),还不如使用已经十分完善的ext3。
2.据小丑奇兵兄的经验,gcc-3.3.2只能配合linuxthreads成功安装kde-3.2,
但对于nptl,只能使用gcc-cvs。
如果大家以后想安装kde-3.2,就应该使用gcc-cvs。
但要注意的是,这里的补丁不能打在cvs版本上,应该对照补丁内容,手工去修改涉及的源码文件,正如我对glibc-cvs所做的一样。
对lfs-cvs添加的安装过程:
===================================
由于使用nptl以及新内核,我们需要修正或添加若干安装步骤。
我上面提及的补丁都应该在第五六章安装相应软件时打上,在这里我就不一一列出。
Chapter05:
-----------------------
1.Install kernel-2.6.2 headers
解压内核2.6.2的源码包,按lfs-book上的做,但是注意要用make include/asm替代make symlinks。
2.Install Glibc - ../glibc-2.3*/configure --prefix=/tools --disable-profile \
- --with-headers=/tools/include --with-binutils=/tools/bin \
- --enable-add-ons=nptl --enable-kernel=current --without-gd \
- --without-cvs --with-tls
复制代码
Chapter06:
-----------------------
1.在chroot之前挂载/dev/shm- mount -t tmpfs none $LFS/dev/shm
复制代码 2.安装内核2.6的头文件- make mrproper
- make include/linux/version.h
- make include/asm
- mkdir /usr/src/glibcheaders
- cp -HR include/asm /usr/src/glibcheaders
- cp -R include/asm-generic /usr/src/glibcheaders
- cp -R include/linux /usr/src/glibcheaders
- touch /usr/src/glibcheaders/linux/autoconf.h
复制代码 3.Install Glibc- ../glibc-2.3*/configure --prefix=/usr --libexecdir=/usr/bin \
- --disable-profile --with-headers=/usr/src/glibcheaders \
- --enable-add-ons=nptl --enable-kernel=current --without-cvs \
- --with-tls
复制代码 4.安装完Glibc后立即安装干净的头文件- tar jxvf glibc-kernelheaders.tar.bz2
- cd usr/include
- cp -R asm-i386 /usr/include/asm
- cp -R linux /usr/include
- mv /usr/include/asm /usr/include/asm-glibc
- mv /usr/include/linux /usr/include/linux-glibc
- ln -s /usr/include/asm-glibc /usr/include/asm
- ln -s /usr/include/linux-glibc /usr/include/linux
复制代码 这里作软链接的原因是因为下面要安装的inetutils使用内核2.6.2的头文件才能成功编译,所以我们就作链接方便后面修改。
5.安装完binutils后立即安装m4,bison,flex
由于使用的binutils是HJL版本,所以要配合m4,bison,flex才能成功编译其他软件(这里也是小丑奇兵兄的经验之谈)。
6.Install inetutils
安装前- ln -sf /usr/src/glibcheaders/asm /usr/include/asm
- ln -sf /usr/src/glibcheaders/asm-generic /usr/include/asm-generic
- ln -sf /usr/src/glibcheaders/linux /usr/include/linux
复制代码 安装后,因为后面的e2fsprogs只能用内核2.4的头文件才能成功安装- ln -sf /usr/include/asm /usr/include/asm-2.4
- ln -sf /usr/include/linux /usr/include/linux-2.4
- rm /usr/include/asm-generic
复制代码
7.安装module-init-tools
内核2.6使用了新的模块加载工具替代modutils。- ./configure --prefix=/
- make
- make install
复制代码
8.安装内核2.6
安装完内核2.6的最后一步make CC=/opt/gcc-2.95.3/bin/gcc install,默认的install.sh假设你安装了lilo,否则找不到出错。而lfs是用grub的,所以出错后我们手工把bzImage和System.map复制到/boot下面。- cp arch/i386/boot/bzImage /boot/lfskernel
- cp System.map /boot
复制代码 最后配置menu.lst就可以啦。
后话:
按以上步骤我们也可以应用在nALFS上,这样就不用每次都手工去做,守在电脑旁。
不过如果这样做,对原profile的修正工作量很大,尤其是软件包的package.ent,我写了两个脚本来自动生成package.ent。
1.md5sum_it
把它放在sources目录下,执行./md5sum_it,随即生成md5list, 内容是所有软件包的md5sum。- #!/bin/sh
- # Created md5sum list of all packages and patches downloaded in PATH.
- #
- # Written by home_king<home_king@163.com>
- #
- rm -f md5list tmpfile
- ls > tmpfile
- cat tmpfile | \
- while read ifile; do
- if [ -f $ifile ] && [ "${ifile##*.}" = "bz2" ] || [ "${ifile##*.}" = "gz" ] || [ "${ifile##*.}" = "patch" ]; then
- md5sum $ifile >> md5list
- fi
- done
- rm -f tmpfile
- echo 'md5list has been created successfully!!!'
复制代码 2.AutoPro_it
./AutoPro_it md5list- #!/bin/sh
- # Auto create package.ent from md5list
- # Written by home_king<home_king@163.com>
- plist=$1
- rm -f package.ent
- if [ -f $plist ]; then
- cat $plist | \
- while read md5 filename; do
- ver_tmp=${filename##*-}
- ver=${ver_tmp%%.tar*}
- if [ "${filename##*.}" = "patch" ]; then
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%.*}-patch-md5 "$md5">" >> package.ent
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%%-*}-patch "$filename"" >> package.ent
- echo >> package.ent
- fi
- if [ "${filename##*.}" = "bz2" ] || [ "${filename##*.}" = "gz" ]; then
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%%-*}-md5 "$md5">" >> package.ent
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%%-*}-version "$ver">" >> package.ent
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%%-*}-package "$filename">" >> package.ent
- echo -n '<!ENTITY ' >> package.ent
- echo "${filename%%-*}-directory "${filename%%-*}-$ver">" >> package.ent
- echo >> package.ent
- fi
-
- done
- fi
复制代码
以上就是我的lfs总结,望兄弟们多多指点。
参考:
http://www.au.linuxfromscratch.org/hints/downloads/files/nptl.txt
感谢小丑奇兵兄的帮助。 |
|