LVM2 to RAID5 Migration – How to Migrate an Entire Volume Group

lvmsoftware-raidUbuntu

I have a Virtual Host server build with Ubuntu and Xen

SO

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

Disk

  • 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.

Best Answer

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.

Related Question