Recently I've had to backup/restore data from a failing drive with LVM over Raid.
Luckily I had access to the backup of the current metadata configuration located in "/etc/lvm/backup/".
Below is what the volumegroup looked like:
vg0 {
&nbs p; id = "xvni1W-24Xu-dVoR-PlXh-gQ vQ-62fL-QX64O3"
&nbs p; seqno = 9
&nbs p; status = ["RESIZEABLE", "READ", "WRITE"]
&nbs p; flags = []
&nbs p; extent_size = 65536 & nbsp; & nbsp; # 32 Megabytes
&nbs p; max_lv = 0
&nbs p; max_pv = 0
&nbs p; physical_volumes {
&nbs p; &nbs p; &nbs p; pv0 {
&nbs p; &nbs p; &nbs p; &nbs p; id = "9gbyhX-Owvj-u4Q4-wR1E-IE f2-gyUA-CJBCJK"
&nbs p; &nbs p; &nbs p; &nbs p; device = "/dev/md3" &nbs p; # Hint only
&nbs p; &nbs p; &nbs p; &nbs p; status = ["ALLOCATABLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; dev_size = 1928892288 # 919.768 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; pe_start = 384
&nbs p; &nbs p; &nbs p; &nbs p; pe_count = 29432 & nbsp; # 919.75 Gigabytes
&nbs p; &nbs p; &nbs p; }
&nbs p; }
&nbs p; logical_volumes {
&nbs p; &nbs p; &nbs p; lv0_sites {
&nbs p; &nbs p; &nbs p; &nbs p; id = "Sg1fYr-NTzr-8AA2-v29K-tc z5-rUMj-uRoXY1"
&nbs p; &nbs p; &nbs p; &nbs p; status = ["READ", "WRITE", "VISIBLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; segment_count = 1
&nbs p; &nbs p; &nbs p; &nbs p; segment1 {
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; start_extent = 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; extent_count = 1280 # 40 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; type = "striped"
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripe_count = 1   ; # linear
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripes = [
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; "pv0", 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; ]
&nbs p; &nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; lv0_m {
&nbs p; &nbs p; &nbs p; &nbs p; id = "scNeN4-4bmg-Y6kq-zKuO-n8 B8-s8mw-FTUYqk"
&nbs p; &nbs p; &nbs p; &nbs p; status = ["READ", "WRITE", "VISIBLE"]
&nbs p; &nbs p; &nbs p; &nbs p; flags = []
&nbs p; &nbs p; &nbs p; &nbs p; segment_count = 1
&nbs p; &nbs p; &nbs p; &nbs p; segment1 {
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; start_extent = 0
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; extent_count = 12800 # 400 Gigabytes
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; type = "striped"
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripe_count = 1   ; # linear
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; stripes = [
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; "pv0", 1280
&nbs p; &nbs p; &nbs p; &nbs p; &nbs p; &nbs p; ]
&nbs p; &nbs p; &nbs p; &nbs p; }
&nbs p; &nbs p; &nbs p; }
&nbs p; }
}
Now to extract data with dd, use the below formula (this will only work for linear stripe):
skip=$[extent_size*stripes+pe_ start] count=$[extent_size*(extent_co unt-1)]
So to get the lv0_m data off of the volume:
dd if=/dev/sdb4 of=/opt/bak/lv0_m.iso bs=512 skip=$[65536*1280+384] count=$[65536*(12800-1)] conv=sync,noerror
Once the iso is created, it can then be loop mounted via:
mount -o loop -t ext3 /opt/bak/lv0_m.iso /mnt/lv0_m
You should then be able to see all the files in the mount point which can then be used for data restoration.
- sandip's blog
- Login or register to post comments
Comments
I'm curious as to why you're subtracting 1 from the extent_count? Doesn't this end up leaving the final extent in the lv out of the output image?
By example, say the source lv has two segments instead of one:
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
&nbs
...so to handle this properly (if they actually were, for instance, on different pv's), one would need to use two dd's:
dd if=/dev/sdb4 of=/opt/bak/lv0_m.iso bs=512 skip=$[65536*1280+384] count=$[65536*(12000-1)] conv=sync,noerror
dd if=/dev/sdb4 of=/opt/bak/lv0_m.iso bs=512 skip=$[65536*13280+384] seek=$[65536*12000] count=$[65536*(800-1)] conv=sync,noerror
(note, i have no idea if seek on an output -file- will append properly)
if you map this out, you'll notice that effectively there is an extent-sized hole between the first and second segment, in the image. For an even more obvious example, say for some reason the segment is one extent large, the above would effectively not copy anything.