Source RPM으로 rpm 패키지를 만들려면 어떻게 해야 하나요?
💡 요약 정리
- rpmbuild 명령 시 MD5 체크섬 오류가 발생하면 source rpm을 직접 설치한 후 재빌드해야 합니다.
- --nomd5 옵션을 사용해 설치하면 소스코드와 spec 파일이 생성됩니다.
- SPECS 디렉터리의 spec 파일로 rpmbuild -ba 또는 -bb 명령을 실행하여 rpm 또는 binary 패키지를 생성할 수 있습니다.
rpmbuild 명령 실행 시, 아래와 같이 MD5 체크섬 오류가 나타나는 경우가 있습니다. 이때는 source rpm을 직접 설치한 후, rebuild 과정을 거쳐야 합니다.
[root@localhost src]# rpmbuild --rebuild fping-3.4-1.fc19.src.rpm
Installing fping-3.4-1.fc19.src.rpm
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
error: unpacking of archive failed on file /usr/src/redhat/SOURCES/fping-3.4.tar.gz;50f3aef7: cpio: MD5 sum mismatch
error: fping-3.4-1.fc19.src.rpm cannot be installed
[root@localhost src]#
1. Source rpm 설치하기
rpmbuild 전에 source rpm 파일을 설치해야 합니다. 이때 --nomd5 옵션을 사용합니다.
[root@localhost src]# rpm -ivh --nomd5 fping-3.4-1.fc19.src.rpm
1:fping warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
########################################### [100%]
[root@localhost src]# cd /usr/src/redhat/
[root@localhost redhat]# ls
BUILD RPMS SOURCES SPECS SRPMS
[root@localhost redhat]# cd SPECS/
[root@localhost SPECS]# ls
fping.spec
[root@localhost SPECS]# cd ..
[root@localhost redhat]# cd SOURCES/
[root@localhost SOURCES]# ls
fping-3.4.tar.gz
[root@localhost SOURCES]#
- 설치 후
/usr/src/redhat/SOURCES디렉터리에는 해당 소스의 tar.gz 파일(fping-3.4.tar.gz)이 생성되며,/usr/src/redhat/SPECS디렉터리에는 spec 파일(fping.spec)이 생성됩니다.
2. .spec 파일로 rebuild 수행하기
/usr/src/redhat/SPECS 디렉터리에서 .spec 파일을 기반으로 rebuild를 진행합니다.
[root@localhost SPECS]# rpmbuild -ba fping.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.875
+ umask 022
+ cd /usr/src/redhat/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /usr/src/redhat/BUILD
+ rm -rf fping-3.4
+ /bin/gzip -dc /usr/src/redhat/SOURCES/fping-3.4.tar.gz
+ tar -xf -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd fping-3.4
++ /usr/bin/id -u
+ '[' 0 = 0 ']'
+ /bin/chown -Rhf root .
(컴파일과정 중간생략)
Requires: libc.so.6()(64bit) libc.so.6(GLIBC_2.2.5)(64bit) libc.so.6(GLIBC_2.3.4)(64bit) libc.so.6(GLIBC_2.4)(64bit) rtld(GNU_HASH)
Processing files: fping-debuginfo-3.4-1
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/fping-3.4-1-r29907
Wrote: /usr/src/redhat/SRPMS/fping-3.4-1.src.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/fping-3.4-1.x86_64.rpm
Wrote: /usr/src/redhat/RPMS/x86_64/fping-debuginfo-3.4-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.89194
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd fping-3.4
+ rm -rf /var/tmp/fping-3.4-1-r29907
+ exit 0
[root@localhost SPECS]#
[root@localhost SPECS]# cd ..
[root@localhost redhat]# ls
BUILD RPMS SOURCES SPECS SRPMS
[root@localhost redhat]# cd RPMS/x86_64/
[root@localhost x86_64]# ls
fping-3.4-1.x86_64.rpm fping-debuginfo-3.4-1.x86_64.rpm
[root@localhost x86_64]# cd ../../SRPMS/
[root@localhost SRPMS]# ls
fping-3.4-1.src.rpm
[root@localhost SRPMS]#
rebuild 시 생성되는 파일 경로는 다음과 같습니다.
/usr/src/redhat/RPMS/x86_64또는/usr/src/redhat/i386: binary rpm 패키지 생성/usr/src/redhat/SRPMS/: source rpm 패키지 생성
rpmbuild -bb fping.spec 명령을 사용하면 됩니다.
참고 안내
기본적으로 spec 파일과 소스코드는 /usr/src/redhat 내 관련 디렉터리에 자동 분리됩니다.
추가적으로 권한 설정, 종속성 패키지 등이 설치되어 있어야 정상적으로 빌드가 가능합니다.