After I played with mdadm a bit too hard, I'm now tryng to recover my lvm2 volumes that were sitting in the original RAID1 array. pvscan finds nothing, but that's not a surprise: since mdadm is not able to rebuild the array, pvscan has no /dev/md1 to look at.

However I know (er... I hope) my lvm2 volumes are still there, I think I only zapped the raid metadata.

My idea is to losetup /dev/sdc2 under /dev/loop1 with an offset using a live sysresccd, so that I skip the broken RAID metadata in /dev/sdc2 and reach the PV itself. I plan something like:

losetup -o xxxxxx /dev/loop1 /dev/sdc2

Then pvscan can find the volume in /dev/loop1. The problem is that I don't know the offset (but that can be overcome by studying or by trial and error) and, most importantly, that losetup does not work with physical devices. How can I create a device that points to another device with an offset? Or, how can I make pvscan look for physical volumes using an offset?

EDIT after @lsd comment:

When I tried:

losetup -o 32256 /dev/loop1 /dev/sdc2 

I got:

losetup: /dev/sdc2: warning: file smaller than 512 bytes, the loop device maybe be useless or invisible for system tools. 

and I assumed the warning was telling me something was wrong, because /dev/sdc2 is smaller than 512 bytes only if you consider it as a normal file, but if losetup supported block devices it should know its real size... should I ignore the warning nevertheless?

  • I see according to the losetup man pages (rhel6.5) that it accepts both a physical device, and a data offset using the -o parameter. Did you try that? – lsd Jan 14 '15 at 16:25
  • @lsd have you got a link to said RHEL manpage? Losetup manpage in sysresccd 3.5.7 does not tell anything about physical devices. – Lucio Crusca Jan 14 '15 at 16:40
  • This is the manpage to losetup on rhel6.5 dated 2003-07-01, from util-linux-ng rpm. As the man page is old it may not be that accurate. I've been looking for lvm information also... – lsd Jan 14 '15 at 16:49
  • Everything I'm seeing suggests it would be easier to dd the disk into a file on another hard drive (in addition to being safer), then try to mount from the image. – lsd Jan 14 '15 at 18:40
  • Following your advice, I assumed losetup supported physical devices and I found the correct offset, which is in my case 134152192. If you turn your comment into an answer I'll accept it, thanks again. – Lucio Crusca Jan 14 '15 at 22:33

losetup works just fine on device files. At least on Ubuntu 14.04. Linux 3.13.0-43-generic with util-linux 2.20.1-5.1ubuntu20. And with 2.26-rc1 from git.

sudo losetup -o 32256 /dev/loop5 /dev/sdb3
sudo tail -c 32257 /dev/sdb3 | sudo cmp - /dev/loop5 

(for some reason, process substitution doesn't work: sudo cmp <(sudo tail -c 32257 /dev/sdb3) /dev/loop5. "cmp: /dev/fd/63: No such file or directory")

I'm not using lvm anymore on this system. I don't remember LVM breaking normal loopback devices. Unless it does some form of locking on the plain block devices, so they can't be used directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.