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).

Figure 5: In TestDisk, you select an item with the arrow keys and press Enter to trigger the desired action.

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.

Figure 6: TestDisk has rediscovered the missing primary partition.

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
Figure 7: Kpartx makes the restored, first partition accessible as the /dev/mapper/loop0p1 device.

The command in this example mounts the first partition (loop0p1) from the image in the /mnt subdirectory.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Top 10 Knoppix Rescue Tricks

    The Knoppix Live Linux distro is packed with powerful tools for fixing broken systems. We ask Knoppix creator Klaus Knopper for his favorite Knoppix rescue tricks.

  • Data Reconstruction

    One false click can quickly delete important data, or even an entire partition. If a backup tool is missing, only a rescue specialist can help.

  • SystemRescueCd

    The SystemRescueCd live system contains numerous tools that you can use to recover deleted files or a defective system.

  • Parted Magic

    It's really annoying when a disk suddenly dies on you or a typo in a command deletes important data. The free Parted Magic Live distro offers help.

  • SystemRescueCd

    If you accidentally delete data or format a disk, good advice can be expensive. Or maybe not: You can undo many data losses with SystemRescueCd.

comments powered by Disqus
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.

Learn More

News