Linux LVM – Moving Logical Volume to a New Physical Disk

linuxlvm

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)?

Best Answer

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 /bat ; 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
Related Question