RPM详解——精选推荐

  • 格式:pdf
  • 大小:546.35 KB
  • 文档页数:7

RPM详解

概述RPM⽂件结构

RPM包⽂件⼀般包含4部分:Lead、Signature、Header、Payload

lead----开头的标识部分,⽤于标识此份⽂件为⼀个RPM包

Signature-----数字签名,通常包括针对头部的签名和针对载荷的签名

Header--------头部,通常包括版权信息,版本号,包描述等信息;有时还包含⼀些特定的标签(Tag),⽐如PRE Tag就包含了rpm包在安装前需要执⾏的预安装脚本。Payload-------载荷,包含实际安装的⽂件RPM命令

安装及升级

安装的⼀般步骤install a package, it goes through a number of steps:

1.Checking the package and the files it wants to install

2.Performing preinstallation tasks

3.Uncompressing the files and placing them in the proper locations

4.Performing post-processing tasks

5.Updating the RPM Database

RPM数据库的相关⽂件位于/var/lib/rpm/⽬录下。新安装

@前⾯为⽤户名及密码,⽤户名uncljoe ,密码workers

升级rpm -Uvh ⽆论软件包存在与否都执⾏升级

或rpm -Fvh仅针对已安装的软件包进⾏升级

升级时,RPM会对每个⽂件,⽐对三个版本的MD5校验值(old package file,current file,new package file)。如果oldpackage file与new package file的MD5校验值⼀样,但current file 不同,说明新⽼版本的⽂件是⼀样的,但管理员编辑过该⽂件(通常是⼀些配置⽂件),rpm 会保留current file(保留管理员的所做的配置),⽽不会⽤新包中的⽂件覆盖。⽽如果oldpackage file与new package file 的MD5校验值不⼀样,⽆论current file校验结果如何,都会⽤新包的⽂件覆盖,同时如果current file与old package file的MD5校验不⼀致(也就是管理员有做过配置),rpm会以.rpmsave为后缀名⾃动备份current file⽂件

卸载rpm -e aspell-en-ca-0.33.7.1-16 aspell-en-gb-0.33.7.1-16

移除rpm包是可以使⽤的选项:--test移除前先测试

--allmatches当有多个rpm包,匹配rpm命令给出的包名时,将所有匹配的包⼀并移除--nodeps忽略依赖性问题

--repackage移除前先备份rpm包,并存放于/var/spool/repackage⽬录(注意:所备份的rpm包并⾮完整的rpm包,不能⽤于重新安装)

列出RPM包的⽂件列表,可以这样:rpm -qpl bash-3.2-147.4.1.7407.1.PTF.898762.x86_64.rpm

或者rpm2cpio xcopilot-0.6.6-3.i386.rpm | cpio –t

从RPM包中提取⽂件rpm2cpio xcopilot-0.6.6-3.i386.rpm | cpio –ivd./usr/doc/xcopilot-0.6.6/README

此命令将在当前⽬录下⽣成/usr/doc/xcopilot-0.6.6/⼦⽬录及⽂件README

测试安装过程:rpm -ivh --test

⾃定义安装⽬录:

前提是要安装的rpm包必须是relocatable(可重定位)的rpm -Uvh --prefix /new/directory package.rpm

或rpm -Uvh --relocate /old/directory=/new/directorypackage.rpm

注意两者的区别,--prefix是指修改⽂件安装时的默认路径前缀,默认前缀可以⽤命令rpm -qpi package.rpm 查看relocation字段读出,如下图

--prefix 选项会把默认路径前缀替换为指定的⽬录。

⽽--relocate则是将待安装⽂件路径的某⼀段替换为新的指定的⽬录,⽽要替换的部分可以是默认路径前缀也可以是其他。

⽐如:rpm -ivh --prefix /opt bash-debuginfo-3.0-27.el4.4.x86_64.rpm

rpm -ivh --relocate /usr=/opt bash-debuginfo-3.0-27.el4.4.x86_64.rpm

安装效果都是⼀样的,都是把原路径中/usr部分替换为/opt,也就是安装到/opt⽬录下

另外,要注意的是,--relocate只会替换安装⽂件中标记为relocatable的⽂件的路径,也就是说不⼀定所有⽂件都是可以修改路径的,如果要强制替换所有⽂件路径,可结合使⽤--badreloc参数rpm -ivh --badreloc --relocate/old/directory=/new/directorypackage.rpm

在虚拟root环境安装rpmrpm -U --root /tmp --dbpath /var/lib/rpm jikes-1.16-1.i386.rpm

--dbpath指明rpm数据库的位置,虚拟root环境(/tmp)下需包含RPM所依赖标准C函数库,否则会报错

error: Failed dependencies: ld-linux.so.2 is needed by jikes-1.16-1 libc.so.6 is needed by jikes-1.16-1 libm.so.6 is needed byjikes-1.16-1 libstdc++-libc6.2-2.so.3 is needed by jikes-1.16-1 libc.so.6(GLIBC_2.0) is needed by jikes-1.16-1libc.so.6(GLIBC_2.1) is needed by jikes-1.16-1 libc.so.6(GLIBC_2.1.3) is needed by jikes-1.16-1其它⼀些有⽤的选项参数

查询

查询谁依赖bash包rpm -q --whatrequires bash

查询/bin/grep⽂件属于哪个包rpm -qf /bin/greprpm -qf `which grep`

rpm -qf $(which grep)

查询rpm包的信息rpm -qi package.rpm

查询包组信息

利⽤之前提到的rpm -qi命令可查询⼀个包所属的包组,如

进⽽可查询该包组的信息rpm -qg “System Environment/Base”

查询⼀个包的⽂件列表rpm -ql bash

或rpm -qlv bash

查询⼀个包的配置⽂件rpm -qc

查询⼀个包的⽂档⽂件rpm -qd

RPM数据库

RPM数据库的相关⽂件位于/var/lib/rpm/⽬录下

验证&签名

验证RPM包

使⽤rpm -V (或--verify)验证⼀个rpm包的完整性及依赖性

正常情况下,⽆输出代表⼀切ok,例如# rpm -V bash

S.5....T. /bin/bash

该命令输出中包含S、5、T三个标志,三者分别代表Size(⼤⼩)、MD5、Time(修改⽇期),说明/bin/bash⽂件的⼤⼩,MD5校验值、修改⽇期与初始安装时的不⼀致。验证控制选项:

检查整个系统的rpm完整性rpm -Va --nofiles

参考:http://www.doczj.com/doc/e046ae5cf524ccbff021845c.html /linux/6.htmlrpm --import 导⼊rpm制作者发布的公钥,然后使⽤rpm -K --nodigest

来检测来源的合法性,显⽰OK,就代表该rpm包来源合法制作RPM包的数字签名过程

验证RPM包的数字签名

疑问:可不可以这样,直接在⽹上发布软件包的特征码并公布相应单向加密算法,让⽤户下载软件包后,⽤相同的加密算法重新计算⼀次特征码,然后与⽹上公布的特征码进⾏对⽐,如果⼀致则说明软件包是完整的,来源合法的;否则则不然。这么⼀来,相⽐原来的⽅式就少了⼀次加密步骤,操作起来也更简单,岂不更好?

答:的确,这样做也可以确保软件包的完整性,⽽且步骤也简单些。但前提是,你必须有⼀个公开的,稳定可靠的发布平台来发布你所制作的软件包的特征码,⽽这对于⼀般的发布者⽽⾔是不易做到的,⽽且如果那么做,意味着你每制作⼀个软件包都必须发布⼀次对应的特征码,⽽上⾯的⽅式只需发布⼀次公钥就⾏,显然更有可操作性https://http://www.doczj.com/doc/e046ae5cf524ccbff021845c.html /security/team/key/

常见RPM验证报错:If verifying the signature fails, an error message such as the following is displayed: error: V3 DSA signature: BAD, key ID0352860f

If it is a new, header-only, signature, an error message such as the following is displayed: error: Header V3 DSA signature:BAD, key ID 0352860f

If you do not have the appropriate key installed to verify the signature, the message contains the word NOKEY such as:warning: V3 DSA signature: NOKEY, key ID 0352860f

Tips

话说rc⽂件The --rcfile option tells the rpm command to use one or more other files to initialize the RPM system. These files tell the rpmcommand the system architecture, operating system, and default location of the RPM database, among a host of othersettings.

The term rc comes from Unix shells, with initialization files such as .cshrc for the C shell, csh. The term rc was originally ashorthand for run commands. An rc is a file of commands that run when the application starts up. For example, the C shell,csh, runs the commands in file named .cshrc when the shell starts.