Linux-tips

Any donation is very welcome
Fork me on GitHub

I. Linux tips

8. Playing with Debian packages

First, let's take a look to a Debian package:

Inside .deb files

So, I think you guessed it but .deb file are Debian package files. Now let's see a bit how they work (let's take libm.deb for this example):

> dpkg-deb -x libm.deb libm

This line will extract data from libm.deb into a libm folder. Now we need to extract Debian content as well:

> dpkg-deb -e libm.deb libm/DEBIAN

No we have access to all the content. First thing to know, folders (except DEBIAN) will be copy as-is in the system (from "/"). So if you have ./libm/usr/lib/libm.so, it means the libm.so file will be copied into /usr/lib/libm.so. Nothing complicated in here.

The interesting part is in ./libm/DEBIAN. You should have at least a checksums and a control files. The first one is just a file containing checksums of files provided by this package (but this isn't mandatory) whereas control contains all information the package manager might need to know about this package. I let you take a look to this manual for more information about it.

Merging packages or add more files into it

The interesting thing in here is that you can totally merge different packages into one by just extracting other packages folders (except the DEBIAN one!) into the first one. Don't forget to add DEBIAN/control useful information like dependencies or conflicts!

The same goes if you want to add other libraries that aren't in the package. Just copy-paste them in the correct folder (the one into you want them to be installed) and that's all.

Creating a debian package from original package and a patch

It's common to have an "original" package file and a Debian patch provided alongside. It's not very complicated to build it in order to then install it but it's always good to know! So let's start with libm_orig.tar.gz and libm_debian.tar.gz.

First, let's extract libm_orig.tar.gz:

> tar xzf libm_orig.tar.gz

Now let's extract libm_debian.tar.gz into it:

> cd libm_orig
> tar xzf libm_debian.tar.gz

Now you just need to build the package:

> dpkg-buildpackage -us -uc

The us and uc options are for generating non-signed package. Read the manual if you want to build a signed package. :p