LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Data recovery from lvm (https://www.linuxquestions.org/questions/linux-general-1/data-recovery-from-lvm-915521/)

Gil@LQ 11-25-2011 12:56 PM

Data recovery from lvm
 
hi every one...

i have a hdd and 3 partitions (1 with data and 2 empty)due to increased size of my virtual machines one partition, i planned to create volume group with all 3 partitions, so i changed the partition with data to lvm using tool data is fine. After that i mistakenly created a volume group with the partition which has data and then added empty partions to the volume grop.Then i realised i did mistake so i removed the partion with data from the volume group using vgreduce command. after removing it when i try to mount it to get the data, it say's unknow filesystem which means i need to format. Please help me is there any way to get that data back from that lvm.i didn't do any foramt, what i did was created volume group with that partition and again removed it from volume group..

Please help me i have all my virtul machines on it.

thank you very much.

_bsd 11-28-2011 07:02 AM

In order to create a VG (Volume Group) you needed to have one or more PV (Physical Volume).

It's difficult to discern from your text, whether or not you initially had a VG with PVs, or just a plain MBR.
If it's the former, most of a VG can be restored using the files stored under /etc/lvm. /etc/lvm/backup keeps backups of the "current" state of a VG. /etc/lvm/archive keeps state prior to any VG,LV command, such as lvreduce.
One may carefully restore a VG to a prior state using the correct file, editing if needed.

However if it's the latter, you previously had an MBR, and you executed pvcreate on a device or partition, you likely overwrote the MBR.

The best course in either event is to resore from a backup.

If, as I'm guessing, you have no backup, please accurately (detailed), describe the status of your boot table type, partitions, existing PV,VG,LV prior to making your error.

Gil@LQ 11-28-2011 10:20 AM

hi bsd, i found your reply little late, so i had to format it and created new one. my main doubt now is, as you said i created a PV,VG and then i create LV, it's all fine, my point is if i have i increase a the VG size, either i need to add a partition to existing VG or a newly crated PV,using vgexted right? But here my requirement is i don't have free space to create new partition or new PV all i do is i have a partition with some data, so i change the filesystem id to lvm and is there any way to add it to a VG with out data loss.

_bsd 11-28-2011 11:37 AM

No, you cannot just change the type to lvm.

You have to backup your data!

Then you can add the partition to the VG, create and/or extend the LV, and then restore the data.

You may add a device or just a partition
First you must
Code:

eg: pvcreate /dev/sda or pvcreate /dev/sda1
Depending on whether you're adding a device or partition, obviously changing the parameters in my example to match yours.

Add the new PV devices(s) to the existing VG
Code:

eg: vgextend VGNAME pvname pvname...
Now the VG is larger.

Grow the LV
Code:

eg: lvextend --extents '100%FREE' LVNAME
Will add all of the newly added space (actually any/all free space in VG) to the LV named on the lvextend command.

Then you need to grow/or recreate your fs. You didn't mention fs type, but many/most support extend/grow command of some type.

Now you can restore the data from backup.


This cannot be done in place, with pre-existing data, expecting data to be preserved.

Gil@LQ 11-28-2011 12:28 PM

ya, i realized that we can not add any pv with data to a existing vg, new pv or partion will be used as a raw space to a existing vg to increage the vg, from it we can create lv or incerease existing vg.
Quote:

eg: lvextend --extents '100%FREE' LVNAME
this is the new command, you given me to increase existing lv to 100% space available in the vg.


thank you very much.


All times are GMT -5. The time now is 08:16 AM.