Disk Cloning - How to create a clone of a hard drive

Disk Cloning

How to create a clone of a hard drive

Ralph Meier
by Ralph Meier
on December 07, 2023
time to read: 12 minutes

Keypoints

How to clone a hard disk

  • With disk cloning, quickly and easily back up the system hard disk before a repair and then restore it back
  • Easy creation of a bootable USB stick with Linux or the Rufus application
  • With good preparation in the area of storage media and permissions, disk cloning is easy to do
  • Upgrade easily to a larger system hard disk with Clonezilla or disk dump

Some time ago, we had to send in a laptop for repair due to a hardware defect. But before sending it in, a copy of the internal system memory should be made and after the memory of the device should be completely erased. The clone of the system hard disk was then to be played onto the repaired unit in order to save the configuration effort that would otherwise have been required again. For this case, so-called disk cloning came into play. Besides this case, there are other reasons to clone one’s hard disk, such as an upgrade to another, possibly larger and faster storage medium for the operating system. Or the creation of another computer with an identical system memory. There are a variety of programmes and ways to perform disk cloning, in this article we focus on the Linux distribution Clonezilla and the utility disk dump (dd).

Preconditions

In order to carry out a smooth disk cloning, the following requirements must be met:

Hardware

In order to carry out a clone with Clonezilla or disk dump, you first need a USB stick on which a bootable Linux distribution can be set up. Then, depending on the desired source and destination, two or three storage media are needed. If either the source storage medium, the target storage medium or both are removable, it only needs the source and target storage medium. However, in the case of two laptops with built-in, e.g. soldered, storage media, an additional storage medium is required for the transfer. The target storage medium must be at least the same size as the source storage medium. In the case of a transfer storage medium, it must be at least the same size as the source storage medium. It is simplest if the target storage medium is at least the same size as the transfer storage medium, but it also works if the transfer storage medium is larger than the target storage medium, as long as the target storage medium is the same size or larger than the source storage medium.

Permissions

If the source storage medium is encrypted, it requires administrator access on the device in which the source storage medium is installed in order to decrypt it.

If the source or target storage media is built-in, BIOS access to boot a Linux distribution should be available on these devices. If both storage media are removable, another computer with BIOS access can be used. Depending on BIOS hardening, it may not need full BIOS access if it is possible to boot from external USB sticks.

Preparation

To ensure that no time is lost during the cloning process, we recommend making the following preparations:

Deactivate Hardening Configurations

In the case of active hard disk encryption, such as Bitlocker or FileVault, this should be deactivated first. Then the operating system should be shut down completely so that the UEFI can be opened at the next start. In the UEFI or BIOS, it should be checked whether the USB interface is active, access to the boot sequence or the boot menu is possible and Secure Boot should be temporarily deactivated.

Create a bootable USB stick

There are many different ways to create a bootable USB stick. Here it is important that the bootable USB stick has UEFI compatibility, otherwise it will not work with current UEFI BIOS, as the Compatibility Support Module (CSM) has been deactivated in the meantime. Read more in the article The BIOS – History and Hardening Options .

We recommend using a live installation of the desired Linux distribution so that no new operating system has to be installed, but the Linux distribution runs exclusively in the RAM and is gone again after shutdown.

On Linux

With Debian version 12.2.0, creating a bootable USB stick is easy. First download the desired ISO file from the Debian website, for example a live installation of version 12.2.0. The ISO file can then be copied directly to the USB stick.

cp debian.iso /dev/sdc

This copying process may require root rights. Afterwards, a sync should be carried out, which forces the writing of any data in temporary storage to persistent storage and thus ensures that the ISO file is completely stored on the USB stick.

On Windows

On Windows, the programme Rufus can be used to create bootable USB sticks with all kinds of operating systems. To ensure UEFI compatibility, select GPT for the partition scheme and UEFI (without CSM) for the target system. The live image is best obtained from the Debian website, as described above.

Rufus configuration for a bootable USB stick with UEFI compatibility

Cloning Process with Clonezilla

The ISO file for creating a bootable USB stick can be obtained from the Clonezilla website.

When the bootable USB stick is ready, the cloning process can be started:

  1. Start the computer and enter the boot menu
  2. Select and start the USB stick with Clonezilla in the boot menu
  3. Select and confirm Clonezilla live (VGA 800×600)
  4. Set language and keyboard
  5. Choose Start_Clonezilla, otherwise you could go directly to the command line here
  6. Select device-device to be able to clone from one storage medium to another
  7. Select expert mode to be able to define some settings later
  8. Select disk_to_local_disk
  9. Set source storage medium
  10. Set target storage medium
  11. Specify advanced configuration, this selection is only possible in expert mode

Advanced configuration of Clonezilla

The parameter -r should be used if the target storage medium is larger than the source storage medium in order to be able to use the entire storage space of the target storage medium without manual partitioning.

The parameter -icds should be used if the target storage medium is smaller than the transfer storage medium.

  1. Select whether the source file system should be checked and repaired. If this is not absolutely necessary, it can be omitted
  2. Determine how the partition table is built on the target storage medium. By default, the partition table is taken from the source storage medium
  3. Select what action happens after the cloning process, shut down, restart or ask the user
  4. Then confirm twice that you agree to the complete overwriting of the target storage medium

If the target storage medium is too small, the cloning process is aborted. Otherwise, the cloning process is carried out as configured.

Cloning Process with disk dump (dd)

The disk dump utility is available on all Linux distributions, in this article a live installation of Debian is used as an example. Debian live installation images are available on the Debian website in different variations.

With a bootable USB stick with a Debian Live installation, the cloning process can be started:

  1. Start the computer and enter the boot menu
  2. Select the USB stick with Debian Live in the boot menu and start it
  3. Start Debian Live
  4. Set language and keyboard layout
  5. Configure location services
  6. Open the terminal
  7. Use the command lsblk (list block devices) to display the internal and connected storage media

lsblk on the command line

More detailed information can be viewed with the commands blkid and fdisk -l, but root rights are required for the executions.

  1. Subsequently, the source and target storage media are specified and the following command is executed
sudo dd if=/dev/nvme0n1 of=/dev/sda bs=64M conv=sync,noerror status=progress
Parameter Description
if Source, in our case the path to the source storage medium
of Target, in our case the path to the target storage medium
bs Block size, this can be used to influence the write speed, among other things, the optimal block size is very hardware-dependent. 64M = 64 megabytes is a good starting value.
conv Conversion, the values sync,noerror cause this area to be filled with NUL if errors occur during reading.
status Amount of information about copy/clone process, the value progress periodically updates the last line with the current copy status

When using a transfer storage medium, the second step is to copy from the transfer storage medium to the target storage medium, specifying the transfer storage medium as if, as it is considered the source storage medium in this step.

disk dump writes bit by bit, so the existing partition table as it exists on the source storage medium is taken over.

When disk cloning isn’t suitable

When changing to a more modern device or generally to a device with different components, disk cloning should not be carried out. This is because the drivers will not fit exactly and in extreme cases the device will not function properly or only to a limited extent. Another reason for reinstalling the operating system on the new device rather than cloning is if there are a lot of old burdens on the source storage medium. These would simply be carried over with a cloning process and could continue to restrict the speed or reliability of the computer.

Conclusion

After a successful cloning process, all previously used hardening settings including hard disk encryption should be reactivated. Disk cloning makes sense in some cases and is the easiest way to back up data and at the same time delete it on the device to be repaired. After the repair, the clone can be restored to the computer and you can continue with the identical status. With a little preparation and the right choice of storage media, especially in terms of disk size, a cloning process is relatively easy to carry out.

About the Author

Ralph Meier

Ralph Meier completed an apprenticeship as an application developer, with a focus on web development with Java, at a major Swiss bank and then completed a Bachelor of Science in Computer Science UAS Zurich at the ZHAW School of Engineering. His primary task is doing security-related analysis of web applications and services. (ORCID 0000-0002-3997-8482)

Links

You need support in such a project?

Our experts will get in contact with you!

×
Burp Bambdas & BChecks

Burp Bambdas & BChecks

Ralph Meier

The BIOS

The BIOS

Ralph Meier

Flipper Zero

Flipper Zero

Ralph Meier

Flipper Zero

Flipper Zero

Ralph Meier

You want more?

Further articles available here

You need support in such a project?

Our experts will get in contact with you!

You want more?

Further articles available here