[linux-lvm] Replace small drive with bigger, using LVM?

Jarkko Oranen oranenj at iki.fi
Wed Sep 10 10:13:47 UTC 2014


On Wed, 2014-09-10 at 10:02 +0100, Craig wrote:

<cut out a bunch of stuff>

> So I've got /boot in a primary partition and then swap and / come via 
> LVM in the extended.
> 
> So I'd love to do something like
> * dd /dev/sda1 to /dev/sdb1 or something like that and have my /boot 
> volume set up
> * install grub into the MBR of /dev/sdb
> 
> The if I can make the right LVM setup, get / from my live system copied 
> to the new drive, remove the old drive lv from the vg and then 
> physically swap the HDDs round.
> 
> Can someone help me with the finer details of this or isn't it doable?
> TIA
> -C

It's very much doable, but as always, the standard disclaimer applies:
back up your data etc.

As it is now, you might just as well move /boot to reside on an LV as
well; a recent enough GRUB2 (meaning: not ancient) will support booting
from it just fine. This way, you won't even need to partition your new
disk. Of course, you're free to use an actual boot partition if you
want.

to move a VG from one PV to another, you can do the following

Assuming source PV is sda2 and new disk is sdb and you don't partition
it:

pvcreate /dev/sdb

vgextend volume_group /dev/sdb

pvmove volume_group /dev/sda2 /dev/sdb

vgreduce volume_group /dev/sda2 # this removes the old PV from the VG.
it will only succeed if the PV is not actually in use, so it's safe.

GRUB2 supports being installed in the MBR of a disk that's an LVM2 PV.

You can keep your old disk with its boot partition and bootloader
installed until you've successfully booted off the new disk, so there's
little danger that you'd actually render your system completely
unbootable.

Remember to update fstab etc. to reflect the new boot partition as well.

I've been told that moving data off the VG with the root volume in it on
a running system may result in a deadlock due to the way the LV device
is temporarily suspended during copies, leading to trouble if the copy
operation requires a read from the LV. However, I've done it several
times with no issues. Still, using a live USB or CD is recommended. If
it does deadlock, you should just be able to reset and continue the
pvmove where it left off... it's quite resilient and won't lose your
data very easily.


--
Jarkko








More information about the linux-lvm mailing list