2024年8月29日 星期四

How to repair and clone disk with ddrescue

 ddrescue is a tool that can be used to repair and clone disks on a Linux system. This includes hard drives, partitions, DVD discs, flash drives, or really any storage device. It performs data recovery by copying data as blocks.


If ddrescue encounters errors from the data it’s trying to copy, it can discard them and keep only the good data. This makes it an ideal tool when trying to recover data from a corrupted disk. In this tutorial, you will learn how to install ddrescue and use it to clone a full disk or partition, and write that data to an empty storage space.

To install ddrescue on UbuntuDebian, and Linux Mint:

$ sudo apt install gddrescue

Clone a partition to image file or other disk

In the section, we will use ddrescue to clone a partition or full disk (the process is the same) to an image file. That file can that be written to another disk or partition afterwards. We will also show the process to clone a partition directly to another disk, bypassing the image file creation and instead creating a direct clone onto new hardware.

  1. First, open a command line terminal and identify the device path to the hard drive or partition that you would line to clone. For this, you can use a tool like lsblkfdisk, etc.
    $ lsblk
    
    Here we find the device path /dev/sdb1 which is the partition we want to clone
    Here we find the device path /dev/sdb1 which is the partition we want to clone
  2. Note that the -d option will force ddrescue to ignore the kernel’s cache and instead access the disk directly.

    ddrescue process of cloning the partition to an image file
    ddrescue process of cloning the partition to an image file
  3. Note that if you are trying to recover data from a corrupted disk, you may want to append the -r option after the first try above. This will instruct ddrescue to retry bad sectors in an effort to recover as much data as possible. You can specify the number of retries after the option. In this example, we will use 3 retries.
    $ sudo ddrescue -d -r3 /dev/sdX backup.img backup.logfile
    
  4. Next, we will copy the new image file to a different disk or partition. We can use an ordinary dd command for this.
    $ sudo dd if=backup.img of=/dev/sdX
    

    Alternatively, the ddrescue command can be used.

    $ sudo ddrescue -f backup.img /dev/sdX clone.logfile
    

    The -f option indicates that we are sending our output to a block device rather than a file.

  5. If you want to clone a disk or partition directly to another, thereby bypassing any image file, you can do so with the following syntax. In this example, we are cloning partition /dev/sdX1 to /dev/sdX2.
    $ sudo ddrescue -d -f /dev/sdX1 /dev/sdX2 clone.logfile
    
  6. Next, we will use the following command syntax to copy the partition to an image file. We are using /dev/sdX in the example below, but you would just need to substitute your own partition or device in place of it. The contents will be written to a file called backup.img.
  7. $ sudo ddrescue -d /dev/sdX backup.img backup.logfile
    


    After completing the steps above, you can access the cloned storage and will hopefully see all of your files there, assuming that ddrescue was successful in recovering them.

沒有留言:

張貼留言

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...