You should make backups of stuff before trying this

My computer had a single 750GB SATAII hard drive in it, with a variety of LVM partitions (/, /home) and non-LVM ones (/boot, swap, some other random ones). I wanted to consolidate slightly, and set up a RAID in case a drive died... (I do have backups of important stuff, but the downtime would be a pain) I also wanted to avoid reinstalling - while it is easy (using Jaunty), I didn't have a 64-bit jaunty cd (only 32-bit ones).

There are some things you could do here that should make stuff easier, but I didn't.

  • Boot into a LiveCD. I used the 32-bit desktop cd from shipit.
  • Install mdadm and lvm2
  • Set up a partition, type 0xfd, covering all of one, blank drive

Now we need to create our md array

#mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdXN missing

where X and N identify the partition you created - for me /dev/sdb1 . Next, create an LVM array, so

#pvcreate /dev/md0
#vgcreate raid /dev/md0

We have now allocated all of the space on the partition to LVM. Now, create a few lv's:

#lvcreate -L300M -nboot raid
#lvcreate -L20G -njaunty raid
#lvcreate -L30G -nhome raid
#lvcreate -L4G -nswap raid

Adjust sizes as necessary. I have a separate boot partition, though I'm not sure this is necessary with this setup. Now create filesystems

#mkfs.ext4 /dev/mapper/raid-boot
#mkfs.ext4 /dev/mapper/raid-home
#mkfs.ext4 /dev/mapper/raid-jaunty
#mkswap /dev/mapper/raid-swap

Obviously, you can use a different fs if you like. Then, we copy across the data from our old system.

#mount /dev/mapper/raid-boot /mnt/boot-new
#mount /dev/sdXN /mnt/boot-old
#cd /mnt/boot-new
#cp -a ../boot-old/* .

Those directories will probably have to be created first. Use X,N as appropriate. Repeat for the root partiton, and home, etc. If you don't have a separate boot partition, don't worry about the boot one (I think you shouldn't need it.)

Now comes the bit that didn't work -- I was using a 32-bit cd, so couldn't chroot into the new system. So reboot back into the old system. Then,

#mdadm --assemble /dev/md0 /dev/sdb1
#mount /dev/mapper/raid-jaunty /mnt/jaunty
#cd /mnt/jaunty    
#mount /dev/mapper/raid-boot boot
#mount -o bind /dev/ dev
#mount -t proc none proc
#mount -t sysfs none sys
#mount -t tmpfs none tmp
#chroot .
#echo md >> /etc/modules
#echo lvm >> /etc/modules
#echo raid1 >> /etc/modules
#update-initramfs -k all -u
#apt-get install grub2

grub2 is needed as we're booting off lvm and raid

#update-grub2
#grub-install /dev/md0 --recheck

This would have been easier if we'd put the md, lvm and raid1 in /etc/modules before copying the os, and run update-initramfs then. I would advise doing that in the future. If you don't do it, then you can't boot, as it can't find /. Also, while you're there, update /etc/fstab on the new system to point to the right places. It's easiest to use UUIDs to identify things, as then you don't have to worry about paths.

Now reboot back into the new system, which should start fine. I haven't added the other drive to the array yet, will update when I've done that.

Once all of the data have been copied across, you can wipe the partition table on the first drive. Make sure you have all of the data copied, and backed up, as this will delete everything on your first drive.

Create a new partion exactly as large (or larger than) the raid partition you made already. Set its type to 0xfd again. Now we add the other drive into our array:

#mdadm --manage --add /dev/md0 /dev/sda1

Done. You can monitor the copying with

cat /proc/mdstat

Some sites I found helpful in doing this:

Here is a fairly general copyable-code.

export VGNAME=dionysus
mount /dev/mapper/$VGNAME-root /mnt/sys
cd /mnt/sys
mount -o bind /dev/ dev
mount -t proc none proc
mount -t sysfs none sys
mount -t tmpfs none tmp
chroot .
echo md >> /etc/modules
echo lvm >> /etc/modules
echo raid5 >> /etc/modules
apt-get install lvm2 mdadm
update-initramfs -k all -u
update-grub
grub-install /dev/sda

Edit as appropriate

Comment by Walter Wed Nov 30 06:21:35 2011
Comments on this page are closed.