I recently had to rebuild my HP Microserver. Although it's a home system, I still like to mirror the disks to protect against disk failures. Previously I used the built in Microserver RAID. However, this made builds problematic (the RAID configured drives weren't recognised and a lot of messing about was required to get them recognised) and the RAID offered isn't true hardware RAID anyway (it's a sort of hardware/software hybrid that relies on CPU cycles so kind of negates one of the main benefits of built in RAID). I therefore decided o his occasion to use software RAID. Here's how I did it.

First off I built the server (Linux Mint distribution) using the LVM option. This creates / and swap as LVM devices but /boot is a standard partition due to the limitations of booting from LVM.

The server was built on disk /dev/sda . /dev/sdb is used as the mirror.

1. Check the existing disk layout and partition the mirror disk identically

 sfdisk -l /dev/sda
 sfdisk -d /dev/sda | sfdisk /dev/sdb
 sfdisk -l /dev/sdb

2. Check the current volume group layout and add the required partition on the mirror disk to LVM (in my case I need to add partition 5 on mirror /dev/sdb to volume group mint-vg - don't add the partition used by /boot)

 vgdisplay -v /dev/vg-mint (partitions listed at the bottom)
 pvcreate /dev/sdb5
 pvs (to check partition added OK)
 vgextend /dev/mint-vg /dev/sdb5
 vgs (to check volume group now includes mirror)

3. Now mirror the LVM partitions

 lvconvert -m 1 /dev/mint-vg/root /dev/sdb5
 lvconvert -m 1 /dev/mint-vg/swap /dev/sdb5
 lvs (to check)

4. /boot needs to mirrored via mdadm as it's not part of mdadm so install that

 apt-get install mdadm

5. Create a metadevice on the mirror partition and create a filesystem on it

 mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
 mkfs.ext2 /dev/md0 (NOTE: ext2 for /boot)

(the missing parameter allows you to create a mirror device even though one disk is missing)

6. Update /etc/mdadm/mdadm.conf with the following:

 DEVICE /dev/sda1 /dev/sdb1

7. The output from the following command

 mdadm --detail --scan >> /etc/mdadm/mdadm.conf

8. Reconfigure mdadm:

 dpkg-reconfigure mdadm

9. Install grub on both drives:

 dpkg-reconfigure grub-pc

10. Mount the newly created metadevice and copy the contents of /boot to it

 mount /dev/md/Microserver:0 /mnt
 cd /boot
 find . | cpio -dumpv /mnt

11. Update /etc/fstab changing the /boot mount point to the UUID of md0 . This can be found as follows:

  blkid /dev/md/Microserver\:0

12. Update the options in /etc/default/grub as follows:

  GRUB_HIDDEN_TIMEOUT=10
  GRUB_HIDDEN_TIMEOUT_QUIET=false
  GRUB_CMDLINE_LINUX_DEFAULT=""

13. Now reboot from md0 by interupting the boot and changing the grub options by entering e, adding:

  insmod  mdraidx
  set root='(md/0)'
  linux /boot/vmlinuz-3.13.0-37-generic root=UID=abdd4fa1-2bb3-4441-8cb3-89d43a236e29 ro

(Obviously, specify your kernel version and UUID)

14. You should now be booted from md0 . Now add the original partition to the metadevice so it forms a mirror:

  mdadm /dev/md0 -a /dev/sda1

Once mirrored, you can perform a test reboot. If you have grub issues, see out grub recovery page.

Thanks to guylabs.ch for much of the mdadm part of the procedure.

Recent Changes

Contribute to this wiki

Why not help others by sharing your knowledge? Contribute something to this wiki and join out hall of fame!
Contact us for a user name and password