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:
- 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!)
- fdisk -l to identify the new disk (Let us assume /dev/sdb)
- mount | grep sdb to see if the disk is not mounted
- unmount /dev/sdb1 if needed to make sure the partitions are NOT mounted.
- fdisk /dev/sdb NOTE: /dev/sdb, not /dev/sdb1 – the new disk device
- Within fdisk, follow those steps:
- press “p” to list partitions on that disk
- press “d” to delete any existing partitions
- “n” to create a new partition
- choose “p” for primary partition
- choose 1 for partition number
- use the whole disk for this partition
- press “t” to change the partition’s system ID
- press “L” to see available list.
- enter “fd” (no 0xfd, just fd) to select Linux raid autodetect
- press “p” to check that your change took.
- 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.