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
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
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.