31
Aug
08

Live Disk Migration with Softraid and LVM

As disk space on my homeserver became rare, and I wanted to start using apples timemachine on a network share I needed to upgrade diskspace.

However, three of four ports where on my sata controller where already occupied and so I couldn’t extend my lvm’s physical volume easily with a new raid1 or raid5 array. So i decided to remove two 250GB disks and replace them by two new 500GB once.

Old disk layout:
sda1 10GB / sda2 240GB
sdb1 10GB / sdb2 240GB
sdc1 260GB / sdc2 240GB
md0, raid1, 10GB sda1, sda2
md1 raid5 480GB sda2, sdb2, sdc2
md1 pv (480GB) for lvm2

Desired layout (with two new 500GB disks):
sda1 10GB / sda2 490GB
sdc1 10GB / sdc2 490GB
sdd1 10GB / sdd2 490GB
md0, raid1, 10Gb sda1, sdc1, sdd1(spare)
md1, raid5, 980GB sda2, sdc2, sdd2
md1 pv (980 GB) for lvm2

Howto accomplish data migration with all services staying online.

Create Backups ;-) (I did)

Remove sdc2 from raid5 array
mdadm /dev/md1 --fail /dev/sdc2 --remove /dev/sdc2

New partitioning for sdc (man fdisk)

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1   *           1         609     4891792   fd  Linux raid autodetect
/dev/sdc2             610       60801   483492240   83  Linux

Add sdc1 to md0 and remove sda1, sdb1
mdadm /dev/md0 --add /dev/sdc1
mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1
mdadm /dev/md0 --fail /dev/sdb1 --remove /dev/sdb1

Create pv for sdc2 space and move all data temparary to it
pvcreate /dev/sdc2
vgextend VG00 /dev/sdc2
pvmove /dev/md1 /dev/sda1

Remove md1 from lvm and delte it
vgreduce VG00 /dev/md1
pvremove /dev/md1
mdadm -S /dev/md1

Shred old disks
shred -vfz /dev/sda
shred -vfz /dev/sdb

Prepare sdc as boot disk
grub-install --recheck /dev/sdc
grub
grub> root (hd3,0)
grub> setup (hd3)
grub> quit

shutdown -h now

Replace sda, sdb with new disks and power on

new partitioning sda,sda (man fdisk):

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1217     9775521   fd  Linux raid autodetect
/dev/sda2            1218       60801   478608480   fd  Linux raid autodetect

add sda1, sdb2 to md0
mdadm /dev/md0 --add /dev/sda1
mdadm /dev/md0 --add /dev/sda2 (spare)

Make each disk bootable
grub-install --recheck /dev/sda
grub-install --recheck /dev/sdb
grub
grub> root (hd1,0)
grub> setup (h10)
grub> root (hd2,0)
grub> setup (hd2)
grub> quit

Assembe new md1 (with one missing disk)
mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sda2 /dev/sdb2 missing

Create pv of md1 and move data to it
pvcreate /dev/md1
vgextend VG00 /dev/md1
pvmove /dev/sdc2 /dev/md1

Remove temp pv and add sdc2 to raid md1
vgreduce VG00 /dev/sdc2
pvremove /dev/sdc2
mdadm /dev/md1 --add /dev/sdc2

Dump raid config
echo "DEVICE /dev/sda* /dev/sdb* /dev/sdc*" > /etc/mdadm/mdadm.conf
mdadm --detail --scan >> /etc/mdadm/mdadm.conf

That it, we are done!
cat /proc/mdstat
Personalities : [raid1] [raid6] [raid5] [raid4] 
md1 : active raid5 sdc2[3] sda2[0] sdb2[1]
      957216768 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [>....................]  recovery =  3.8% (18258160/478608384) finish=107.4min speed=71383K/sec

md0 : active raid1 sda1[0] sdb1[2](S) sdc1[1]
      4883648 blocks [2/2] [UU]

unused devices:

pvscan 
  PV /dev/md1   VG VG00   lvm2 [912,87 GB / 480,50 GB free]
  Total: 1 [912,87 GB] / in use: 1 [912,87 GB] / in no VG: 0 [0   ]


0 Responses to “Live Disk Migration with Softraid and LVM”


  1. No Comments

Leave a Reply