dpkg-repack
Rebuild installed packages into Debian archives
SYNOPSIS
dpkg-repack [OPTIONS] <package-name> [...<package-name>]
PARAMETERS
-d, --deb-args <arguments>
Pass additional arguments directly to the dpkg-deb command.
-a, --arch <architecture>
Override the detected architecture for the package. Useful for cross-architecture scenarios.
-m, --maintainer <email>
Override the maintainer email address in the package's control file.
-r, --root <directory>
Specify an alternative root directory from which to extract files (e.g., for a chroot environment).
-s, --section <section>
Override the package's section (e.g., "utils", "net") in the control file.
-p, --priority <priority>
Override the package's priority (e.g., "optional", "extra") in the control file.
--md5sums
Force the generation of md5sums in the package's control file, even if dpkg-deb might skip it.
--no-md5sums
Prevent the generation of md5sums. This is often the default behavior for newer dpkg-deb versions.
--generate-control
Only generate the control file for the package; do not create the full .deb archive. Useful for debugging.
--tag <tag-string>
Add a custom tag string to the generated .deb filename (e.g., package_tag.deb).
--confdir <directory>
Specify an alternative directory for dpkg-repack's configuration files.
--excludes <patterns>
A comma-separated list of shell patterns for files or directories to exclude from the generated package.
--keep-extras
Do not delete temporary extra files created in the control archive after package creation.
--extra-dist-files <files>
A comma-separated list of additional files to include in the debian/dist directory within the package.
--no-conf-files
Do not include conffiles (configuration files) in the generated package.
--tmpdir <directory>
Specify an alternative temporary directory for dpkg-repack's operations.
--list-installed-packages
List all installed packages on the system and exit.
--version
Display version information for dpkg-repack.
--help
Display a help message and exit.
DESCRIPTION
dpkg-repack is a powerful utility that allows you to recreate a Debian package (a .deb file) from a package that is already installed on your system. This command is invaluable in scenarios where the original .deb file has been lost, but you need to reinstall the package, transfer it to another machine, or simply create a backup.
It works by inspecting the files currently installed on the filesystem that belong to the specified package, along with the package's metadata stored in dpkg's status database. It then bundles these components into a new .deb archive, closely resembling the original package. While it recreates the package, it's important to note that it packages the *currently installed state*, including any modifications made to non-conffiles. It does not re-resolve dependencies, but rather includes the dependency information as it was recorded for the installed package.
The generated .deb file typically includes the package's binaries, libraries, documentation, and configuration files (conffiles), making it a self-contained unit for reinstallation.
CAVEATS
dpkg-repack recreates a package based on its *current* installed state. This means if any files belonging to the package have been modified (e.g., config files not properly marked as conffiles, or manual changes to binaries), those modifications will be included in the new .deb.
It does not attempt to resolve or verify dependencies during repackaging; it simply carries over the dependency information from the original package's control file.
While generally robust, it may encounter issues with very complex packages that rely heavily on pre/post-installation scripts, specific kernel modules, or intricate hooks that are not easily reproducible through file extraction alone. It relies on a healthy dpkg status database for accurate package information.
USAGE EXAMPLES
To repackage a single installed package, run: sudo dpkg-repack <package-name>
For example: sudo dpkg-repack apache2
To repackage multiple packages: sudo dpkg-repack apt firefox-esr
The generated .deb files will typically be placed in the current working directory from where the command was executed.
OUTPUT FILE NAMING
The recreated .deb file will follow the standard Debian naming convention: packagename_version_architecture.deb. For instance, repackaging 'apache2' might result in a file named apache2_2.4.52-1ubuntu4.7_amd64.deb.
HISTORY
dpkg-repack has been a long-standing utility in the Debian/Ubuntu ecosystem, designed to address the practical need for creating distributable .deb archives from installed software. It's written in Perl and maintained as part of the Debian project's toolchain. Its development has focused on maintaining compatibility with evolving dpkg standards and improving its robustness in handling various package types and system configurations. Its core functionality of snapshotting an installed package into a portable .deb file has remained consistent since its inception.