Friday, October 05, 2007

How to Migrate rootvg from EVMS to LVM2

I have been using EVMS to manage my Gentoo Linux box for the past few years, primarily because its LVM and RAID features were integrated, but now that it appears EVMS is not going to be accepted by the community at large, and mdadm has emerged (dramatically improving the manageability of Linux software RAID), and LVM2 has seen significant improvements in functionality, I'm ready to migrate to a more standard configuration: LVM2 VGs on Software RAID partitions.

This procedure is what I used to upgrade from a single 36GB SCSI drive that hosted my /boot, swap, and root VG via EVMS to twin mirrored 36 GB SCSI drives using LVM2 and Software RAID...

The original 36 GB drive in this procedure started as /dev/sda,...

0) Shutdown
1) Install the new pair of disks as sdb and sdc
2) Boot (ideally into single user mode, so your file systems will not be trafficked while you're copying data from the old ones to the new ones)
3) Partition sdb and sdc to the following:

Disk /dev/sdb: 36.4 GB, 36420075008 bytes
255 heads, 63 sectors/track, 4427 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 8 64228+ fd Linux raid autodetect
/dev/sdb2 9 73 522112+ 82 Linux swap / Solaris
/dev/sdb3 74 4427 34973505 fd Linux raid autodetect

4) # mkswap /dev/sdb2
# mkswap /dev/sdc2

5) You may need to create md devices first before this creating the arrays with this next step, depending on how old your version of mdadm is, but in later versions it automatically creates them for you. If you do need to, mknod /dev/md0 b 9 1; mknod /dev/md1 b 9 2

# mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
# mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb3 /dev/sdc3

6) The name rootvg is already in use by my original root VG, so I named the new one rootvg2. The name can be changed later, so it doesn't really matter what you call it.
# vgcreate rootvg2 /dev/md1

7) # lvcreate -L 1GB -n root_lv rootvg2
# lvcreate -L 1GB -n tmp_lv rootvg2
# lvcreate -L 2GB -n var_lv rootvg2
# lvcreate -L 10GB -n usr_lv rootvg2
# lvcreate -L 11GB -n games_lv rootvg2
# lvcreate -l 2138 -n foo_lv rootvg2 # <<-- notice 2138 is the total remaining extents in the VG

8) # mkfs.ext3 /dev/rootvg2/root_lv
# mkfs.ext3 /dev/rootvg2/tmp_lv
# mkfs.ext3 /dev/rootvg2/var_lv
# mkfs.ext3 /dev/rootvg2/usr_lv
# mkfs.ext3 /dev/rootvg2/games_lv
# mkfs.ext3 /dev/rootvg2/foo_lv

9) Mount the new file systems and copy over the current rootvg's data to the new FSs
# mount /dev/rootvg2/root_lv /mnt
# mount /dev/md0 /mnt/boot
# mount /dev/rootvg2/usr_lv /mnt/usr
# mount /dev/rootvg2/var_lv /mnt/var
# mount /dev/rootvg2/tmp_lv /mnt/tmp
# mount /dev/rootvg2/games_lv /mnt/usr/games
# mount /dev/rootvg2/foo_lv /mnt/foo
# cd /
# tar -clvf - . |(cd /mnt; tar -xf -)
# mount /boot
# cd /boot
# tar -clvf - . |(cd /mnt/boot; tar -xf -)
# cd /usr
# tar -clvf - . |(cd /mnt/usr; tar -xf -)
# cd /var ... (etc.)

10) Because udev won't be active on your new root when you boot, you actually need to populate the new root's /dev directory with some rudimentary devices.
# cd /mnt/dev
# MAKEDEV std consoleonly fd md hda hdb hdc hdd sda sdb sdc sdd

11) If you don't already have one, you need to create an initrd image to boot with that will load both md and LVM2 devices. Either genkernel or lvm2create_initrd should work. I used the "Make your initrd" procedure from the HOWTO Install Gentoo on an LVM2 root partition wiki. Once you've created the images, of course you need to create the new entry in your new /boot's grub.conf. I used the genkernel method, and mine looked like this:

title LVM2 Linux vmlinuz-2.6.16-gentoo-r7deuteronomy
root (hd0,0)
kernel /vmlinuz-2.6.16-gentoo-r7deuteronomy udev dodmraid dolvm2 root=/dev/ram0 init=/linuxrc lvmraid=/dev/md1 real_root=/dev/rootvg2/root_lv ramdisk=8192
initrd /initramfs-genkernel-x86-2.6.16-gentoo-r7genesis

12) Update your /etc/fstab in the new root (/mnt/etc/fstab) to reflect the new device names. Mine looks like this:

/dev/md0 /boot ext3 noauto 1 2
/dev/rootvg2/root_lv / ext3 rw,user_xattr 0 1
/dev/sda2 none swap sw 0 0
/dev/sdb2 none swap sw 0 0
/dev/rootvg2/tmp_lv /tmp ext3 rw,nosuid,user_xattr 0 1
/dev/rootvg2/var_lv /var ext3 rw,suid,user_xattr 0 1
/dev/rootvg2/usr_lv /usr ext3 rw,user_xattr 0 1
/dev/rootvg2/games_lv /usr/games ext3 rw,nosuid,user_xattr 0 1

13) Save your new RAID configuration to /mnt/etc/mdadm.conf. Be sure to anticipate the change in device names (i.e. the current /dev/sdb will be the new /dev/sda, and the current /dev/sdc will be /dev/sdb after our next reboot).
# echo "DEVICE /dev/sda1 /dev/sda3 /dev/sdb1 /dev/sdb3" >> /mnt/etc/mdadm.conf
# mdadm --detail --scan >> /mnt/etc/mdadm.conf

10) Install the new MBRs on your new mirrored root disks (using GRUB)
# device (hd0) /dev/sdb
# root (hd0,0)
# setup (hd0)
# device (hd0) /dev/sdc
# root (hd0,0)
# setup (hd0)

11) Shutdown to power off
12) Reassign SCSI IDs so your two new root disks are the first two (0 and 1, or 0 and 2... whatever you like), and put the old root disk as the last ID.
13) Boot

I think I included all the steps I used here. Sorry if I left anything out!

No comments:

Blog Archive