2013/09/25

Hot Swap (remove and add) a RAID 1 disk in Ubuntu 13.04

Edit 2015-0630: Do not use the below as a backup solution. A better solution I now use is rsync to mirror my raid array to an external LUKS encrypted hard drive.  
This article shows you how to remove a disk from a RAID 1 array in Ubuntu 13.04 and add a new disk to the Array. This is known as hot swapping when you replace the drive without shutting the computer down.

I have a home server that I back up all my data to from all my different devices and computers. This data is on an encrypted LUKS filesytem with software RAID 1 array. A RAID 1 Array requires a minimum of 2 disks and the disks are mirrored so that if one disk fails, you still have your data on a second disk. I also like to keep a third disk off site and rotate it into the RAID 1 Array. The off site backup protects my data in case my computer is ever stolen or destroyed in a fire. This is easiest if you have a hot swap hard drive bay in your computer.

Requirements for this to work.
  Linux Operating System
  Mdadm software installed (RAID software)

All of the following commands are in the terminal.
  You will have to replace 'md1' and 'sdd' with your own values from your machine.

  • Identify disk to remove from Array
    • sudo fdisk -l
  • Fail disk from the Array
    • sudo mdadm /dev/md1 -v --fail /dev/sdd
  • Remove disk from the Array
    • sudo mdadm /dev/md1 -v --remove /dev/sdd
  • Check disk is removed from the Array
    • sudo mdadm --detail /dev/md1
  • Physically remove disk from the machine
  • Insert new disk into machine
  • Check that new disk is seen by machine
    • sudo fdisk -l
  • Add disk to the Array, different method for new disk with no partitions versus readding a disk back to the Array
    • New hard drive with no partitions
      • sudo mdadm /dev/md1 -v --add /dev/sdd
    • Disk that has been part of the Raid Array before
      • sudo mdadm /dev/md1 -v --re-add /dev/sdd
  • Monitor status of Raid rebuild
    • sudo mdadm /dev/md1 --detail
It takes many hours to synchronize new large hard drives.

I use dm-crypt software for disk encryption.