I have been a happy user of LVM for the last 3 years. Never had any problem until last week when everything disappeared from my disk.
Grub refused to boot the system and every lvm command I knew vgscan, lvscan or pvscan gave me nothing.
After some research I discovered that I should have included in my backup the /etc/lvm directory. Well, good to know for next time.
So after a few hours of research and I guess a little bit of luck I managed to recover all my data.
1. So what is in the /etc/lvm directory?
Backup files generated by LVM each time you change the structure of the disk. They look like that
creation_host = "mypc" # Linux mypc 2.6.35-28-generic
#50-Ubuntu SMP Fri Mar 18 18:42:20 UTC 2011 x86_64
creation_time = 1303817218 # Tue Apr 26 12:26:58 201
main { ## Note that main is the name of my volume group
## and therefore this be diffent for you
id = "29gZ34-vvVq-qING-irrW-oxJP-muBC-6R6x1Q"
seqno = 13
status = ["RESIZEABLE", "READ", "WRITE"]
flags = []
extent_size = 8192 # 4 Megabytes
max_lv = 0
max_pv = 0
physical_volumes {
pv0 {
id = "IfhgDL-LpD6-cbCH-sEDp-Fsu9-la81-KlyGdC"
device = "/dev/sda6" # Hint only
status = ["ALLOCATABLE"]
flags = []
dev_size = 321042897 # 153.085 Gigabytes
pe_start = 384
And it goes on and on
2. How to get this file without backup?
So assuming you did not save that drive you here is a way to get it back. Boot using a rescue CD or a liveCD and once logged in as root in the shell, run the following command.
grep -a -B500 -A500 physical_volumes /dev/sda6 > results
This will search the whole lvm physical volume (sda6 in my case) for a string that we know is included in the file we are after. The -A and -B options tell grep to return 500 lines before the match and 500 lines after the match.
You might have to repeat this operation if your lvm setup was using multiple drives.
3. Get some coffee
It will take quite a while.
You might have to repeat this operation too.
4. Sort the results
The res file will contain quite a lot of garbage and most likely several copies of the file we are after. Why several copies? Remember that LVM save a copy each time you change the disk structure.
An easy way to find out which version is the latest is to use the creation_time filed that is included in the file
#grep -a creation_time\ \=\ [0-9] res creation_time = 1229967708 # Mon Dec 22 17:41:48 2008 creation_time = 1229967855 # Mon Dec 22 17:44:15 2008 creation_time = 1286641220 # Sat Oct 9 17:20:20 2010 creation_time = 1286641265 # Sat Oct 9 17:21:05 2010 creation_time = 1238857427 # Sat Apr 4 16:03:47 2009 creation_time = 1239575936 # Sun Apr 12 23:38:56 2009 creation_time = 1229968090 # Mon Dec 22 17:48:10 2008 creation_time = 1303817218 # Tue Apr 26 12:26:58 2011 creation_time = 1286641220 # Sat Oct 9 17:20:20 2010 creation_time = 1286641265 # Sat Oct 9 17:21:05 2010
In my case the latest backup was done in April 2011. So I can use a text editor to extract the file out of the res file.
I used the timestamp 1303817218 to locate the file within the res file.
5. Reinitialize the physical volume
pvcreate -u IfhgDL-LpD6-cbCH-sEDp-Fsu9-la81-KlyGdC /dev/sda6
You will find the id of the physical volume in the file you recently recovered.
You might have to repeat this operation if you have multiples volumes in the LVM.
6. Reinitialize the volume group
vgcreate main /dev/sda6 [second drive ...]
Name is the name of my volume group, you will most likely remember what is yours but most likely it is the name before the first opening bracket in your file.
If you have multiples physical volumes, append at the end of the command line.
7. restore the lvm configuration backup
vgcfgrestore -f backup.vgc main
At that stage if you are lucky lvscan should give you the list of you logical volumes and you should be able to mount them.
Good luck with your recovery and next time don’t forget to backup the /etc/lvm directory.