Open Source Software and Linux

Dec 18 2008   2:03PM GMT

Recovering files from an LVM or ext3 partition with testdisk

John Little Profile: Xjlittle

I recently had a virtual server crash that was using LVM as the disk on which the VM was installed. To complicate matters even further the virtual machine was using LVM formatted with ext3 for it’s file systems. I had 25 GB of music on here that I did not want to lose so I was bent on figuring a way out of my dilemma.

I eventually ran across an application called testdisk. Testdisk turned out to be the answer to my problem. Although not very intuitive and lacking in documentation I am going to lead you through using the testdisk application in case you ever need it.

Testdisk runs as a static application. All you need to do is download and extract it. Once it is extracted cd into the directory call linux. Execute the program testdisk_static followed by device path of the disk from which you want to recover data. Shown below is the command that I used.

./testdisk_static /dev/linux-virtuals/music.repo

The first screen that you see will look like the following screenshot. The disk from which you want to recover should be highlighted. Click on proceed to bring up the next screen.
1st screen after running testdisk

Choose Intel as your disk type unless you know that you are using one of the other types listed.
choose Intel for partition

On the next screen hit enter to have test disk analyze analyze your partition.
analyze partition
Test disk to perform a quick search of your partiton. After you hit enter you are asked if you want testdisk to look for Vista partitions. Click no unless you have Vista partitions.

A short list of the partitions that testdisk found will show on your screen. Click enter to continue.
testdisk short list of partitions

On this screen you will be prompted to continue a deeper search. Click enter to have testdisk thoroughly search the partition and find anything that is deleted. This may take awhile to complete depending on the size of the partition.
testdisk deeper search

Once it is finished it will let you know. This is where things can get a little tricky. Scroll down through the list of partitions until you find one that is marked with a P in the legend below the list. Click P to see the list of files contained in that partition. Note that not all listed partitions will show the P in the testdisk legend. If they don’t there isn’t any data their to collect.
partition with P data

Once you’ve pressed the P you will see a list of directories. Highlight the directory where you believe your files are and hit enter. You will have to work down through the original directory structure that you had on disk. If those don’t contain the files use the right arrow key to back your way out to the top level of the file system. Scroll down until you find another partition marked with a P and check it for your files.
directory tree

directory tree

directory tree

my music!

An Voila! Here is my music. At the bottom of the screen you are told to hit copy. If you want the whole directory back up one level by hitting the left arrow key. Highlight the directory to copy it by pressing c. This will bring up a list of your current working directory. Keep hitting the left and down arrow keys until you are in the directory where you want to save your recovered files.

Hope this helps. Everything I’ve ever read said ext3 couldn’t be recovered. Don’t believe it-here it is in black and white. So go get those files that you didn’t back up! 🙂 (Yes I learned my lesson.. here comes Amanda or Bacula or Backup Manager!)


1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • smhoff
    This worked for me! Thanks a ton!
    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: