30

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. Commented 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? Commented Mar 8, 2015 at 9:26
  • Not at all. If it makes things easier, the new disk can be part of vg0 as well. Commented Mar 8, 2015 at 9:31

1 Answer 1

39

One volume group solution:

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

Be aware the pvmove command can take a long time depending on the size of your disk.

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 should 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
8
  • Wow, seems I completely misread the pvmove man page. In that case I'll obviously settle for the one volume group solution. :) Commented Mar 8, 2015 at 9:52
  • 1
    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). Commented 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. Commented Jul 5, 2015 at 23:42
  • 3
    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) Commented Nov 15, 2016 at 13:43
  • 1
    warning: tar with * might skip hidden (dot) files. I prefer the following line: tar cC /bar . | tar xC /mnt Commented Dec 22, 2023 at 20:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.