SUSE Conversations


LJDT: Installed RPM Size



By: ab

August 21, 2009 2:20 pm

Reads:185

Comments:0

Rating:0

This entry is part 4 of 10 in the series LJDT - Linux Just Does That

Sometimes I find myself wondering how big an installed RPM’s files really are. Use a simple script to do all of the calculating of file sizes, plus see how to recreate the RPM from the system where the package is installed in the latest addition to Linux Just Does That.

So first a refresher on the basics. Once a package is installed getting a list of files that it put on the filesystem (at least that were stored within the RPM) can be done with a simple ‘rpm’ command:

rpm -ql MozillaFirefox

/usr/bin/firefox                                         
/usr/lib64/firefox                                       
/usr/lib64/firefox/application.ini                       
/usr/lib64/firefox/blocklist.xml                         
/usr/lib64/firefox/chrome                                
/usr/lib64/firefox/chrome/browser.jar                    
/usr/lib64/firefox/chrome/browser.manifest
*snip*

And away it goes listing files forever, which is a nice start. For the curious you can add a ‘p’ on the end of ‘-ql’ and then point to an RPM package file and get the listing of files from within it before actually installing it. With this fine listing of files finding out the file size shouldn’t be too hard, so let’s tackle that next. For this I created a small script that loops through the results and calculates their size:

i=0;
for j in `rpm -ql MozillaFirefox | xargs ls -ld | grep -v 'drwx' | grep -v 'lrwx' | awk '{print $5}'`; do
  i=`echo $i+$j | bc -l`;
done;
echo $i;
unset i j

This can all be combined into one command (or better ways may be found) but basically this gets the file listing, gets output that is not recursive in nature from ls (which happens to show the sizes of the data as well as the object type (directory, file, symlink, etc.)), and then loops through all of those file sizes adding them up. This is a bit of a hack and could need manipulation per implementation of ‘ls’ (some of them, like SUSE’s, have default options applied while others may not). A better way of getting the size, for instance, would likely be to use `stat –format=%s` and then only run that against files (not directories).

So there is a more-elegant solution in my opinion, and it also lets you recreate the package from which your software was installed even if you have since deleted it. RPM itself provides the ability to recreate packages with the (you’ll never guess) –repackage option. How does this work? Simply:

rpm -e --repackage MozillaFirefox

One thing to note is that the –repackage option is used while erasing packages. This happens so that RPMs can be rolled back to a previous version after an update does not fix a problem or causes new problems. As a result if you do not want to erase the package while generating an RPM from it be sure to keep this in mind or reinstall the RPM after repackaging it (which would leave the old RPM file behind as always).

This repackage option does include the scripts for install/removal that the original RPM had as those are stored in the RPM database and as a result the resulting RPM should be very close (if not identical) to what you had before. The completed size of the RPM should be approximately the same as the size of the files on disk plus the extra package information and scripts as stored by the RPM format.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
Series Navigation<< LJDT: Taking Advantage of ScreenLJDT: Workspaces >>

Tags:
Categories: SUSE Linux Enterprise Desktop, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

Comment

RSS