by June 30, 2004 0 comments



A lot of software for Linux is available in the .rpm format, because they’re much easier to install than tar balls or source files. But there are also cases where the RPM is not available and installing the software, therefore, becomes a daunting task. To make life easier, you can create your own RPM files from the source files using the rpm command. This command also has other powerful functions, which are not so well known. We’ll talk about some of them in this article.

Creating your own RPMs
Let’s start by using the rpm command to create your own RPM files. If you have a source RPM for a particular Linux software, then you can convert it into an RPM that will support your machine’s architecture. For this, you’ll have to install the source RPM file for the software, which can be done as follows. 

#rpm —ivh filename.src.rpm

Direct
Hit!
Applies
to:
Linux Users
USP:
Create your own RPM files and roll back to older software versions using the rpm command
Links:
www.rpm.org, www.tldp.org/HOWTO/RPM-HOWTO

This will copy the source tar ball to /usr/src/redhat/SOURCES directory and will also create a .spec file that will look like filename.spec. This .spec file will be copied to the /usr/src/redhat/SPECS directory. Now, run the following command to create an RPM file.

#rpmbuild -ba /usr/src/redhat/SPECS/filename.spec

The final RPM file will be created in the /usr/src/redhat/RPMS directory. Similarly, as long as you have the .spec file for a source tar ball, you can easily create an RPM for it. You can also create your own .spec file in case you don’t find it anywhere. Understanding how to do that is not easy and beyond the scope of this article, so check out the link
http://rpm.org/RPM-HOWTO/ on how to do this. 

Version rollback
If you’ve upgraded to a new version of any package, let’s say test.1.1.rpm from test.1.0.rpm, and found problems or bugs in it, then the traditional way of rolling back to the older version is fairly cumbersome. First, you’ll have to remove the test.1.1.rpm file from the system, and then hunt for the older version (test.1.0) from a .rpm repository and finally download and reinstall it. In case your package is a dependency for any other package, then you won’t even be able to uninstall it. It’s more or less like being stuck with the new version. 

This is where RPM’s rollback feature comes handy. Rollback means that RPM will automatically recreate the .rpm files of the older package before removing them and installing the newer ones. In this case, when you roll back to the older version, it will automatically remove the newer one and install the older version from the repository, which it created. 

To use the rollback feature, you’ll have to use the rpm command with an additional switch ‘-repackage’ when installing a newer version of the software. So if you’re installing test.1.1.rpm, then the command would be as follows.

#rpm -Uvh —repackage test.1.1.rpm

This will install the newer version and save the older version (test.1.0.rpm) to the
/var/spool/repackage directory.

Whenever you want to rollback to the older version, just run the following command.

#rpm -Uvh –rollback ‘time’ 

Check the ‘Enable RPM rollbacks’ option to activate the transaction rollback feature in up2date

Here replace ‘time’ with the date or time of installation of the newer RPM. For instance, if you roll back to the older version three hours after installing the new one, you will issue the following command.

#rpm —Uvh —rollback ‘3 hours ago’

You can even configure RPM to automatically repackage all .rpm files that were upgraded by modifing the macros file in the /etc/rpm directory. Keep in mind, though, that this will occupy a lot of disk space as all the older versions of the packages will be saved on the local hard disk. To automate the repackaging process, open the file /etc/rpm/macros and make the following changes.

%_repackage_all_erasures 1

If the file doesn’t exist then create it using any text editor.

Graphical rollback
}
You can use up2date (a graphical front-end for automatic update installation in RedHat/Fedora) if you find it difficult to key in commands in the terminal window. To configure it , first run the following command.

#up2date-config

This will open a graphical dialogue box. Select the Retrieval/Installation tab and check the option ‘Enable RPM Rollbacks’. It will start repackaging the .rpm files. To roll back to a previous RPM version just run the following command.

#up2date -undo

Other powerful switches
Besides being able to create your own RPMs or rolling back to older software versions, there are lots of other useful functions that the rpm command is capable of. Try out some of the following. 

1. Suppose you have a file in your machine and you don’t know which package owns it, then run the following command.

rpm -qf filename

This will return the name of the package, which had installed this file.

2. In case of a directory, run the command like as below.

#rpm -qd directory_name

3. To get details about any given RPM you can run the command as below.

#rpm -pqi filename.rpm

This will return a brief description of the RPM.

4. To list down all the files and their paths, which an RPM will produce when installed, run the following command.

#rpm -pql filename.rpm

Anindya Roy

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

<