This site is now 100% read-only, and retired.

Re-creating Debian binary packages with dpkg-repack

Posted by Steve on Mon 19 Feb 2007 at 07:21

If you've installed a Debian package upon a machine, but lost the binary archive, then it is difficult to copy that package to another machine. Thankfully is a simple solution for recreating a Debian package from an installed system.

Several months ago I wrote a small patch to the crawl game which would allow nefarious users to cheat. Once I built the package and tested it I deleted the source code in a tidying mood.

Unfortunately once I'd deleted my patch, and the package source code, I acquired another computer suitable for playing games upon - but without the sources I didn't have the option of installing the Debian binary package upon this new machine.

Thankfully there is a simple solution to this problem: dpkg-repack.

dpkg-repack allows you to turn a package which you've installed back into a binary .deb file.

To use it you must first install it:

root@mine:~# apt-get install dpkg-repack
...
Selecting previously deselected package dpkg-repack.
(Reading database ... 97640 files and directories currently installed.)
Unpacking dpkg-repack (from .../dpkg-repack_1.25_all.deb) ...
Setting up dpkg-repack (1.25) ...

Once installed you can convert an installed Debian package back into a .deb file suitable for re-installation upon another host.

The simplest usage looks something like this:

mine:~# dpkg-repack coreutils
dpkg-deb: building package `coreutils' in `./coreutils_5.97-5.3_amd64.deb'.

As you can see there is not much output, but all being well the package will be built as expected. The simplest way to test this is to see what is inside the file:

mine:~# dpkg --contents coreutils_5.97-5.3_amd64.deb  
drwxr-xr-x root/root         0 2007-02-17 01:44 ./
drwxr-xr-x root/root         0 2007-02-17 01:44 ./bin/
-rwxr-xr-x root/root     69104 2007-01-30 20:38 ./bin/mv
-rwxr-xr-x root/root     15560 2007-01-30 20:38 ./bin/false
-rwxr-xr-x root/root     40128 2007-01-30 20:38 ./bin/touch
-rwxr-xr-x root/root     36072 2007-01-30 20:38 ./bin/chmod
-rwxr-xr-x root/root     21448 2007-01-30 20:38 ./bin/cat
..

If you don't wish to run the rebuild as root, and you have the fakeroot package installed you can do so as follows:

skx@mine:~$ fakeroot -u dpkg-repack bash
dpkg-deb: building package `bash' in `./bash_3.1dfsg-8_amd64.deb'.

Once again a check of the contents suggests it is all OK:

skx@mine:~$ dpkg --contents bash_3.1dfsg-8_amd64.deb
...
...
drwxr-xr-x root/root         0 2007-02-17 01:47 ./etc/skel/
...
...

One interesting thing about using dpkg-repack is that it will install any configuration files from /etc as they are upon the current host - rather than their pristine version(s). This is either a very useful thing, or not what you would expect.

For more details of using the package please see the man-page, accessible by running "man dpkg-repack".

 

 


Re: Re-creating Debian binary packages with dpkg-repack
Posted by glanz (70.53.xx.xx) on Mon 19 Feb 2007 at 19:50
[ View Weblogs ]
~(,~,`>

Very nice! Thanks a lot. This is something I missed and it will come in very handy...

I already used it for some wifi stuff and it saved me a lot of hand configuration on another machine.

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by Steve (62.30.xx.xx) on Mon 19 Feb 2007 at 21:39
[ View Weblogs ]

"~(,~,`>" ?! I have no idea what that is supposed to represent, though I assume it wasn't just random noise.

I'm glad you found the introduction useful; but if you're relying upon the configuration file handling do make sure you see the warning at the bottom of the manpage.

It might also be interesting to use the --generate option if you want to perform more changes upon the package prior to (re)building it.

Steve

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by glanz (70.53.xx.xx) on Tue 20 Feb 2007 at 01:14
[ View Weblogs ]
~(,~,`>

THAT, Steve, is a (mus musculus) mouse... (as in Xfce)... Anyway, to me it looks like a mouse.

I did read the warnings and I am aware of the "--generate" option. Right now I am experimenting with it to make sure I know all it's ins and outs before using it on other stuff. I had to redo host of course on related utilities.

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by Hercynium (64.69.xx.xx) on Mon 19 Feb 2007 at 21:51
Several times I have had a need for this type of utility - in the past I simply ended up rolling my own new debs, even for a simple one-file patch or custom config that I wanted to distribute to the rest of the servers. I just used it on a server with some custom patches to the mrtg script and it made a pkg I can now simply push out to the new ones I'm building instead of patching each one manually!

An hour of work reduced to 5 min!

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by rbochan (24.58.xx.xx) on Tue 20 Feb 2007 at 13:05
[ View Weblogs ]
One interesting thing about using dpkg-repack is that it will install any configuration files from /etc as they are upon the current host - rather than their pristine version(s).
Wow... that could really be handy for cloning installs!

...Rob

The American Dream isn't an SUV and a house in the suburbs; it's Don't Tread On Me.

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by Anonymous (80.69.xx.xx) on Tue 20 Feb 2007 at 17:10
I also like this tool very much.

It is just a small perl script without any dependencies to etch/sarge.

So you also can copy it to old woody-machines and repack there - very handy.
I used it a lot when migrating from woody to sarge.

regards
Thorsten

[ Parent ]

Re: Re-creating Debian binary packages with dpkg-repack
Posted by AustinDenyer (69.176.xx.xx) on Tue 27 Mar 2007 at 18:35
I use this all the time. I often use packages from Sid/Experimental, and as such run the risk of blowing up every time I do an 'apt-get upgrade'. So, I I run 'apt-get upgrade -s' first, then 'dpkg-repack <list-of-files-to-be-upgraded>' before I do the real upgrade. That way, if it breaks my system, recovery is only a 'dpkg -i *' away.

Trust me, it's saved my hide many times.

[ Parent ]