Amazon.co.uk Widgets

Log in

X
Ubuntu Circle of friends

GNU ddrescue for hard disk imaging or recovery on Ubuntu 24.04 LTS

GNU ddrescue (ddrescue) is a proven data recovery tool which you can trust. However, it is also quite a complicated command line tool. If only there was a way to make it more straightforward to use.

 

Contents

GNU ddrescue is a data recovery tool. It copies data from one file or block device (hard disc, cdrom, etc) to another, trying to rescue the good parts first in case of read errors.

ddrescue is an essential tool for data recovery originally released in 2004 and consistently updatedover time. As is often the case your Linux distribution might be a little behind the upstream release. Ubuntu 24.04 LTS has release 1.27 which is only a little behind the current release, but for LTS users I would recommend sticking with the release provided with the LTS distribution unless you absolutely know you need a fix made in the current release.

Using ddrescue safely

With any tool capable of erasing data, there is the opportunity to make a mistake that results in the source data being damaged. You should allow the tools you run to finish, avoid running them on mounted partitions and never try to repair data on suspected damaged drives. In this case unmount the drive if you mounted it and try to recover an image of all you can onto a new good drive, ideally of the same capacity and form factor if it is destined to be a replacement for a broken computer.

Allow tools to finish!

Patience is a virtue. Some tools can take an extraordinarily long time to run. Let them!

Don't run tools on mounted partitions

Mounted partitions make a disk available to use. Unmounted disks are safe to run low level tools on.

Don't try to repair damaged drives

Make as good a copy of a damaged drive and then try to repair the copy. Damaged drives should be retired.

You should take care to remember that any data on a chosen destination will be replaced. This is why it can be helpful to have the DDRescue-GUI and optionally, GParted, to provide a better visual check before you might destroy the existing data on a destination drive!

From the GNU ddrescue Manual, all emphasis mine!

  • GNU ddrescue is like any other power tool. You need to understand what it does, and you need to understand some things about the machines it does those things to, in order to use it safely.
  • Never try to rescue a r/w mounted partition. The resulting copy may be useless. It is best that the device or partition to be rescued is not mounted at all, not even read-only.
  • Never try to repair a file system on a drive with I/O errors; you will probably lose even more data.
  • If you use a device or a partition as destination, any data stored there will be overwritten.
  • Some systems may change device names on reboot (e.g. udev enabled systems). If you reboot, check the device names before restarting ddrescue.
  • If you interrupt the rescue and then reboot, any partially copied partitions should be hidden before allowing them to be touched by any operating system that tries to mount and "fix" the partitions it sees.

An example of DDrescue in action

I needed to image a Windows hard drive for a friend, before inspecting it to confirm or deny a ransomware attack. This necessitated removing the drive from the laptop, a Lenovo, (which was easy), then connecting it to a USB port on my Linux Computer.

I used a USB 3.0 to SATA Adapter Cable for 2.5in SSD HDD Drives (pictured).

USB 3.0 to SATA Adapter Cable for 2.5in SSD HDD Drives

Fortunately, I had another identical size external USB drive too, which I attached via USB. My Linux computer contains a hard drive too, so now there are three drives attached. Crucially the Windows drive and the new destination drive are not mounted.

You can use the command lsblk -e7 to list available drives (which are known as block devices). This command prints all block devices (except RAM disks) in a tree-like format by default. Use lsblk --help to get a list of all available options.

In this listing you can see the internal 1TB drive /dev/sda, and an external 500GB drive /dev/sdb. Even if you are an expert it can be hard to determine what each drive is from the device name but its obvious (to me that /dev/sda is my running Linux because it contains the boot partition and a large partition for everything else. If in doubt unplug all external drives and rerun this command after plugging them in one at a time until you understand what device refers to what drive.

$ sudo lsblk -e7
sudo lsblk -e7
NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda    8:0    0 931.5G  0 disk 
├─sda1
│      8:1    0     1G  0 part /boot/efi
└─sda2
       8:2    0 930.5G  0 part /var/snap/firefox/common/host-hunspell
                               /snap
                               /
sdb    8:16   0 465.8G  0 disk 
├─sdb1
│      8:17   0   100M  0 part 
├─sdb2
│      8:18   0    16M  0 part 
├─sdb3
│      8:19   0 464.8G  0 part /media/username/XXXXXXXX12345678
└─sdb4
       8:20   0   825M  0 part

GParted — a graphical tool for managing disks on Linux

GParted is a free partition editor for graphically managing disk partitions.

GParted allows you to resize, copy, and move partitions without data loss, enabling you to grow or shrink drives, create space for new operating systems and attempt data rescue from lost partitions. 

GParted makes it very much easier to understand which block device represents each drive and this is vitally important because the destination will be overwritten!

GParted — a graphical tool for managing disks on Linux

Installing GParted

$ sudo apt update 
$ sudo apt install gparted

In GParted you can click on the drop down menu on the right hand side to visually check each block device and make sure you know which is which. In this screenshot you can see that what is obviously a Windows 8.1 drive is /dev/sdb.

Installing ddrescue

$ sudo apt install gddrescue

Using ddrescue

In this example (taken from the ddrescue documentation) a drive /dev/sdb is being copied to a new drive /dev/sdc, using -f to overwrite the output device, and -r3 to retry for a maximum of three passes. finally it writes a mapfile called mapfile, which is a data file about the operation. Don't just copy this command. Pay attention to device names!

$ ddrescue -f -r3 /dev/sdb /dev/sdc mapfile

Be patient with ddrescue! Do not interrupt once you start! Note that a 1TB drive took about 7 hours. Just make sure your computer doesn't hibernate or sleep and leave it to finish.

Installing DDRescue-GUI on Ubuntu 24.04

DDRescue-GUI helps users recover important data fast, using GNU ddrescue but without having to understand the command line, which can be daunting.


See also:
DDRescue-GUI homepage
GNU ddrescue homepage
GNU ddrescue manual
GNOME Partition Editor - GParted

Licences, trademarks, source code licences and attributions

Licences, trademarks, source code licences and attributions

Multizone and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited licence granted by Open Source Matters, Inc. 928uk® is a trademark of Multizone Limited, registered in the UK. AdMob™, AdSense™, AdWords™, Android™, Chrome OS™, Chromebook™, Chrome™, DART™, Flutter™, Firebase™, Firestore™, Fuchsia™, Gmail™, Google Maps™, Google Pixel™, Google Play™, Pixelbook Go™, and Pixel™ and other trademarks listed at the Google Brand Resource center are trademarks of Google LLC and this site is not endorsed by or affiliated with Google in any way. Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. App Store is a service mark of Apple Inc. The OSI logo trademark is the trademark of Open Source Initiative. Microsoft, CoPilot, Microsoft 365, Microsoft Teams, and Windows are trademarks of the Microsoft group of companies. ROKU, the ROKU Logo, STREAMING STICK, ROKU TV, ROKU POWERED, the ROKU POWERED Logo, ROKU READY, the ROKU READY Logo, the purple fabric tag design,and the purple d-pad design are trademarks and/or registered trademarks of Roku, Inc. in the UK, the United States and other countries. UNIX® and the X® logo are registered trademarks of The Open Group. Any other product or company names may be trademarks™ or registered® trademarks of their respective holders. Use of these trademarks in articles here does not apply affiliation or endorsement by any of them.

Where the source code is published here on ezone.co.uk or on our GitHub by Angus Fox, Multizone Limited it is licenced according to the open source practice for the project concerned.

BSD 3-Clause "New" or "Revised" Licence
Original source code for mobile apps are licenced using the same licence as the one used by "The Flutter Authors". This Licence, the BSD 3-Clause "New" or "Revised" Licence (bsd-3-clause) is a permissive licence with a clause that prohibits others from using the name of the project or its contributors to promote derived products without written consent.
GNU General Public Licence v2.0 or later
Original source code for Joomla! published here on ezone.co.uk by Angus Fox, Multizone Limited is licenced using the same licence as the one used by Joomla!. This Licence, the GNU General Public Licence Version 2 or later (gpl-2.0) is the most widely used free software licence and has a strong copyleft requirement. When distributing derived works, the source code of the work must be made available under the same licence.

You can use any code you find here, just respect the licences and dont use the name of this site or our company to promote derived products without written consent. I mean, why would you? You're not us!

Amazon Associate
As an Amazon Associate we earn from qualifying purchases.
Logo
Our Logo Image is by Freepik. We chose it because its an M and also the letter A twice - and that represents us.