I have a Virtual Host server build with Ubuntu and Xen


  • Ubuntu 12.04.1 LTS 64Bits
  • xen-hypervisor-4.1


  • Hitachi SAS 15K 147GB (x2) in a Volume group
  • sda1 1GB /boot
  • sda2 146GB lvm
  • sdb1 147GB lvm

Every virtual machine has minimum two LV (root, swap)

I have available three new disks Hitachi SAS 15K 600GB I want to create a RAID5 with this disk and migrate all partitions from the VG. Is this is possible and how?

I know how to create a simple RAID with Simple RAID setup with mdadm but I want have the flexibility of the VG on my RAID. Is this is possible and how?

My need is to have the flexibility of VG but RAID redundancy.

2 Answers 2


First, you create the raid array. Assuming the new drives are sdc, sdd, and sde, and you don't already have any raid arrays, and you have created a single raid partition on each, do:

sudo -s
mdadm --create /dev/md0 -n 3 -l raid5 /dev/sd[cde]1
mdadm --detail --scan >> /etc/mdadm/mdadm.conf

Then you add it to the vg, move the logical volumes over, and remove the existing pvs:

pvcreate /dev/md0
vgextend vg0 /dev/md0
pvmove -i 10 /dev/sda2 /dev/md0
pvmove -i 10 /dev/sdb1 /dev/md0
vgreduce vg0 /dev/sda2 /dev/sdb1

Now you will need to transfer your /boot partition, rebuild your initramfs, and reinstall grub to get the system able to boot from the new disks:

mount --move /boot /mnt
rmdir /boot
cp -a /mnt /boot
umount /mnt
update-initramfs -u
dpkg-reconfigure grub-pc

A menu will ask which disks grub should be installed to. Select sdc, sdd, and sde. Now you can shutdown and remove the old disks.


Yes, you can use LVM on RAID, that's no problem at all.

You just create the RAID using mdadm, then pvcreate/vgcreate a new VG on it. Then you lvcreate the LVs and use dd if=/dev/oldvg/lv1 of=/dev/newvg/lv1 bs=1M or similar to copy your old LVs over to the new VG.

That'd be the fastest method - suitable if you do not wish to keep using your old disks, and if you do not make the move while the system is online. I.e. you'd do this from a rescue or live system.

If you need this to be online while the machine is running and actively working, then instead of vgcreate you would add the new raid as a PV to your existing VG, using pvcreate/vgextend.

Then you can use pvmove to make the LVs move from the old disk to the new RAID, and finally remove the old disk from the VG using vgreduce. In your case you'd repeat that for both disks.

You should be aware however that pvmove is very slow, and also one of the most dangerous operations in LVM. You may suffer data loss if anything goes wrong. Making a copy is safer - if something goes wrong, the original data is hopefully still unharmed.

  • I'm planning to use snapshots for move the data every Virtual machine and the Main Virtual Host too
    – rkmax
    Apr 11, 2013 at 17:09
  • 2
    Alternative to pvmove is to convert every LV to mirrors, and then once everything is synchronised, disconnect the old drives or use lvchange --splitmirrors and then you'll have a backup of the VG on the old drives. Apr 11, 2013 at 17:15
  • pvmove is NOT slow, nor dangerous. If the system crashes during the move, it will be restarted on the next boot.
    – psusi
    Apr 11, 2013 at 17:51
  • Online pvmove will always take much longer than a offline direct copy, due to the metadata updates, and the fact that the disk is in-use so pvmove has to be nice, but also due to implementation issues (it used to be particularly slow on RAID, google it, not sure if that's fixed). And one time it corrupted a filesystem for me - bug of course, but you do get those in Linux. In place data moving/restructuring operations are always dangerous (more dangerous than not doing them). mdadm --grow is also slow and one of the most dangerous operations for mdadm. Anyway: have a backup. Or two backups. Apr 11, 2013 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .