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
-
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.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.