computer_science:linux:linux_mdadm_software_raid

Using mdadm to create a Software RAID in Linux

Part of Linux

In Debian:

sudo apt get install mdadm

You can use:

sudo mdadm -E /dev/sd[b-c]

to check if the devices are part of a RAID / super-block is found.

sudo fdisk /dev/sdX

To create the partition, input the following values in order. Each Input should be followed by a confirmation (ENTER)

ValueDescription
nNew primary Partition
PDefine as Primary Partition
1Partition Number
(ENTER)Confirm Default Starting Block
(ENTER)Confirm Default End Block
tChoose partitions type
fdPartition type: Linux Raid auto
wWrite Changes

Useful Options for fdisk

ValueDescription
dDelete selected partition
pPrint partitions information
LList available types of partitions

Don't forget to repeat the steps for all disks you using on the RAID.

sudo mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
ValueDescription
–createCreate a new RAID
/dev/md0Using /dev/md0
–level=mirrorRaid as Mirror
–raid-devices=2Use 2 devices
/dev/sd[b-c]1The devices sdb1 and sdc1

Use mkfs to create a ext4 File System with:

sudo mkfs.ext4 /dev/md0

Edit your fstab to auto-mount your RAID on boot:

sudo nano /etc/fstab

Eg:

/dev/md0  /mnt/md0  ext4  defaults,nofail 0 0

To make sure that the array is reassembled automatically at boot, adjust your /etc/mdadm/mdadm.conf:

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

Uncomment - if necessary - your array on /etc/mdadm/mdadm.conf by removing the Starting “#”:

sudo nano /etc/mdadm/mdadm.conf

Update the initramfs again so that the early boot process does not try to bring an unavailable array online:

sudo update-initramfs -u

You can use the following commands to check the status of your RAID:

sudo mdadm -E /dev/sd[b-c]1
sudo mdadm --detail /dev/md0
  • computer_science/linux/linux_mdadm_software_raid.txt
  • Last modified: 2023/12/01 12:07
  • by 127.0.0.1