1 安装新内核 ,两个内核
umount /dev/sr0 ---取消挂载
cd /misc/cd ---换成centos6.8的光盘后挂载
rpm -ivh kernel-2.6.32-642.el6.x86_64.rpm --oldpackage ---降级安装内核
[root@centos6 boot]#rpm -q kernel
kernel-2.6.32-696.el6.x86_64
kernel-2.6.32-642.el6.x86_64
2 rm -f /bin/rpm ,安装Rpm包恢复之 或 cpio
- 方法一:cpio
[root@centos6 app]#which rpm ---查看rpm来源于哪个文件
/bin/rpm
[root@centos6 app]#rm -f /bin/rpm ---删除
[root@centos6 app]#rpm ---rpm已无法正常使用
-bash: /bin/rpm: No such file or directory
[root@centos6 app]#rpm2cpio /misc/cd/Packages/rpm-4.8.0-55.el6.x86_64.rpm |cpio -itv ---预览包内文件
[root@centos6 app]#cd / ---因为rpm要存放在/bin/rpm,所有进入根目录,并且根目录已经有bin这个目录,所以不用-d解包的时候再创建目录,直接解包就可以
[root@centos6 /]#rpm2cpio /misc/cd/Packages/rpm-4.8.0-55.el6.x86_64.rpm |cpio -iv ./bin/rpm
./bin/rpm
4007 blocks
[root@centos6 /]#rpm ---rpm可以正常使用
RPM version 4.8.0
Copyright (C) 1998-2002 - Red Hat, Inc.
This program may be freely redistributed under the terms of the GNU GPL
Usage: rpm [-aKfgpWHqVcdilsKiv?] [-a|--all] [-f|--file] [-g|--group] [-p|--package] [-W|--ftswalk] [--pkgid] [--hdrid] [--fileid]
[--specfile] [--triggeredby] [--whatrequires] [--whatprovides] [--nomanifest] [-c|--configfiles] [-d|--docfiles]
[--dump] [-l|--list] [--queryformat=QUERYFORMAT] [-s|--state] [--nofiledigest] [--nomd5] [--nofiles] [--nodeps]
[--noscript] [--comfollow] [--logical] [--nochdir] [--nostat] [--physical] [--seedot] [--xdev] [--whiteout]
[--addsign] [-K|--checksig] [--delsign] [--import] [--resign] [--nodigest] [--nosignature] [--initdb] [--rebuilddb]
[--aid] [--allfiles] [--allmatches] [--badreloc] [-e|--erase <package>+] [--excludedocs] [--excludepath=<path>]
[--fileconflicts] [--force] [-F|--freshen <packagefile>+] [-h|--hash] [--ignorearch] [--ignoreos] [--ignoresize]
[-i|--install] [--justdb] [--nodeps] [--nofiledigest] [--nomd5] [--nocontexts] [--noorder] [--nosuggest] [--noscripts]
[--notriggers] [--oldpackage] [--percent] [--prefix=<dir>] [--relocate=<old>=<new>] [--replacefiles] [--replacepkgs]
[--test] [-U|--upgrade <packagefile>+] [--quiet] [-D|--define 'MACRO EXPR'] [-E|--eval 'EXPR'] [--macros=<FILE:...>]
[--nodigest] [--nosignature] [--rcfile=<FILE:...>] [-r|--root ROOT] [--querytags] [--showrc] [--quiet] [-v|--verbose]
[--version] [-?|--help] [--usage] [--scripts] [--setperms] [--setugids] [--conflicts] [--obsoletes] [--provides]
[--requires] [--info] [--changelog] [--xml] [--triggers] [--last] [--dupes] [--filesbypkg] [--fileclass]
[--filecolor] [--fscontext] [--fileprovide] [--filerequire] [--filecaps]
- 方法二 进入rescue模式
1、按ESC进入救援模式
2、选择语言
3、选择键盘类型
4、跳过网络
5、救援模式操作系统的根是挂载到/mnt/sysimage/
6、进入shell
7、创建/mnt/cdrom目录,并将光盘挂载到这个目录下
8、重新安装rpm包
这里需要注意的是要用--force,因为只是破坏了一个文件,不是卸载之后重新安装,所以要用--force进行安装;--root=/mnt/sysimage/ 表示指明操作系统的根在哪个目录下
9、切换回真正的根后查看rpm是否安装成功并退出、重启
3 /usr/bin/java 找出来自哪个包
[root@centos7 ~]#ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 Jul 14 11:18 /usr/bin/java -> /etc/alternatives/java
[root@centos7 ~]#ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 Jul 14 11:18 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64/jre/bin/java
4 删除/lib64/libc.so.6 恢复之
①删除该文件
glibc-2.12-1.209.el6.x86_64
[root@centos6 ~]#rm -f /lib64/libc.so.6 ---删除该文件
[root@centos6 ~]#ls
ls: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@centos6 ~]#cd
[root@centos6 ~]#pwd
/root
[root@centos6 ~]#rpm
rpm: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
[root@centos6 ~]#reboot ---删除之后发现好多命令都无法使用了,说明这个文件是个库文件,好多程序都依赖于它,只能手动关电源的方式关机,然后重启进入救援模式
reboot: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
②进入救援模式
说明:我们只是破坏了一个文件,并不是把这个包都卸载了,所以要用--force强制重新安装。
5 reset.sh
[root@centos7 test]#cat reset.sh
#!/bin/bash
##################################
#Filename:reset.sh
#Description:
#Date:2017-08-01
#Author:zhangdazhi
#Version:2.0
#####################################
cat>>/root/.bashrc<<end
alias cdnet=‘cd /etc/sysconfig/network-scripts/’
alias editnet=‘vim /etc/sysconfig/network-scripts/fcfg-ens33’
alias cdpack='cd /run/media/root/CentOS\ 7\ x86_64/Packages/'
alias p='poweroff'
alias egrep='egrep --color=auto'
alias ct='cd /app/test'
end
cat>>/root/.bash_profile<<end
PATH=$PATH:/app
PS1="\[\e[31m\][\u@\h \W]\\$\[\e[0m\]"
end
echo "set nu">>.vimrc
name=$1
id $name &> /dev/null &&{ echo $name is exist; }||{ useradd $name;echo $name is created;echo magedu|passwd --stdin $name; }
echo script is finished
unset name;set --
rpm --import RPM-GPG-KEY-CentOS-7
rpm -q tree &>/dev/null ||rpm -ivh /run/media/root/CentOS\ 7\ x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm&>/dev/null
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat >> etc/yum.repos.d/base.repo<<end
[base]
name=centos7repo
baseurl=file:///run/media/root/CentOS\ 7\ x86_64/
gpgcheck=0
end
rpm -q autofs &> /dev/null ||yum -q -y install autofs
systemctl start autofs
systemctl enable autofs
rpm -qf /usr/bin/lsb_release &>/dev/null ||yum -q -y install redhat-lsb-core