rpm作为linux最重要的软件管理工具,有着不可或缺的地位,连yum都要依赖于rpm的存在才能正常使用,所以掌握rpm的恢复还是很重要的,下面就来看一下如何恢复rpm。
卸载rpm软件包
[[email protected] ~]$ rpm -e rpm
error: Failed dependencies:
rpm = 4.11.3-17.el7 is needed by (installed) rpm-libs-4.11.3-17.el7.x86_64
rpm is needed by (installed) color-filesystem-1-13.el7.noarch
rpm = 4.11.3-17.el7 is needed by (installed) rpm-python-4.11.3-17.el7.x86_64
rpm >= 0:4.4.2 is needed by (installed) yum-3.4.3-132.el7.centos.0.1.noarch
rpm >= 4.1.1 is needed by (installed) createrepo-0.9.9-23.el7.noarch
rpm is needed by (installed) policycoreutils-2.2.5-20.el7.x86_64
rpm >= 4.9.0 is needed by (installed) redhat-rpm-config-9.1.0-68.el7.centos.noarch
rpm = 4.11.3-17.el7 is needed by (installed) rpm-build-4.11.3-17.el7.x86_64
[[email protected] ~]$ yum remove rpm
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package rpm.x86_64 0:4.11.3-17.el7 will be erased
--> Processing Dependency: rpm for package: color-filesystem-1-13.el7.noarch
--> Processing Dependency: rpm >= 4.1.1 for package: createrepo-0.9.9-23.el7.noarch
--> Processing Dependency: rpm >= 4.4.2 for package: yum-3.4.3-132.el7.centos.0.1.noarch
--> Processing Dependency: rpm = 4.11.3-17.el7 for package: rpm-libs-4.11.3-17.el7.x86_64
--> Processing Dependency: rpm = 4.11.3-17.el7 for package: rpm-python-4.11.3-17.el7.x86_64
--> Processing Dependency: rpm for package: policycoreutils-2.2.5-20.el7.x86_64
--> Processing Dependency: rpm >= 4.9.0 for package: redhat-rpm-config-9.1.0-68.el7.centos.noarch
...
--> Processing Dependency: totem(x86-64) = 1:3.14.3-5.el7 for package: 1:totem-nautilus-3.14.3-5.el7.x86_64
--> Running transaction check
---> Package gnome-classic-session.noarch 0:3.14.4-13.el7 will be erased
---> Package totem-nautilus.x86_64 1:3.14.3-5.el7 will be erased
--> Finished Dependency Resolution
Error: Trying to remove "yum", which is protected
[[email protected] ~]$ rpm -e rpm --nodeps
[[email protected] ~]$ rpm -qa
-bash: /usr/bin/rpm: No such file or directory
卸载之后再次是使用rpm工具查看所有的软件包时会报错误的,也就意味rpm软件包已经卸载不能使用了。
恢复rpm软件包
rpm软件包的恢复需要借助于linux系统光盘,首先就是要将linux系统光盘加载到系统中,将启动项改为从光盘启动“CD-ROM Drive”。
在下面的选择界面中选择为“Troubleshooting”——“Rescue a CentOS system”进入到光盘的救援模式中。
在下面的界面中选择第一项“Continue”
进入到救援模式之后,就可以使用linux命令了,使用df可以查看到分区的情况,可能注意到了这里这linux系统里的分区情况不一样,这里显示的不是linux系统的分区,而是光盘中分区情况,叫做伪系统,使用ls可以查看显示所有的目录,其中“/mnt/sysimage”才是linux系统的根目录,进入目录里面查看一下,是不是和linux根目录的目录是一样的呢。
在救援模式中,也可以使用linux命令进行操作。
如果在当前命令行,执行“rpm -ivh”会报一些错误,安装软件时,会以当前目录为主,而我们需要将rpm软件包安装到linux正常启动的系统中去,所以需要加一个参数“--root=/mnt/sysimage”。
安装完rpm软件包后,重新启动系统,发现rpm软件又回来,到此rpm的恢复已经完成了,可以正常使用rpm对软件进行管理了。