第九天 1-8 实战 : 从光盘中提取二进制包并恢复丢失的文件
简介:使用cpio和rpm2cpio命令,提取rpm安装包中,丢失的文件。前提是我们必须明确的知道丢失的文件及其安装路径
背景:当在linux中,修复系统时明确知道是丢了哪个文件,但是在此时强制安装丢失文件相应的rpm包时又会出现很多依赖关系提示。
我们只需要这个丢掉的文件而已,可以找到丢失文件的相关rpm包,然后用cpio及rpm2cpio组合,把文件提取出来,然后再复制到丢失文件的相应位置
功能介绍:cpio命令
In copy-out mode,
cpio copies files into an archive. It reads a list of filenames, one per line, on the standard input,
and writes the archive onto the standard output.
A typical way to generate the list of filenames is with the find command;
you should give find the -depth option to minimize problems with permissions on directories that are unreadable.
我们将要使用的命令为:cpio -idv [filepath]
-i #指运行在copy-in mode
-d #指在当需要的时候,创建目录
-v #指列出进度
rpm2cpio命令 格式:rpm2cpio [filename]
rpm2cpio converts the .rpm file specified as a single argument to a cpio archive on standard out.
If a '-' argument is given, an rpm stream is read from standard in.
例如:
rpm2cpio rpm-1.1-1.i386.rpm
rpm2cpio - < glint-1.0-1.i386.rpm
rpm2cpio glint-1.0-1.i386.rpm | cpio -dium
实验:
[root@xiaogan ~]# which httpd /usr/sbin/httpd [root@xiaogan ~]# rpm -qf `which httpd` httpd-2.4.6-40.el7.x86_64 [root@xiaogan ~]# rm /etc/httpd/conf/httpd.conf -rf [root@xiaogan ~]# ls /etc/httpd/conf/* /etc/httpd/conf/magic [root@xiaogan ~]# ls -a /etc/httpd/conf/* /etc/httpd/conf/magic [root@xiaogan ~]# ls -l /etc/httpd/conf/* -rw-r--r-- 1 root root 13077 9月 17 2015 /etc/httpd/conf/magic [root@xiaogan ~]# rm -rf etc [root@xiaogan ~]# ls a Documents httpd.conf nginx-1.11.2.tar.gz run usr anaconda-ks.cfg Downloads initial-setup-ks.cfg Pictures Templates var Desktop extundelete-0.2.4.tar.bz2 Music Public test Videos [root@xiaogan ~]# rpm2cpio /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm | cpio -idv ./etc/httpd/conf/httpd.conf ./etc/httpd/conf/httpd.conf 7701 blocks [root@xiaogan ~]# ls etc/httpd/conf/httpd.conf etc/httpd/conf/httpd.conf [root@xiaogan ~]# cp etc/httpd/conf/httpd.conf /etc/httpd/conf/. [root@xiaogan ~]# rpm -e httpd
这是试验中碰到的问题,在缺少文件的情况下,还是卸载成功了,但会提示警告信息 [root@xiaogan ~]# which httpd /usr/sbin/httpd [root@xiaogan ~]# rpm -qf `which httpd` httpd-2.4.6-40.el7.centos.4.x86_64 [root@xiaogan ~]# ls /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf [root@xiaogan ~]# ls a Downloads nginx-1.11.2.tar.gz test anaconda-ks.cfg extundelete-0.2.4.tar.bz2 Pictures Videos Desktop initial-setup-ks.cfg Public Documents Music Templates [root@xiaogan ~]# cp /etc/httpd/conf/httpd.conf . [root@xiaogan ~]# rm /etc/httpd/conf/httpd.conf -rf [root@xiaogan ~]# ls /etc/httpd/conf/httpd.conf ls: cannot access /etc/httpd/conf/httpd.conf: No such file or directory [root@xiaogan ~]# rpm -e httpd warning: file /etc/httpd/conf/httpd.conf: remove failed: No such file or directory [root@xiaogan ~]# which httpd /usr/bin/which: no httpd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) [root@xiaogan ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm warning: /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: httpd-tools = 2.4.6-40.el7 is needed by httpd-2.4.6-40.el7.x86_64 [root@xiaogan ~]# rpm -ivh /mnt/Packages/httpd-tools-2.4.6-40.el7.x86_64.rpm warning: /mnt/Packages/httpd-tools-2.4.6-40.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] package httpd-tools-2.4.6-40.el7.centos.4.x86_64 (which is newer than httpd-tools-2.4.6-40.el7.x86_64) is already installed file /usr/bin/ab from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 file /usr/bin/htdbm from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 file /usr/bin/htdigest from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 file /usr/bin/htpasswd from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 file /usr/bin/httxt2dbm from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 file /usr/bin/logresolve from install of httpd-tools-2.4.6-40.el7.x86_64 conflicts with file from package httpd-tools-2.4.6-40.el7.centos.4.x86_64 [root@xiaogan ~]# rpm2cpio /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm |cpio -idv ./etc/httpd/conf/httpd.conf ./etc/httpd/conf/httpd.conf 7701 blocks [root@xiaogan ~]# ls a Documents extundelete-0.2.4.tar.bz2 Music Public Videos anaconda-ks.cfg Downloads httpd.conf nginx-1.11.2.tar.gz Templates Desktop etc initial-setup-ks.cfg Pictures test [root@xiaogan ~]# cp etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf cp: cannot create regular file ‘/etc/httpd/conf/httpd.conf’: No such file or directory [root@xiaogan ~]# ld /etc/httpd ld: cannot find /etc/httpd: No such file or directory [root@xiaogan ~]# rpm2cpio /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm | cpio -duim 7701 blocks [root@xiaogan ~]# ls /etc/httpd ls: cannot access /etc/httpd: No such file or directory [root@xiaogan ~]# ll total 1032 -rw-r--r-- 1 root root 0 8月 7 10:10 a -rw-------. 1 root root 1798 7月 27 21:54 anaconda-ks.cfg drwxr-xr-x. 2 root root 6 7月 27 22:11 Desktop drwxr-xr-x. 2 root root 6 7月 27 22:11 Documents drwxr-xr-x. 2 root root 6 7月 27 22:11 Downloads drwxr-xr-x 5 root root 52 8月 7 14:58 etc -rw-r--r-- 1 root root 108472 8月 3 23:01 extundelete-0.2.4.tar.bz2 -rw-r--r-- 1 root root 11753 8月 7 14:50 httpd.conf -rw-------. 1 root root 1891 7月 27 22:04 initial-setup-ks.cfg drwxr-xr-x. 2 root root 6 7月 27 22:11 Music -rw-r--r-- 1 root root 924979 8月 6 23:09 nginx-1.11.2.tar.gz drwxr-xr-x. 2 root root 6 7月 27 22:11 Pictures drwxr-xr-x. 2 root root 6 7月 27 22:11 Public drwxr-xr-x 3 root root 18 8月 7 14:58 run drwxr-xr-x. 2 root root 6 7月 27 22:11 Templates drwxr-xr-x 3 root root 26 8月 7 10:10 test drwxr-xr-x 7 root root 65 8月 7 14:58 usr drwxr-xr-x 6 root root 48 8月 7 14:58 var drwxr-xr-x. 2 root root 6 7月 27 22:11 Videos [root@xiaogan ~]# cd etc/ [root@xiaogan etc]# ls httpd logrotate.d sysconfig [root@xiaogan etc]# which tree /usr/bin/tree [root@xiaogan etc]# cd .. [root@xiaogan ~]# tree etc etc |-- httpd | |-- conf | | |-- httpd.conf | | `-- magic | |-- conf.d | | |-- autoindex.conf | | |-- README | | |-- userdir.conf | | `-- welcome.conf | |-- conf.modules.d | | |-- 00-base.conf | | |-- 00-dav.conf | | |-- 00-lua.conf | | |-- 00-mpm.conf | | |-- 00-proxy.conf | | |-- 00-systemd.conf | | `-- 01-cgi.conf | |-- logs -> ../../var/log/httpd | |-- modules -> ../../usr/lib64/httpd/modules | `-- run -> /run/httpd |-- logrotate.d | `-- httpd `-- sysconfig |-- htcacheclean `-- httpd 8 directories, 17 files [root@xiaogan ~]# mv etc/* /etc mv: overwrite ‘/etc/logrotate.d’? y^Hn^C [root@xiaogan ~]# clear [root@xiaogan ~]# ls etc logrotate.d sysconfig [root@xiaogan ~]# which httpd /usr/bin/which: no httpd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin) [root@xiaogan ~]# rpm -e httpd error: package httpd is not installed [root@xiaogan ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm warning: /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY error: Failed dependencies: httpd-tools = 2.4.6-40.el7 is needed by httpd-2.4.6-40.el7.x86_64 [root@xiaogan ~]# rpm -ivh /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm --nodeps warning: /mnt/Packages/httpd-2.4.6-40.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Preparing... ################################# [100%] Updating / installing... 1:httpd-2.4.6-40.el7 ################################# [100%] [root@xiaogan ~]# which httpd /usr/sbin/httpd [root@xiaogan ~]# ls /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf [root@xiaogan ~]# rpm -e httpd [root@xiaogan ~]#