强制升级glibc2.14到2.17问题

源码编译安装,关键是恢复、比对。备份系统文件,用Live系统恢复原系统状态;比对发行版包管理器软件包的安装路径,移除冲突,比对发行版编译软件包时的编译选项,如果函数库没编译某些特性,可能会导致系统崩溃或已有的应用程序不可用。

pwd /root/linux-3.7 # make INSTALL_HDR_PATH=/root/headers headers_install # pwd /root/glibc-2.17/build $ ../configure --prefix=/usr --enable-add-ons=nptl,libidn --with-headers=/root/headers/include --enable-kernel=3.7.0 $ make $ make install_root=pwd/dest install

pwd

/root/linux-3.7

make INSTALL_HDR_PATH=/root/headers headers_install

pwd

/root/glibc-2.17/build
$ ../configure --prefix=/usr --enable-add-ons=nptl,libidn --with-headers=/root/headers/include --enable-kernel=3.7.0
$ make
$ make install_root=pwd/dest install
warning: 这里如果使用make DESTDIR=...将失效,因为glibc的Makefile是手写的,不是用autotools生成的,DESTDIR是GNU标准,autotools兼容GNU标准
nptl,libidn是为了跟Debian原有的程序兼容

ls dest/usr/lib/librt.so dest/usr/lib/librt.so # ldd /bin/ls | grep librt.so librt.so.1 => /lib/i686/cmov/librt.so.1 (0xb7730000)

ls dest/usr/lib/librt.so

dest/usr/lib/librt.so

ldd /bin/ls | grep librt.so

librt.so.1 => /lib/i686/cmov/librt.so.1 (0xb7730000)

发现不对劲,make install后的glibc,跟系统原来的glibc安装路径不同,这样会导致应用程序使用不同版本的glibc文件而崩溃
调试方法:

make install_root=pwd/dest -p > /tmp/make $ dpkg -S librt.so libc6-dev: /usr/lib/librt.so libc6: /lib/librt.so.1 libc6-i686: /lib/i686/cmov/librt.so.1 # apt-get remove libc6-i686

make install_root=pwd/dest -p > /tmp/make

$ dpkg -S librt.so
libc6-dev: /usr/lib/librt.so
libc6: /lib/librt.so.1
libc6-i686: /lib/i686/cmov/librt.so.1

apt-get remove libc6-i686

启发: 源码编译后,安装前,要查看比对发行版软件包管理器已安装的相关软件包的路径

接着,通过比对dest/和系统软件包的安装路径,备分系统重要的文件夹,以便系统崩溃后,用U盘里的GNU/Linux恢复系统
比对:

cat /tmp/diff.sh #! /bin/bash destdir=$1 pkg=$2 list=/tmp/list.diff pkglist=/tmp/list.pkg backupdir="/backup/pkg" answer=n if [ x"$destdir" == x -o x"$pkg" == x ] ; then echo "Usage: diff.sh destdir debian-pkg" exit 1 fi dpkg -L $pkg 2>&1 1>/dev/null if [ $? -ne 0 ] ; then echo "error: $pkg doesn't exists." exit 1 fi echo -n "backup $pkg to $backupdir/$pkg.tar?(y/[n])" read -N 1 -t 5 answer echo rm -f $list $pkglist for name in dpkg -L $pkg do if [ ! -e $destdir/$name -a -f $name ] ; then echo $name | tee -a $list fi if [ x$answer == x"y" -a -f $name ] ; then echo $name >> $pkglist fi done mkdir -p $backupdir tar cf $backupdir/$pkg.diff.tar -T $list 2>/dev/null if [ x$answer == x"y" ] ; then tar cf $backupdir/$pkg.pkg.tar -T $pkglist 2>/dev/null fi # /tmp/diff.sh dest/ libc6 # /tmp/diff.sh dest/ libc6-dev

cat /tmp/diff.sh

! /bin/bash

destdir=$1
pkg=$2
list=/tmp/list.diff
pkglist=/tmp/list.pkg
backupdir="/backup/pkg"
answer=n
if [ x"$destdir" == x -o x"$pkg" == x ] ; then
echo "Usage: diff.sh destdir debian-pkg"
exit 1
fi
dpkg -L $pkg 2>&1 1>/dev/null
if [ $? -ne 0 ] ; then
echo "error: $pkg doesn't exists."
exit 1
fi

echo -n "backup $pkg to $backupdir/$pkg.tar?(y/[n])"
read -N 1 -t 5 answer
echo
rm -f $list $pkglist
for name in dpkg -L $pkg
do
if [ ! -e $destdir/$name -a -f $name ] ; then
echo $name | tee -a $list
fi
if [ x$answer == x"y" -a -f $name ] ; then
echo $name >> $pkglist
fi
done
mkdir -p $backupdir
tar cf $backupdir/$pkg.diff.tar -T $list 2>/dev/null
if [ x$answer == x"y" ] ; then
tar cf $backupdir/$pkg.pkg.tar -T $pkglist 2>/dev/null
fi

/tmp/diff.sh dest/ libc6

/tmp/diff.sh dest/ libc6-dev

备份:

ls dest/ etc lib sbin usr var # du -sh /etc/ /lib/ /sbin/ /usr/ /var/ # mkdir /backup # cp -R /etc/ /lib/ /sbin/ /usr/ /var/ /backup/

ls dest/

etc lib sbin usr var

du -sh /etc/ /lib/ /sbin/ /usr/ /var/

mkdir /backup

cp -R /etc/ /lib/ /sbin/ /usr/ /var/ /backup/

假想要进行的安装:

make install # while read name > do > rm -f $name > done < /tmp/list.diff

make install

while read name

do
rm -f $name
done < /tmp/list.diff
出现错误:

test ! -x /root/glibc-2.17/build/elf/ldconfig || LC_ALL=C LANGUAGE=C \ /root/glibc-2.17/build/elf/ldconfig \ /lib /usr/lib LD_SO=ld-linux.so.2 CC="gcc" /usr/bin/perl scripts/test-installation.pl /root/glibc-2.17/build/ Segmentation fault make[1]: *** [install] Error 139 make[1]: Leaving directory `/root/glibc-2.17' make: *** [install] 错误 2 #

test ! -x /root/glibc-2.17/build/elf/ldconfig || LC_ALL=C LANGUAGE=C
/root/glibc-2.17/build/elf/ldconfig
/lib /usr/lib
LD_SO=ld-linux.so.2 CC="gcc" /usr/bin/perl scripts/test-installation.pl /root/glibc-2.17/build/
Segmentation fault
make[1]: *** [install] Error 139
make[1]: Leaving directory `/root/glibc-2.17'
make: *** [install] 错误 2

试验正常的安装方法:
如果是编译安装比系统低版本的glibc,要用tar方式安装,然后删除/tmp/list.diff里的文件,再ldconfig。
这里我估计/lib/libc.so.6这些链接文件链接的是原来系统的库文件,所以要用tar方式覆盖以指向新的库文件,否则删除顺序出错,可能导致找不到函数库而导致系统崩溃,还没去做实验证实(懒)。ldconfig会链接高版本的函数库到系统。遇到问题用tar安装是非常好用的方法。这个方法也可以用来安装高版本glibc。

init 1 # cd dest # tar cf - . | (cd / && tar xf -) # while read name > do > rm -f $name > done < /tmp/list.diff # ldconfig -v

init 1

cd dest

tar cf - . | (cd / && tar xf -)

while read name

do
rm -f $name
done < /tmp/list.diff

ldconfig -v

如果是编译安装比系统高版本的glibc

init 1 # make install segment fault # ldconfig -v # make install

init 1

make install

segment fault

ldconfig -v

make install

warning: 不要用那个rm -f $name的/tmp/list.diff方法,目前不知道为什么会失败,难道是glibc的idn add on没装?
这里还有个问题glibc依赖特定版本的gcc和kernel吗?
如果make install的安装方法不成功,就用tar的方法安装吧,make install后面有个check,要测试不少东西,跟binutils, gcc, linux的版本都有关系。

上面那篇IBM文章的作者说,编译安装glibc建议在runlevel 1中进行,直接安装会出错,需要重启系统纠正关系链,如果重启系统仍出错,用U盘的Live系统手动纠正关系链或恢复系统
如果能正常重启系统,进入glibc再make install一次,这次安装通过的话就算安装成功了

验证:

ldd /bin/ls libc.so.6 => /lib/libc.so.6 (0xb76fb000) # ls -l /lib/libc.so.6 lrwxrwxrwx 1 root root 12 1月 5 11:55 /lib/libc.so.6 -> libc-2.17.so # /lib/libc.so.6 GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al. Compiled by GNU CC version 4.4.5. Compiled on a Linux 2.6.39 system on 2013-01-05. # man ls

ldd /bin/ls

libc.so.6 => /lib/libc.so.6 (0xb76fb000)

ls -l /lib/libc.so.6

lrwxrwxrwx 1 root root 12 1月 5 11:55 /lib/libc.so.6 -> libc-2.17.so

/lib/libc.so.6

GNU C Library (GNU libc) stable release version 2.17, by Roland McGrath et al.
Compiled by GNU CC version 4.4.5.
Compiled on a Linux 2.6.39 system on 2013-01-05.

man ls

昨晚在irc.freenode.net上的glibc channel,询问一位IBM glibc开发者,关于glibc开发和编译的事,记录如下:

  • 您正在 #glibc 频道里聊天 * #glibc 的主题是:glibc wiki is at http://sources.redhat.com/glibc/wiki/HomePage | Feedback and FAQ are at http://sources.redhat.com/glibc/wiki/Feedback * #glibc 的主题由 ryanarn 于 Wed Oct 15 03:49:37 2008 设置 * Ajaeger 已退出(Quit: Ajaeger) <c-aries> What tools are you use for reading glibc source code? I use etags, but it usually lead me to wrong place * mjw 已退出(Quit: Leaving) <ryanarn> c-aries: I use grep and a knowledge of the sysdeps directory hierarchy <ryanarn> c-aries: sometimes you have to look at the glibc make output build log to see exactly which files are being picked up and how/when/from-where <ryanarn> c-aries: also, recompiling components with -dD -E will give you macro expanded source if the layers of macros are confusing. <c-aries> Thanks ryanarn. I have another question. What's your develop enviroment? I mean whether you build the newest glibc from git repo or just use the distribution build script? <ryanarn> c-aries: it depends on what your end goal is. I work for IBM enabling new features in GLIBC for new hardware, so I build from master. <ryanarn> if you're a user you should probably be using a distribution source rpm. <c-aries> I read sys_exeve () from kernel, and then reach at /lib/ld-linux.so. I wanna find a way to debug the ld.so actually. <ryanarn> ahh, I wrote a bit of a tutorial on the wiki about debugging the loader.. well I started to. <ryanarn> you need to set up the debugger to debug the loader and then break in the loader very very early. <c-aries> I also curious about how to build the newest glibc repo.. Do you have any good articles or resource instruct me to build the newest repo? <ryanarn> c-aries: the glibc git page on the wiki instructs you how to pull. As far as building... I would grab your distro's source RPM. Do the rpmbuild there, save the log file and then pull the configure invocation out of that and use it for configuring your own build of the git repo. <ryanarn> otherwise you're likely to spend days in configure hell. <c-aries> go hell and you'll find how to build the newest glibc XD. Many thanks ryanarn, you inspired me how to hack glibc, thanks for you clues. * kosaki8 已退出(Ping timeout: 260 seconds) * kosaki2 (kosaki2@nat/redhat/x-nnlnvliklfurxywh) 进入了 #glibc <ryanarn> c-aries: you're welcome

  • 您正在 #glibc 频道里聊天

  • glibc 的主题是:glibc wiki is at http://sources.redhat.com/glibc/wiki/HomePage | Feedback and FAQ are at http://sources.redhat.com/glibc/wiki/Feedback

  • glibc 的主题由 ryanarn 于 Wed Oct 15 03:49:37 2008 设置

  • Ajaeger 已退出(Quit: Ajaeger)
    <c-aries> What tools are you use for reading glibc source code? I use etags, but it usually lead me to wrong place

  • mjw 已退出(Quit: Leaving)
    <ryanarn> c-aries: I use grep and a knowledge of the sysdeps directory hierarchy
    <ryanarn> c-aries: sometimes you have to look at the glibc make output build log to see exactly which files are being picked up and how/when/from-where
    <ryanarn> c-aries: also, recompiling components with -dD -E will give you macro expanded source if the layers of macros are confusing.
    <c-aries> Thanks ryanarn. I have another question. What's your develop enviroment? I mean whether you build the newest glibc from git repo or just use the distribution build script?
    <ryanarn> c-aries: it depends on what your end goal is. I work for IBM enabling new features in GLIBC for new hardware, so I build from master.
    <ryanarn> if you're a user you should probably be using a distribution source rpm.
    <c-aries> I read sys_exeve () from kernel, and then reach at /lib/ld-linux.so. I wanna find a way to debug the ld.so actually.
    <ryanarn> ahh, I wrote a bit of a tutorial on the wiki about debugging the loader.. well I started to.
    <ryanarn> you need to set up the debugger to debug the loader and then break in the loader very very early.
    <c-aries> I also curious about how to build the newest glibc repo.. Do you have any good articles or resource instruct me to build the newest repo?
    <ryanarn> c-aries: the glibc git page on the wiki instructs you how to pull. As far as building... I would grab your distro's source RPM. Do the rpmbuild there, save the log file and then pull the configure invocation out of that and use it for configuring your own build of the git repo.
    <ryanarn> otherwise you're likely to spend days in configure hell.
    <c-aries> go hell and you'll find how to build the newest glibc XD. Many thanks ryanarn, you inspired me how to hack glibc, thanks for you clues.

  • kosaki8 已退出(Ping timeout: 260 seconds)

  • kosaki2 (kosaki2@nat/redhat/x-nnlnvliklfurxywh) 进入了 #glibc
    <ryanarn> c-aries: you're welcome
    后记
    Unix有好多小技巧,一个tar命令,居然会成为slackware的生命线,有tar,就能实现软件包管理的基本功能,还能保存权限复制特殊设备文件,归档供压缩程序使用,太强大了。昨天还了解到源码编译恢复系统的方法,就简简单单地在live系统上cp,什么都恢复了。还有init 1的作用第一次体会到。太兴奋太好玩了。学越久,发现越多小技巧,感觉魅力无穷啊,一个小小的命令能那么有用,太厉害了。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,542评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,596评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,021评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,682评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,792评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,985评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,107评论 3 410
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,845评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,299评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,612评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,747评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,441评论 4 333
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,072评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,828评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,069评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,545评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,658评论 2 350

推荐阅读更多精彩内容