Cloning a Debian system with apt-clone
Debian Clone
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).
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.
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.
Limitations
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.
Infos
- apt-clone: https://github.com/mvo5/apt-clone
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.