Disk cloning

Disk cloning is the process of duplicating all data on a digital storage drive, such as a hard disk or solid state drive, using hardware or software techniques. Unlike file copying, disk cloning also duplicates the filesystems, partitions, drive meta data and slack space on the drive. Common reasons for cloning a drive include; data backup and recovery; duplicating a computer's configuration for mass deployment and for preserving data for digital forensics purposes. Drive cloning can be used in conjunction with drive imaging where the cloned data is saved to one or more files on another drive rather than copied directly to another drive.

Background
Disk cloning occurs by copying the contents of a drive called the source drive. While called "disk cloning", any type of storage medium that connects to the computer via USB, NVMe or SATA can be cloned. A small amount of data is read and then held in the computer's memory. The data is then either written directly to another (destination) drive or to a disk image.

Typically, the destination drive is connected to a computer (Fig. 1). Once connected, a disk cloner is used to perform the clone itself. A hardware-based drive cloner can be used which does not require a computer. However, software cloners tend to allow for greater flexibility because they can exclude unwanted data from being duplicated reducing cloning time. For example, the filesystem and partitions can be resized by the software allowing data to be cloned to a drive equal to or greater than the total used space. Most hardware-based cloners typically require for the destination drive to be the same size as the source drive even if only a fraction of the space is used. Some hardware cloners can clone only the used space but tend to be much more expensive.

Deployment
A common use of disk cloning is for deployment. For example, a group of computers with similar hardware can be set up much quicker by cloning the configuration. In educational institutions, students are typically expected to experiment with computers to learn. Disk cloning can be used to help keep computers clean and configured correctly. Further, while installing the operating system is quick, installation of programs and ensuring a consistent configuration is time consuming. Thus, disk cloning seeks to mitigate this administrative challenge.

Digital forensics
One of the most common applications of disk cloning is for digital forensics purposes. This aims to ensure that data is preserved at the time it was acquired for later analysis. Techniques for cloning a disk for forensic purposes differ from cloning a drive for other purposes. Typically, the cloning process itself must not interfere with the data. Because software cannot be installed on the system, a hardware-based cloner is generally used to duplicate the data to another drive or image. Further, the hardware-based cloner also has write-blocking capabilities which intercepts write commands to prevent data being written to the drive.

Backup
Disk cloning can be used as a backup solution by creating a duplicate of data as it existed when the clone was started. The clone can be used to restore corrupted files such as corrupted databases. In modern software solutions, it is not uncommon for disk cloning techniques to be combined with disk imaging techniques to create a backup solution.

Drive upgrade
Upgrading to a larger or faster drive can be facilitated by cloning the old drive to the new drive once it is installed into the system. This reduces the need to having to manually reinstall applications, drivers and the operating system. The procedure can be used when migrating from mechanical hard disk drives to solid state drives. Modern cloning software tends to communicate with storage devices through a common interface, which means, that any storage device can be cloned and migrated. Sometimes, booting from the destination drive can fail and require adjustments in the computer's UEFI or BIOS to make the new clone bootable.

Technical challenges
There are several technical challenges that need to be considered when planning to clone a drive.

Drive in use
Often, cloning software runs within the operating system which is running off of one of the drives being cloned. As a result, any attempt to clone the contents of the drive, even to a file, would result in data corruption. Consequently, the drive cloner must ensure that the data on the source drive remains in a consistent state at the time of reading. Further, in the case, that the user desires to clone to the computer's system drive, this generally cannot be done while the operating system is running.

A common solution to cloning a drive that is in use, which is utilized by software such as CloneZilla, is to boot from a Linux-based operating system so the drive can be copied and/or overwritten. This approach is not suitable for servers that need to be running all the time and cannot be shutdown routinely to perform the backup (or cloning) operation. Further, the Linux-based operating system must provide appropriate drivers for the system's hardware. Drivers are also required for the source and destination drives and for any attached storage involved in facilitating the cloning operation such as USB, tape device and networking drivers.

Some server-based operating system incorporate mechanisms to allow the drive to be safely backed up while the system is running to overcome these challenges. For example, Windows Server 2003 (and later) includes volume shadow service (VSS). VSS takes a snapshot of the drive so that any changes are not written to the snapshot. The snapshot creates a virtual drive called a shadow volume that is backed up (or cloned) by the software.

Slow
Disk cloning can be time consuming, especially, for large disks because a true clone needs to copy all the data on the disk even if most data resides in unallocated drive space. Software solutions can determine the space in use and only copy the used data reducing the time needed to clone the drive. Some drive cloners make use of multithreading to further speed up the cloning operation.