Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    how to exract rpm files and rebuild it again?

    I want to extract one .rpm file and want to add one .txt file and then I want to rebuld it .

    will it work or not .
    I got some thing like

    rpm2cpio command but is that the only way to extract .Kindly tell me is there any other efficient way to do this and also tell me how to rebuld this again into .rpm file.


  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Get the spec file or the source rpm of that package.
    In any case: edit the spec file and rebuild the rpm with rpmbuild.
    You must always face the curtain with a bow.

  3. #3
    Thanks ..
    I got some files after the rpm2cpio commad and then i have changed some document and then made a tar ball of all that file now I want to make that tar to a rpm.

    suppose I have xyz.rpm then

    1.rpm2cpio xyz.rpm | cpio -mvid (this will give some files)

    then I changed some files and do as follows
    2.tar -cfv xxx.tar <foldername>/ (foldername= where all files are there from the xyz.rpm)

    then I have tried with rpmbuild option but it is not working
    3.rpmbuild -tb xxx.tar

    I can't able to do this ,can any one tell me how to to do this.


  4. $spacer_open
  5. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    No, unpacking the rpm is the wrong way.

    You either need the spec file and all sources
    or the source rpm.

    Then you edit the spec file to include your textfile
    Then you build a new rpm with the rpmbuild command and your specfile.
    You must always face the curtain with a bow.

  6. #5
    Like irithori says, you are going about it wrong. you need to understand how an RPM file works. It is true that an RPM is just basically a cpio archive of files, but it comes with pre and post install scripts and various macros that affect how it gets installed.

    To wit, you need to build the RPM using within these constraints. Here's what you need to do, in a nutshell.

    1. create an RPM build environment for your regular user
    mkdir ~/rpms
    cd ~/rpms
    2. create an rpm config file:
    cat -> ~/.rpmmacros
    # adds Packager info to RPM
    %packager Your Name
    # set this to your distro version (.el5 = RHEL 5, .fc16 = Fedora 16, etc.)
    %dist .el5
    # set toplevel for all rpm subdirs (e.g., system _topdir is /usr/src/redhat)
    %_topdir %(echo $HOME/rpms)
    # gpg username (uncomment this to be able to sign packages)
    #%_gpg_name "user@localhost"
    # buildroot dir
    %buildroot /var/tmp/%{name}-%{version}-%{release}
    3. install the Source RPM for the package you wish to modify, e.g.:
    rpm -ivh cool-package-1.0.src.rpm
    this will install at least two files:
    4. modify the source package, e.g.:
    cd ~/rpms/SOURCES
    tar zxf cool-package-1.0.tar.gz
    If you are changing the source tarball, it is a good idea to up the version:
    mv cool-package-1.0 cool-package-1.1
    now carry on with modifying the source, then tar it back up (reflecting the new version, if changed):

    tar zcf cool-package-1.1.tar.gz
    5. modify the SPEC file. Use an editor that has syntax highlighting, it is a big help. I use vim. if you changed the version, change it in the spec file (the Version: tag). if you added a file, make sure it gets installed in the %install section, and make sure it is listed in the %files section. also, you should add a line to the %changelog section, noting your changes (reflect the version change there, too, if necessary).

    6. rebuild the rpm:
    rpmbuild -bb ~/rpms/SPECS/cool-package.spec
    The RPM will get written to the ~/rpms/RPMS directory (under the relevant arch subdir)

    btw, don't build as rpms as root, it is a great way to fubar your system.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts