Skip to content

Instantly share code, notes, and snippets.

@mivade
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivade/0b1ab9bfabff46b817f0 to your computer and use it in GitHub Desktop.
Save mivade/0b1ab9bfabff46b817f0 to your computer and use it in GitHub Desktop.
Recovery Notes

Recovering from a disk failure

This gist contains notes on what to do when needing to recover from a disk failure. A good tool to use is the SystemRescueCd live image which includes all the useful tools for performing recovery operations.

Booting to a USB disk from grub

If for whatever reason you can't boot from a USB disk with the BIOS, then you can still use grub. Simply do

set root=(hd1)
linux /path/to/kernel
initrd /path/to/intrd

The paths can be found by opening the live image on another computer and looking at the grub configuration files.

Encrypted disks

Use cryptsetup to decrypt the drive before being able to perform fsck on it.

See this page for details.

Further information.

Basic mounting of an encrypted image

cryptsetup luksOpen image_file.img some_name
vgscan --mknodes
vgchange -aly

Then mount via the command line or use Nautilus (or similar file manager) to do the mounting.

Backups

The Arch wiki has a good page on using dd for making backups. Note that this process could take more than 24 hours depending on the size of the partition and the number of errors!

Preventive measures

Some things to look into in the future:

Imported from elsewhere

The following subsections are imported from notes written down elsewhere a long time ago. They may or may not be outdated, but should eventually be revised to reflect current realities.

Useful Tools

Debian package names are listed here. Things in quotes are taken directly from the package description and probably indicates that no one has tried using them yet.

  • ddrescue/gddrescue: Copies partitions and automatically tries to correct for disk errors.
  • magicrescue: Recovers files by looking for magic numbers.
  • gpart: Try to fix broken partition tables
  • testdisk: "Partition scanner and disk recovery tool. TestDisk checks the partition and boot sectors of your disks."

General Procedure

It is typically a good idea to copy the damaged partition to another disk and work on that so that any accidental damage done while attempting to recover data isn't permanent (and also in case the damaged partition doesn't somehow develop more problems in the time it takes to recover everything). Say the damaged partition is mounted as /dev/sdc5. If the gddrescue package is installed, the following command will copy /dev/sdc5 to the partition image file sdc5.img:

ddrescue /dev/sdc5 sdc5.img

Note: This takes a long time to run. Depending on the size of and amount of damage to the partition, this could take > 24 hours.

You can use gpart to fix partition tables if that is the problem. Detailed instructions are here. To summarize, first run gpart /dev/sdc (or whatever the correct device is) to have it scan the device and guess what the partitions are. If it says the check is ok and the partitions look correct, you can write the partition table to the device with gpart -W /dev/sdc /dev/sdc. You may also want to use the -b option to backup the original partition table.

TestDisk seems to be a useful tool that can do what gpart can do plus more. It has not been extensively tested by this troper.

Magic Rescue will let you recover files of certain types. It works by looking for "magic numbers" that identify file types. To use it, you have to specify a "recipe" which specifies what types of files to look for and how to rescue them. The default recipes are in /usr/share/magicrescue/recipes/. For example, say you are trying to recover Excel files for a colleague who uses Windows. In that case, you would use the msoffice recipe like so:

magicrescue -d recovered -r msoffice disk.img

where -d specifies the directory to put recovered files in, -r gives the recipe to use, and disk.img is the partition to look at. This troper considers Magic Rescue somewhat of a last resort since it preserves neither directory structure nor file names. It's better than losing everything, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment