LVM: Using an image of a PV?

Posted on

LVM: Using an image of a PV? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, lvm, image, dd, .

I have a logical volume spanning several drives. One of those drives (3TB, the largest of the bunch) is dying, and I am currently making an image of it (via ddrescue). I’m not yet sure on how to use this image as a replacement PV though.

The steps I’m currently thinking of are:

  1. Mount image as a loop device, with losetup
  2. pvscan
  3. vgchange -a y

Would, after this procedure, LVM detect the loop device as a PV that’s part of my volume group (among the working physical drives), and allow me to access the logical volume as normal?

Everything I’ve found on LVM images so far seems to be about imaging logical volumes, not physical ones, as I am doing now.

If this didn’t work, I would just create an image of the entire logical volume (using the failing drive as a PV), however that would mean leaving the failing drive idle but powered on for hours while ddrescue copies the data on the perfectly working drives, risking more data loss.

Solution :

What I might do is …. assumming that the LVs within the volume group contain standard filesystems:

  1. Do a standard backup of each LV.
  2. Replace the failing disk
  3. Remake the volume group, and logical volumes from scratch just like was done originally.
  4. Restore each logical volume from the backups.

You might be able to shortcut things for some logical volumes if they do not span physical volumes. The shortcuts would be to create the new logical volume with the exact same parameters so that the location of the internal filesystem data would still be consistent.

The file etclvmlvm.conf is where you can set which kind of devices are probed by pvscan. Just set a suitable pattern that includes your loopback device.

For anyone who might find this later, my image has now been written and lvm is able to use the loop device, as described in the initial question.

Leave a Reply

Your email address will not be published.