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
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.