Cloning a Debian system with apt-clone

Debian Clone

© Lead Image © Csaba Deli,

© Lead Image © Csaba Deli,

Article from Issue 268/2023

In the right circumstances, apt-clone can be a simple option for cloning your Debian system.

A new system, container, or chroot jail can be created in a few minutes. However, configuring any of them can take hours, especially if you want them to resemble existing systems. Numerous cloning applications exist, notably dd, Partimage, or Clonezilla, but on Debian-derivatives, such as Debian Ubuntu or Linux Mint, one of the simplest tools is a small script called apt-clone [1]. Apt-clone is vaguely reminiscent of Clonezilla, but has the advantage of simplicity because it uses standard command-line tools and basic commands. Apt-clone can also be used as a convenient backup.

Apt-clone belongs to the cluster of small scripts that center on apt-get and apt and their management or ease of use. New members of these scripts are always appearing and occasionally disappearing, so the Debian stable repository contains 54 of these scripts and Debian unstable repository 64 – a figure that might very well increase before the next official release. Apt-clone itself is over a decade old, which is time enough for its use to spread quietly. Most Debian derivatives include apt-clone in its repositories, but you can also download the source code from GitHub. As I write, though, the latest couple of Ubuntu releases contain a version of apt-clone that appears to have version incompatibilities. In general, though, do not be concerned if you notice that the most recent contributions are a couple of years old. The fact is, git clone is so simple, and mature enough, that the code rarely needs to be updated.

Creating the Cloning File

Reporting on apt-clone tends to focus on the basics. Even online man pages tend to be incomplete. For this reason, rely only on the man page installed with the script, or the summary available with the --help (-h) option.

Before using apt-clone, update your system with apt upgrade so that you are not dealing with different Debian releases and the original system is as bug-free as possible. Then run

apt-clone clone FILE

Unless you specify --source DIRECTORY, the output will go to the present working directory. If you have any third party .deb packages, add --with-dpkg-repack at the end of the command so that apt-clone will attempt to include them in the backup directory. However, be aware that the attempt may not always be successful, because an installable .deb package does not automatically have the format and standard required by the Debian distribution. Such packages work perfectly fine in everyday use, but may not be picked up by apt-clone (Figure 1).

Figure 1: Creating the archive file: Note the number of third-party packages.

Whatever the case, in a few minutes, apt-clone will create a TAR-zipped file. If you are trying to include third-party packages, it will probably take much longer because each third-party package must be analyzed separately. You can read general information about the newly created file using the command:

<C>apt-clone info FILE<C>

In Figure 2, across seven different desktops, 2,977 packages are installed, but only 2,619 are official Debian packages, which suggests that a perfect clone could be unlikely, although the basic functionality should clone successfully. A different view of the archive file can be had by viewing it in an archive application such as Ark (Figure 3). As you might expect, package sources and apt settings are major categories for the archive, as well as apt-clone's logfile. Preferences include configuration settings from directories such as .config or .local. In theory, you might be able to unarchive the file and attempt to edit, but to do so is likely to take more effort than is worthwhile. Still, it is never wasted time to know exactly what you are doing instead of blindly following instructions.

Figure 2: An overview of an archive file using apt-clone info.
Figure 3: An overview of the archive file's content.

Because the archived file contains system-sensitive information, you should encrypt unless you plan to delete it immediately after cloning. The quickest way to do so with reasonable security is to use GPG and keep the file encrypted when you are not actually using it.

How to Clone

Once you have the archive file, install the target system with the same Debian release as the source system. Using another Debian release may work, but it increases the chances of problems – problems that may cost more time than apt-clone is likely to save. Transfer the archive file to the root directory of the target system, decrypt it if necessary, and run as root:

apt-clone restore FILE

The process is similar to that of installing packages normally and may take 20 minutes or more on recent hardware, depending on the number of packages involved. It will take even longer if you choose to use restore-new distro instead of restore, because you will be attempting to upgrade packages at the same time. Probably less can go wrong if you upgrade before restoring.

When the process finishes, the cloning will complete without the need to reboot, exactly as happens when a new package is installed. Similarly, because the source files belong to root and are copied as root, you should not have problems with permissions. If you do have any problems, using apt-clone diff to compare with the source machine's file may help with problem-solving.


The main drawback to apt-clone is that is designed for use with official repositories. If the system you are cloning includes packages installed with .deb packages from third-party sources, apt-clone will try to handled them, but sometimes without success. That means that if you have installed, for example, the latest version of LibreOffice from The Document Foundation, you will have to back up the configuration files separately. Similarly, transferring the configuration files to a newer release of the operating system may also have limited success. Probably, the most useful time to use apt-clone is when you are installing a lab with identical workstations or a new home computer that you want to be identical to your old one. When apt-clone meets your needs, it is an elegant little script, but it is never going to be a complete solution for every possible circumstance.

The Author

Bruce Byfield is a computer journalist and a freelance writer and editor specializing in free and open source software. In addition to his writing projects, he also teaches live and e-learning courses. In his spare time, Bruce writes about Northwest Coast art ( He is also cofounder of Prentice Pieces, a blog about writing and fantasy at

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More