安裝yumdownloader工具:
# yum install yum-utils
設定源:
[base-src]
name=CentOS-5.4 - Base src -
baseurl=http://vault.centos.org/5.4/os/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=os
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
[updates-src]
name=CentOS-5.4 - Updates src-centos
baseurl=http://vault.centos.org/5.4/updates/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=updates
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#packages used/produced in the build but not released
[addons-src]
name=CentOS-5.4 - Addons src -
baseurl=http://vault.centos.org/5.4/addons/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=addons
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras-src]
name=CentOS-5.4 - Extras src-centos
baseurl=http://vault.centos.org/5.4/extras/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=extras
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#additional packages that extend functionality of existing packages
[centosplus-src]
name=CentOS-5.4 - Plus src-centos
baseurl=http://vault.centos.org/5.4/centosplus/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
#contrib - packages by Centos Users
[contrib-src]
name=CentOS-5.4 - Contrib src-centos
baseurl=http://vault.centos.org/5.4/contrib/SRPMS/
#mirrorlist=http://mirrorlist.centos.org/?release=5.4&arch=SRPMS&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
怎麼檢視某個命令的原始碼
比如想檢視uname這個命令的原始碼
[root@localhost usr]# whereis uname
uname: /bin/uname /usr/share/man/man1/uname.1.gz /usr/share/man/man2/uname.2.gz /usr/share/man/man1p/uname.1p.gz /usr/share/man/man3p/uname.3p.gz
[root@localhost usr]# rpm -qf /bin/uname
coreutils-8.5-7.fc14.i686
##沒有yumdownloader 的話可以這樣子安裝#yum install yum-utils
[workhard@localhost tmp]$ yumdownloader --source coreutils-8.5-7.fc14.i686 ##source下載原始碼包
到這一步後有兩種方法可以檢視到原始碼包,第一種方法
[workhard@localhost tmp]$ rpm -qpl coreutils-8.5-7.fc14.src.rpm | grep tar ##查詢rpm中的 tar檔案,原始碼一般放在這裡
coreutils-8.5.tar.xz
##從rpm包中提取指定的檔案
[workhard@localhost tmp]$ rpm2cpio coreutils-8.5-7.fc14.src.rpm | cpio -idv coreutils-8.5.tar.xz
coreutils-8.5.tar.xz
9446 blocks
[workhard@localhost coreutils-8.5]$ tar xjvf coreutils-8.5.tar.xz
##到解壓出來的coreutils-8.5/src/中就能找到相關的原始碼了
第二種方法:安裝原始碼包
[workhard@localhost tmp]$ rpm -i coreutils-8.5-7.fc14.src.rpm ##安裝原始碼包
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
##centos和rhel一般安裝後的原始碼在/usr/src/redhat下的各個目錄下,但fedora是在~/rpmbuild/SOURCES/
##可以通過locate命令查詢程式碼包被安裝到哪裡了
[workhard@localhost tmp]$ locate *coreutils*tar*
/home/workhard/tmp/coreutils-8.5.tar.xz
/home/workhard/rpmbuild/SOURCES/coreutils-8.5.tar.xz
[workhard@localhost tmp]$ cd /home/workhard/rpmbuild/SOURCES/c
[workhard@localhost SOURCES]$ tar Jxvf coreutils-8.5.tar.xz
[workhard@localhost src]$ cd coreutils-8.5/src/
[workhard@localhost src]$ ll uname*
-rw-r--r--. 1 workhard workhard 48 Jan 1 2010 uname-arch.c
-rw-r--r--. 1 workhard workhard 10024 Jan 1 2010 uname.c
-rw-r--r--. 1 workhard workhard 146 Jan 1 2010 uname.h
-rw-r--r--. 1 workhard workhard 49 Jan 1 2010 uname-uname.c
安裝*.src.rpm後怎麼解除安裝
[workhard@localhost SOURCES]$ cd /home/workhard/rpmbuild/SOURCES
[workhard@localhost SPECS]$ rpmbuild --rmsource --rmspec coreutils.spec
**相關說明
一、yumdownloader comes from the yum-utils package, if you don't have that installed already.
#yum install yum-utils
二、RPM用法
rpm {-i|--install} [install-options] PACKAGE_FILE ...
-f, --file FILE
Query package owning FILE.
-p, --package PACKAGE_FILE
Query an (uninstalled) package PACKAGE_FILE.
-l, --list
List files in package.
-qf:查詢指定檔案屬於哪個RPM軟體包
-qpl:列出RPM軟體包內的檔案資訊;
三、rpm2cpio - Extract cpio archive from RPM Package Manager (RPM) package.
顧名思義,rpm2cpio是將rpm包檔案轉換成cpio歸檔檔案
四、CPIO用法
cpio - copy files to and from archives
-i 抽取的意思,和"--extract"等同
-d 建立目錄,和"--make-directories"等同
-v 冗餘資訊輸出,和"--verbose"等同
五、rpmbuild用法
--rmsource
Remove the sources after the build
--rmspec
Remove the spec file after the build