Caution: It is highly advised you run
ddrescue from a live USB or similar, and not on the damaged hard drive. Using the damaged hard drive any more than absolutely necessary may cause more (and worse!) data loss.
First off, you're going to enable the
sudo add-apt-repository universe
On Ubuntu 18.04 (and later, assumed for this guide), this will automatically update your package repositories as well.
Once you have
universe enabled, we can go ahead and install
sudo apt install gddrescue
Next, find your partitions/disk data. This is usually achievable through the
blkid commands. On my (example) system, we will be cloning
/dev/sdb. Once we have our names, we can just run ddrescue:
sudo ddrescue -d -r3 /dev/sda /dev/sdb /path/to/rescue.log
We're going to use the
-d option to read the disk directly, and the
-r3 to retry a bad block three times before moving on.
rescue.log is an (optional) log file used to restart a recovery if it is interrupted. You may store it in-memory, but it is highly recommended to store it to an external (third) USB drive.
Let this run, and hopefully your drive will be restored.
For further options, read the manpage for
ddrescue after installing it. You can access it with the following command:
A full disk
ddrescue is doable, but is somewhat frowned upon due to putting unnecessary stress on the disk. If at all possible, try to only recover the minimum amount of data necessary - a single partition, for example. In order to do this, you'll need to create a partition on your target drive first.