Disk cloning

Disk cloning is the process of making an image of a partition or of an entire hard drive. This can be useful for copying the drive to other computers or for backup and recovery purposes.

Tip: Over time file systems get new features and the mkfs utilities change their defaults, but not all new features can be enabled without reformatting. So, when moving data to a new drive, instead of cloning the block devices or file systems, consider creating a new file system and only copy the files (and their attributes, ACLs, extended attributes, etc.) with e.g. rsync.

Block-level cloning

Using dd

See dd#Disk cloning and restore and Core utilities#dd alternatives.

Using ddrescue

If possible, data recovery from disks should be performed using their native interface: SATA or, for older drives, IDE. Results may vary while using USB adapters.

GNU ddrescue is a data recovery tool capable of ignoring read errors. ddrescue is not related to dd in any way except that both can be used for copying data from one device to another. The key difference is that ddrescue uses a sophisticated algorithm to copy data from failing drives causing them as little additional damage as possible. See the ddrescue manual for details.

To clone a faulty or dying drive, run ddrescue twice. For the first round, copy every block without read error and map the errors to rescue.map.

# ddrescue --force -n /dev/sdX /dev/sdY rescue.map

where X is the partition letter of the source and Y of the target block device.

For the second round, copy only the bad blocks and try 3 times to read from the source before giving up.

# ddrescue --force -d -r3 -n /dev/sdX /dev/sdY rescue.map

In some circumstances the disk controller or a USB adapter may lock, while attempting to read a particular sector. The option may be used to instruct ddrescue to start reading after that position.

Now you can check the file system for corruption and mount the new drive.

# fsck -f /dev/sdY

File system cloning

Using e2image

e2image is a tool included in for debugging purposes. It can be used to copy ext2, ext3, and ext4 partitions efficiently by only copying the used blocks. Note that this only works for ext2, ext3, and ext4 filesystems, and the unused blocks are not copied so this may not be a useful tool if one is hoping to recover deleted files.

To clone a partition from physical disk , partition 1, to physical disk , partition 1 with e2image, run

# e2image -ra -p /dev/sda1 /dev/sdb1
Tip: GParted uses e2image to efficiently copy ext2/3/4 partitions.

Versatile cloning solutions

These applications allow easy backup of entire filesystems and recovery in case of failure, usually in the form of a Live CD or USB drive. They contain complete system images from one or more specific points in time and are frequently used to record known good configurations. See Wikipedia:Comparison of disk cloning software for their comparison.

See also Synchronization and backup programs for other applications that can take full system snapshots, among other functionality.

  • System Tar & Restore Backup and Restore your system using tar or Transfer it with rsync
    • GUI and CLI interfaces
    • Creates .tar.gz, .tar.bz2, .tar.xz or .tar archives
    • Supports openssl / gpg encryption
    • Uses rsync to transfer a running system
    • Supports Grub2, Syslinux, EFISTUB/efibootmgr and Systemd/bootctl
https://github.com/tritonas00/system-tar-and-restore || system-tar-and-restoreAUR
gollark: Clearly someone doesn't know about the tetrational rotation theorem.
gollark: I favour arachno-capitalism.
gollark: As planned.
gollark: > having Nitro
gollark: Since it would be silly to add one character per possible family composition.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.