Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| engineering:computer_science:linux:linux_mdadm_software_raid [2024/08/16 13:56] – removed - external edit (Unknown date) 127.0.0.1 | engineering:computer_science:linux:linux_mdadm_software_raid [2024/08/16 13:56] (current) – ↷ Links adapted because of a move operation carlossousa | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Using mdadm to create a Software RAID in Linux ====== | ||
| + | |||
| + | Part of [[engineering: | ||
| + | |||
| + | ===== Installation ===== | ||
| + | |||
| + | In Debian: | ||
| + | < | ||
| + | |||
| + | sudo apt get install mdadm | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== ===== | ||
| + | |||
| + | ===== Partition Disks for mdadm usage ===== | ||
| + | |||
| + | You can use: | ||
| + | |||
| + | < | ||
| + | sudo mdadm -E / | ||
| + | |||
| + | </ | ||
| + | |||
| + | 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 / | ||
| + | |||
| + | </ | ||
| + | |||
| + | ^Value^Description| | ||
| + | |–create|Create a new RAID| | ||
| + | |/ | ||
| + | |–level=mirror|Raid as Mirror| | ||
| + | |–raid-devices=2|Use 2 devices| | ||
| + | |/ | ||
| + | |||
| + | ===== 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: | ||
| + | |||
| + | < | ||
| + | / | ||
| + | |||
| + | </ | ||
| + | |||
| + | To make sure that the array is reassembled automatically at boot, adjust your / | ||
| + | |||
| + | < | ||
| + | sudo mdadm --detail --scan | sudo tee -a / | ||
| + | |||
| + | </ | ||
| + | |||
| + | Uncomment - if necessary - your array on / | ||
| + | < | ||
| + | |||
| + | sudo nano / | ||
| + | |||
| + | </ | ||
| + | |||
| + | 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 / | ||
| + | |||
| + | </ | ||
| + | |||
| + | < | ||
| + | sudo mdadm --detail /dev/md0 | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||