升级原因
Android12项目,在ubuntu 16.04.7版本的服务器编译kernel 5.10出现报错:
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.27'
升级参考
执行到sudo make 和 sudo make install 后提示安装失败。
此时执行cd 和 pwd 之外的指令都提示Segmentation fault,很明显系统崩溃了。重启直接无法开机,也无法进入recovery mode 的root模式进行修复。
修复过程
1、咨询IT没有对系统镜像进行备份,仅备份用户文件数据的硬盘。
2、由于是服务器,不到万不得已不想重装系统,因为有很多其他环境。
3、网上寻找资料
ubuntu系统崩溃,甚至Recovery模式和tty都无法进入,这个方法可以救援!_try ubuntu-优快云博客
误删了Linux系统的libm.so.6文件与libm-2.27.so的软链接导致的开机出现kernel panic的解决方案(图文U盘救援详细教程)-优快云博客
Ubuntu 手动更新glibc导致内核崩溃(无法正常关机/开机启动失败)_ubuntu升级glibc崩溃-优快云博客
3.1 服务器相关的文件多做备份,养成好习惯。
3.2 首先尝试将/lib64下的so 链接到/lib/x86_64-linux-gnu(备份了原始的),重启后可以开机,但是乱码,sudo等指令执行异常,Android代码编译失败。
3.3 网上文章提到手动升级glibc版本主要是 更改了/lib64下的 ld-linux-x86-64.so.2的软链接,使用U盘启动器Try ubuntu后挂载已经崩溃的系统镜像进行更改修复。
sudo mkdir /mnt
sudo mount /dev/sda4 /mnt (我们服务器系统镜像是sda4 注意区分)
sudo chroot /mnt
cd /
sudo mv lib64/ lib64.bak
sudo mkdir lib64
sudo ln -s /lib/x86_64-linux-gnu/ld-2.23.so /lib64/ld-linux-x86-64.so.2
注:在U盘启动的模式下,执行 sudo chroot /mnt 成功,说明异常的系统已能正常开机。
3.4 参考3.3修复后重启,开机后进入文件系统不乱码了。但是编译Android工程还是失败。
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:132:0,
from /disk2/workspace/android/kernel-4.4/scripts/basic/fixdep.c:106:
/usr/include/time.h:37:32: fatal error: bits/types/clock_t.h: 没有那个文件或目录
compilation terminated.
scripts/Makefile.host:91: recipe for target 'scripts/basic/fixdep' failed
make[2]: *** [scripts/basic/fixdep] Error 1
/disk2/workspace/android/kernel-4.4/Makefile:447: recipe for target 'scripts_basic' failed
make[1]: *** [scripts_basic] Error 2
make[1]: *** 正在等待未完成的任务....
3.5 查看ldd版本已经是2.27了,/usr/include的头文件也被替换掉了。这才是导致Android编译失败的原因。下面罗列被改动的文件。
cd glibc-2.27 && mkdir build && cd build/
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
==》config的参数prefix with-headers with-binutils影响的目录
test@m-server:/usr/bin$
-rwxr-xr-x 1 root root 252928 7月 3 10:01 iconv
-rwxr-xr-x 1 root root 1141360 7月 3 10:01 localedef
-rwxr-xr-x 1 root root 141664 7月 3 10:01 locale
-rwxr-xr-x 1 root root 88552 7月 3 10:01 gencat
-rwxr-xr-x 1 root root 6465 7月 3 10:01 mtrace
-rwxr-xr-x 1 root root 15366 7月 3 10:01 tzselect
-rwxr-xr-x 4 root root 51056 7月 3 10:02 getconf
-rwxr-xr-x 1 root root 32280 7月 3 10:02 pcprofiledump
-rwxr-xr-x 1 root root 5291 7月 3 10:02 xtrace
-rwxr-xr-x 1 root root 3283 7月 3 10:02 catchsegv
-rwxr-xr-x 1 root root 81792 7月 3 10:02 getent
-rwxr-xr-x 1 root root 66712 7月 3 10:02 makedb
-rwxr-xr-x 1 root root 83624 7月 3 10:02 sprof
-rwxr-xr-x 1 root root 57512 7月 3 10:02 pldd
-rwxr-xr-x 1 root root 5437 7月 3 10:02 ldd
-rwxr-xr-x 1 root root 4277 7月 3 10:02 sotruss
test@m-server:/usr/include$
-rw-r--r-- 1 root root 5412 7月 3 10:01 limits.h
-rw-r--r-- 1 root root 1955 7月 3 10:01 values.h
-rw-r--r-- 1 root root 2342 7月 3 10:01 gnu-versions.h
-rw-r--r-- 1 root root 15697 7月 3 10:01 features.h
-rw-r--r-- 1 root root 2363 7月 3 10:01 stdc-predef.h
-rw-r--r-- 1 root root 1857 7月 3 10:01 iconv.h
-rw-r--r-- 1 root root 4410 7月 3 10:01 gconv.h
-rw-r--r-- 1 root root 7674 7月 3 10:01 locale.h
-rw-r--r-- 1 root root 17848 7月 3 10:01 langinfo.h
-rw-r--r-- 1 root root 4561 7月 3 10:01 assert.h
-rw-r--r-- 1 root root 10963 7月 3 10:01 ctype.h
-rw-r--r-- 1 root root 4579 7月 3 10:01 libintl.h
-rw-r--r-- 1 root root 1752 7月 3 10:01 nl_types.h
-rw-r--r-- 1 root root 45384 7月 3 10:01 math.h
-rw-r--r-- 1 root root 3583 7月 3 10:01 fpu_control.h
-rw-r--r-- 1 root root 7163 7月 3 10:01 complex.h
-rw-r--r-- 1 root root 5857 7月 3 10:01 fenv.h
-rw-r--r-- 1 root root 31489 7月 3 10:01 tgmath.h
-rw-r--r-- 1 root root 4910 7月 3 10:01 ieee754.h
-rw-r--r-- 1 root root 3669 7月 3 10:01 setjmp.h
-rw-r--r-- 1 root root 12243 7月 3 10:01 signal.h
-rw-r--r-- 1 root root 35784 7月 3 10:01 stdlib.h
-rw-r--r-- 1 root root 1803 7月 3 10:01 monetary.h
-rw-r--r-- 1 root root 11892 7月 3 10:01 inttypes.h
-rw-r--r-- 1 root root 8626 7月 3 10:01 stdint.h
-rw-r--r-- 1 root root 1832 7月 3 10:01 errno.h
-rw-r--r-- 1 root root 1937 7月 3 10:01 ucontext.h
-rw-r--r-- 1 root root 1203 7月 3 10:01 alloca.h
-rw-r--r-- 1 root root 3239 7月 3 10:01 fmtmsg.h
-rw-r--r-- 1 root root 2799 7月 3 10:01 stdio_ext.h
-rw-r--r-- 1 root root 6800 7月 3 10:01 printf.h
-rw-r--r-- 1 root root 29665 7月 3 10:01 stdio.h
-rw-r--r-- 1 root root 918 7月 3 10:01 libio.h
-rw-r--r-- 1 root root 932 7月 3 10:01 _G_config.h
-rw-r--r-- 1 root root 7018 7月 3 10:01 dlfcn.h
-rw-r--r-- 1 root root 6102 7月 3 10:01 malloc.h
-rw-r--r-- 1 root root 21306 7月 3 10:01 obstack.h
-rw-r--r-- 1 root root 2434 7月 3 10:01 mcheck.h
-rw-r--r-- 1 root root 17545 7月 3 10:01 string.h
-rw-r--r-- 1 root root 4752 7月 3 10:01 strings.h
-rw-r--r-- 1 root root 1404 7月 3 10:01 byteswap.h
-rw-r--r-- 1 root root 3189 7月 3 10:01 endian.h
-rw-r--r-- 1 root root 955 7月 3 10:01 memory.h
-rw-r--r-- 1 root root 6050 7月 3 10:01 argz.h
-rw-r--r-- 1 root root 2866 7月 3 10:01 envz.h
-rw-r--r-- 1 root root 31111 7月 3 10:01 wchar.h
-rw-r--r-- 1 root root 2312 7月 3 10:01 uchar.h
-rw-r--r-- 1 root root 10363 7月 3 10:01 time.h
-rw-r--r-- 1 root root 12484 7月 3 10:01 dirent.h
-rw-r--r-- 1 root root 6686 7月 3 10:01 grp.h
-rw-r--r-- 1 root root 6029 7月 3 10:02 pwd.h
-rw-r--r-- 1 root root 42785 7月 3 10:02 unistd.h
-rw-r--r-- 1 root root 6614 7月 3 10:02 glob.h
-rw-r--r-- 1 root root 2501 7月 3 10:02 wordexp.h
-rw-r--r-- 1 root root 22050 7月 3 10:02 regex.h
-rw-r--r-- 1 root root 2295 7月 3 10:02 fnmatch.h
-rw-r--r-- 1 root root 1468 7月 3 10:02 getopt.h
-rw-r--r-- 1 root root 3785 7月 3 10:02 tar.h
-rw-r--r-- 1 root root 4732 7月 3 10:02 sched.h
-rw-r--r-- 1 root root 962 7月 3 10:02 re_comp.h
-rw-r--r-- 1 root root 22 7月 3 10:02 wait.h
-rw-r--r-- 1 root root 2267 7月 3 10:02 cpio.h
-rw-r--r-- 1 root root 6690 7月 3 10:02 spawn.h
-rw-r--r-- 1 root root 10564 7月 3 10:02 fcntl.h
-rw-r--r-- 1 root root 22 7月 3 10:02 poll.h
-rw-r--r-- 1 root root 1501 7月 3 10:02 utime.h
-rw-r--r-- 1 root root 5251 7月 3 10:02 ftw.h
-rw-r--r-- 1 root root 8372 7月 3 10:02 fts.h
-rw-r--r-- 1 root root 3598 7月 3 10:02 termios.h
-rw-r--r-- 1 root root 214 7月 3 10:02 termio.h
-rw-r--r-- 1 root root 1583 7月 3 10:02 ulimit.h
-rw-r--r-- 1 root root 1730 7月 3 10:02 ar.h
-rw-r--r-- 1 root root 4350 7月 3 10:02 a.out.h
-rw-r--r-- 1 root root 1385 7月 3 10:02 libgen.h
-rw-r--r-- 1 root root 264 7月 3 10:02 stab.h
-rw-r--r-- 1 root root 1343 7月 3 10:02 sgtty.h
-rw-r--r-- 1 root root 2494 7月 3 10:02 ttyent.h
-rw-r--r-- 1 root root 2977 7月 3 10:02 paths.h
-rw-r--r-- 1 root root 3111 7月 3 10:02 fstab.h
-rw-r--r-- 1 root root 3358 7月 3 10:02 mntent.h
-rw-r--r-- 1 root root 5223 7月 3 10:02 search.h
-rw-r--r-- 1 root root 2039 7月 3 10:02 error.h
-rw-r--r-- 1 root root 2209 7月 3 10:02 err.h
-rw-r--r-- 1 root root 5232 7月 3 10:02 sysexits.h
-rw-r--r-- 1 root root 25 7月 3 10:02 syscall.h
-rw-r--r-- 1 root root 23 7月 3 10:02 ustat.h
-rw-r--r-- 1 root root 1447 7月 3 10:02 regexp.h
-rw-r--r-- 1 root root 24 7月 3 10:02 syslog.h
drwxr-xr-x 3 root root 4096 7月 3 10:02 scsi
drwxr-xr-x 2 root root 4096 7月 3 10:02 net
-rw-r--r-- 1 root root 5548 7月 3 10:02 wctype.h
-rw-r--r-- 1 root root 5197 7月 3 10:02 shadow.h
-rw-r--r-- 1 root root 4528 7月 3 10:02 gshadow.h
-rw-r--r-- 1 root root 25414 7月 3 10:02 argp.h
-rw-r--r-- 1 root root 2259 7月 3 10:02 crypt.h
-rw-r--r-- 1 root root 41269 7月 3 10:02 pthread.h
-rw-r--r-- 1 root root 2399 7月 3 10:02 semaphore.h
-rw-r--r-- 1 root root 3759 7月 3 10:02 mqueue.h
-rw-r--r-- 1 root root 7456 7月 3 10:02 aio.h
-rw-r--r-- 1 root root 1522 7月 3 10:02 execinfo.h
-rw-r--r-- 1 root root 3476 7月 3 10:02 proc_service.h
-rw-r--r-- 1 root root 16023 7月 3 10:02 thread_db.h
drwxr-xr-x 2 root root 4096 7月 3 10:02 protocols
-rw-r--r-- 1 root root 2031 7月 3 10:02 aliases.h
-rw-r--r-- 1 root root 2840 7月 3 10:02 ifaddrs.h
drwxr-xr-x 2 root root 4096 7月 3 10:02 netipx
drwxr-xr-x 2 root root 4096 7月 3 10:02 netash
drwxr-xr-x 2 root root 4096 7月 3 10:02 netax25
drwxr-xr-x 2 root root 4096 7月 3 10:02 netatalk
drwxr-xr-x 2 root root 4096 7月 3 10:02 netrom
drwxr-xr-x 2 root root 4096 7月 3 10:02 netpacket
drwxr-xr-x 2 root root 4096 7月 3 10:02 netrose
drwxr-xr-x 2 root root 4096 7月 3 10:02 netiucv
drwxr-xr-x 2 root root 4096 7月 3 10:02 neteconet
drwxr-xr-x 2 root root 4096 7月 3 10:02 netinet
-rw-r--r-- 1 root root 12012 7月 3 10:02 resolv.h
-rw-r--r-- 1 root root 28051 7月 3 10:02 netdb.h
drwxr-xr-x 2 root root 4096 7月 3 10:02 arpa
-rw-r--r-- 1 root root 1878 7月 3 10:02 nss.h
drwxr-xr-x 2 root root 4096 7月 3 10:02 rpc
drwxr-xr-x 2 root root 4096 7月 3 10:02 nfs
drwxr-xr-x 2 root root 12288 7月 3 10:02 sys
-rw-r--r-- 1 root root 3047 7月 3 10:02 stropts.h
-rw-r--r-- 1 root root 3222 7月 3 10:02 utmp.h
-rw-r--r-- 1 root root 126 7月 3 10:02 lastlog.h
-rw-r--r-- 1 root root 1569 7月 3 10:02 pty.h
-rw-r--r-- 1 root root 4099 7月 3 10:02 utmpx.h
-rw-r--r-- 1 root root 172464 7月 3 10:02 elf.h
-rw-r--r-- 1 root root 7206 7月 3 10:02 link.h
drwxr-xr-x 23 root root 4096 7月 3 10:02 x86_64-linux-gnu
3.6 使用VM虚拟机安装Ubuntu 16.04.7 LTS(和服务器相同的版本),从虚拟机中拷贝 /usr/bin 和/usr/include 被替换的文件,替换到服务器上后重启,都恢复了。
**** 千万不要升级和内核相关的库,建议直接升级系统版本。*****
**** 小技巧,物理服务器不方便反复尝试,可以用VM虚拟安装相同的镜像模拟;虚拟机还可以保存快照,操作异常后通过快照回到正常的版本。*****