Lots of people make use of linux's
lvm (Logical Volume Manager) for
providing services such as disk volume resizing and snapshotting under linux.
But few people seem to know about the little
pvmove utility, which offers a
very powerful facility for migrating data between disk volumes on the fly.
Let's say, for example, that you have a disk volume you need to rebuild for some reason. Perhaps you want to change the raid type you're using on it; perhaps you want to rebuild it using larger disks. Whatever the reason, you need to migrate all your data to another temporary disk volume so you can rebuild your initial one.
The standard way of doing this is probably to just create a new filesystem on
your new disk volume, and then copy or
rsync all the data across. But how
do you verify that you have all the data at the end of the copy, and that
nothing has changed on your original disk after the copy started? If you did
a second rsync and nothing new was copied across, and the disk usage totals
exactly match, and you remember to unmount the original disk immediately,
you might have an exact copy. But if your original disk data is changing at
all, getting a good copy of a large disk volume can actually be pretty tricky.
lvm/pvmove solution to this problem is this: instead of doing
a userspace migration between disk volumes, you add your new volume into the
existing volume group, and then tell lvm to move all the physical extents
off of your old physical volume, and the migration is magically handled by
lvm, without even needing to unmount the logical volume!
# Volume group 'extra' exists on physical volume /dev/sdc1 $ lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert data extra -wi-ao 100.00G # Add new physical volume /dev/sdd1 into volume group $ vgextend extra /dev/sdd1 Volume group "extra" successfully extended $ lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert data extra -wi-ao 200.00G # Use pvmove to move physical extents off of old /dev/sdc1 (verbose mode) $ pvmove -v /dev/sdc1 # Lots of output in verbose mode ... # Done - remove old physical volume $ pvremove /dev/sdc1 $ lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert data extra -wi-ao 100.00G
The joys of linux.blog comments powered by Disqus