====== Using mdadm to create a Software RAID in Linux ====== Part of [[engineering:computer_science:linux:linux|Linux]] ===== Installation ===== In Debian: sudo apt get install mdadm ===== ===== ===== Partition Disks for mdadm usage ===== You can use: sudo mdadm -E /dev/sd[b-c] to check if the devices are part of a RAID / super-block is found. ==== Drive Partitioning for RAID: ==== sudo fdisk /dev/sdX To create the partition, input the following values in order. Each Input should be followed by a confirmation (ENTER) ^Value^Description| |n|New primary Partition| |P|Define as Primary Partition| |1|Partition Number| |(ENTER)|Confirm Default Starting Block| |(ENTER)|Confirm Default End Block| |t|Choose partitions type| |fd|Partition type: Linux Raid auto| |w|Write Changes| === Useful Options for fdisk === ^Value^Description| |d|Delete selected partition| |p|Print partitions information| |L|List available types of partitions| Don't forget to repeat the steps for all disks you using on the RAID. ===== Creating a RAID 1 ===== sudo mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1 ^Value^Description| |–create|Create a new RAID| |/dev/md0|Using /dev/md0| |–level=mirror|Raid as Mirror| |–raid-devices=2|Use 2 devices| |/dev/sd[b-c]1|The devices sdb1 and sdc1| ===== Creating File System on a RAID Device ===== Use mkfs to create a ext4 File System with: sudo mkfs.ext4 /dev/md0 ===== Automount RAID on boot ===== 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 ===== Check Raid Status ===== 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