Rescuing and restoring data
Disk Workshop
If you need to use ddrescue
to rescue a whole data storage medium rather than just one partition, you can run fdisk -l copy.img
to see whether the partition table is still present and correct. This gives you a list of all partitions, with the numbers behind the names in the first column matching the respective numbers in the device files.
If you are repairing a disk with the newer GPT (GUID partition table), use gdisk
[3]. You might have to install this tool using the package manager. On Ubuntu, it resides in the gdisk package. The following command:
gdisk -l copy.img
lists partitions in the image.
Finds
If you are missing one or more partitions, you can run TestDisk against the image [4]. This program tries to detect and recover partitions. You will need to install TestDisk [5] using the package manager; on Ubuntu, it resides in the testdisk package. Then, you simply call the tool and pass in the image file with testdisk copy.img
, which takes you to the text-based user interface (Figure 5).
At the top, TestDisk again presents the image file. Make sure that Proceed is highlighted at the bottom and press Enter. Next, you need to let TestDisk know whether the drive uses the modern GPT. In this case, select EFI GPT; otherwise, use Intel. Finally, restart with Analysis.
TestDisk now shows a summary of the current situation in the upper part of the window. Missing or duplicate partitions in the list indicate a defect. In this case, launch Quick Search. TestDisk runs a search and then lists all the partitions it finds (Figure 6). Pressing P lets you look at the files and directories on a partition; the arrow and Enter keys are used for navigation. Pressing Q takes you back to the list of all partitions.
After the tool has tracked down all the partitions, select Write. If you are still missing one or several partitions, select Deeper Search. TestDisk then performs an in-depth analysis, which takes a little longer. It might even reveal ancient partitions that partially overlap. Access the previously missing partition in the list; if in doubt, just guess. Use the arrow keys to make a primary or logical partition from the rediscovered partition. This partition is then restored by TestDisk.
TestDisk ignores all partitions with a D in the first column, so they remain deleted. When you are satisfied, press Enter and write the new partition table with Write. Press Y to confirm the prompt and then press OK to enable the write. Quit lets you go back a menu until TestDisk finally quits.
Choices
To mount the restored partitions, use the package manager to install the kpartx
program, which is part of the multipath-tools package (on Ubuntu, the package goes by the same name) and then point it to the image file:
kpartx -a -v copy.img
The tool now creates a separate device below /dev/mapper
for each partition in the image file. You only have to read the device file for your partition in the information displayed and then mount
(Figure 7):
mount -o loop,ro /dev/mapper/loop0p1 /mnt
The command in this example mounts the first partition (loop0p1
) from the image in the /mnt
subdirectory.
« Previous 1 2 3 4 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.