22

I have three logical volumes in a single volume group using a single physical volume (the whole existing disk /dev/sda).

I now want to move one of those logical volumes to a new, faster disk, i.e., going from:

/dev/sda
    |-vg0-root → mounted to /
    |-vg0-foo  → mounted to /foo
    |-vg0-bar  → mounted to /bar

to:

/dev/sda
    |-vg0-root → mounted to /
    |-vg0-foo →  mounted to /foo

/dev/sdb
    |-vg1-bar  → mounted to /bar

From what I understand I cannot use pvmove or vgsplit because there's only one physical volume in the existing volume group.

What's a good approach to achieve this (preferably online, creating a new volume group for the new disk is not a requirement)?

3
  • I did check the many similar questions, but as far as I understand, those don't describe my situation. Bonus question: Is using a whole disk as physical volume a bad idea per se? It seems this decision made the solution much harder in my case.
    – htorque
    Mar 8, 2015 at 9:15
  • 2
    Do you have any particular reason you don't want to add your new physical disk as a physical volume to the existing volume group? Mar 8, 2015 at 9:26
  • Not at all. If it makes things easier, the new disk can be part of vg0 as well.
    – htorque
    Mar 8, 2015 at 9:31

1 Answer 1

32

One volume group solution:

 pvcreate /dev/sdb
 vgextend vg0 /dev/sdb
 pvmove -n /dev/vg0/bar /dev/sda /dev/sdb

Two volume group solution:

 pvcreate /dev/sdb
 vgcreate vg1 /dev/sdb
 lvcreate -l100%FREE vg1
 mkfs -t ext4 /dev/vg1/lvol1
 mount /dev/vg1/lvol1 /mnt

Now difficult part, all activities MUST stop on /bar:

 cd /mnt ; ( cd /bar ; tar cf - * ) | tar xf -
 cd /
 umount /mnt
 mount /dev/vg1/lvol1 /bar

where

  • pvcreate erase all data on disk (and prepare for LVM)
  • lvcreate sould create a logical volume lvol1, you specify lv name with -n bar
  • I use HP-UX syntax for lv, you might have to use /dev/mapper/myvg-mylv syntax

Once you have verified data are OK, in new place:

  • you can safely delete old /bar
  • edit /etc/fstab to use new /bar
6
  • Wow, seems I completely misread the pvmove man page. In that case I'll obviously settle for the one volume group solution. :)
    – htorque
    Mar 8, 2015 at 9:52
  • Actually, one could use vgsplit after pvmove to achieve the two volume group solution a bit easier (however, the logical volume still needs to be deactivated using lvchange).
    – htorque
    Mar 8, 2015 at 12:37
  • 2
    The usefulness of "pvmove" is a very good reason to use a single VG instead of multiple VGs.
    – tgharold
    Jul 5, 2015 at 23:42
  • 2
    It seems like vgreduce can then be used to remove the old volume if that is the requirement (It wasn't for the specific question, but a question asking about moving all volumes would likely be marked a duplicate) Nov 15, 2016 at 13:43
  • My current experience is that in the single vg solution, pvmove requires an -n flag to specify the logical volume. Or it says a Physical volume /dev/vg0/bar not found Run `pvmove --help' for more information. error message. The man page says the same. May I insert it into the post?
    – peterh
    Sep 11, 2017 at 16:15

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.