Linux – LVM and cloning HDs

grublinuxlvm

Using Linux, I have several backup levels. One of them is a periodical sector by sector copy (using dd) of my laptop harddisk to an external USB disk. Yes, I have other backups too, like remote rsync.

This approach (the disk dd) is OK when cloning a HDD with no LVM volumes, since I can plug the external disk anytime and mount the partitions simply mounting /dev/sdb* instead of /dev/sda*. Trivial and handy.

Today I moved ALL my harddisk (including the /boot) to LVM. Everything works fine. I will stress it for a couple of days, and then I will do a sector by sector copy to my external harddisk.

Now I have a problem, I guess.

If in the future I plug the external USB HDD to recover any file, the OS will detect a duplicate LVM configuration, with the same name and the same UUID. Even doing a vgrename (which LVM would be renamed, the internal HDD or the external HDD?), the cloned UUID will not change. Is there any command to change name and UUID? Ideally I would clone the HDD and then change the LVM group name and its UUID, but I don't know how to do it.

Another related issue would be…

In the past I have booted my laptop using the external disk, using the BIOS boot menu and changing GRUB entries manually to boot from /dev/sdb instead of /dev/sda. But now my current GRUB configuration boots directly from a LVM logical volume, something like: set root='(LVM-root)' in my grub.cfg. So… What is going to happen with duplicated volumes?

Any suggestion?

I guess I could repartition my external harddisk and change backup strategy from dd to rsync, but this disk has windows installed too, and I really would like to have a physical "real" copy.

Best Answer

I agree with one of the previous answers -- running dd on the whole disk is not a great solution here. If the reason you're stuck on dd has to do with backing up another OS, then you can use dd only for those other OS partitions, and rsync for the linux partitions.

Part of the problem is that if you run dd of the whole disk while you have filesystems up and mounted from it, there is no way to ensure the backup is consistent. It may work 9 times out of 10, but under any load, the resultant backup could be corrupted. The only way to ensure this doesn't happen is to unmount all filesystems and deactivate all volume groups for the entire time that the dd is running. Not very convenient if your / is mounted from LVM.

In any event, if you insist on sticking with this approach, the tool you're looking for to rename a duplicated vg is called "vgimportclone". It's intended for use with device level snapshots, but it will work with dd as well.

Related Question