Installing new disks and preparing to use in Linux Software RAID

A Linux Software RAID (using mdadm) creates a new virtual media on top of which we create partitions  and format partitions (ext3/4, FAT32 etc…).    Here we describe how to initialize the underlying disk(s) to be ready for inclusion / addition to a software RAID.   Repeat the instructions for each (new) disk.  The commands here are based on Ubuntu Linux but should apply to all Linux systems.

In a Linux Software RAID (mdadm), each partition/disk  must be initialized to type “Linux raid autodetect“.      In most cases,  each disk in a RAID system will have a single partition.   In a software RAID, the underlying elements are partitions so it is possible to have multiple RAIDs spanning the same disks (each using a different partition on each disk.   It is questionable whether using more than one partition per RAID disk would result in degraded performance.   In this post, we assume that you will use a single partition per disk/raid device.

After installing the new disk(s) in your computer, follow these steps for each disk:

  1. cat /proc/mdstat to identify what disks (/dev/sdb /dev/sdc /dev/sdd ….) are part of the existing RAID (we don’t want to reformat one of those by accident!)
  2. fdisk -l to identify the new disk   (Let us assume /dev/sdb)
  3. mount | grep sdb to see if the disk is not mounted
  4. unmount /dev/sdb1 if needed to make sure the partitions are NOT mounted.
  5. fdisk /dev/sdb NOTE:  /dev/sdb,  not /dev/sdb1 –  the new disk device
  6. Within fdisk, follow those steps:
    1. press “p” to list partitions on that disk
    2. press “d”  to delete any existing partitions
    3. “n” to create a new partition
      • choose “p” for primary partition
      • choose 1 for partition number
      • use the whole disk for this partition
    4. press “t” to change the partition’s system ID
    5. press “L” to see available list.
    6. enter “fd” (no 0xfd, just fd) to select Linux raid autodetect
    7. press “p” to check that your change took.
    8. press “w” to write the changes and exit fdisk.

Reusing a disk from another array:

If you are reusing a disk from another mdadm RAID array, you must first zero out the superblock:

cat  /proc/mdadm        (see if a RAID array is running / active)
mdadm --stop /dev/md0   (if an array is active, stop it)
mdadm --zero-superblock /dev/sdd1

Copy a disk partition to a new disk:

If you are adding a new disk to an existing raid or preparing a new raid, you want all the partitions to be identical.    You can copy the partition from one disk to another:

sfdisk -d /dev/sdc >  /tmp/partition.txt
sfdisk  /dev/sdb   <  /tmp/partition.txt

OR in a single step:

 sfdisk -d /dev/sdc  | sfdisk  /dev/sdb

Since the new disk/partition will be used in a software raid, you DO NOT need to format it with a file system.   Your new disk is now ready for inclusion in a Software RAID.


About admin

My name is Christian Marcotte. I live in San Diego with my wife Carolyn and our son Jeremiah. This site is a recording of my currrent ponderings, hobbies and interest.
This entry was posted in Linux, NAS, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *