User Tools

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mdadm [2022/09/30 04:31] – created normanmdadm [2025/06/20 11:25] (current) – [“not enough to start the array” – error while staring mdadm RAID array] norman
Line 1: Line 1:
 ====== Mdadm Helpers ====== ====== Mdadm Helpers ======
 +
 +*************
 +
 +===== Debian Disable/Enable Raid Monthly Checks =====
 +
 +<code>dpkg-reconfigure mdadm</code>
 +
 +or edit cron job
 +
 +<code>nano /etc/cron.d/mdadm</code>
 +
 +[[https://askubuntu.com/questions/1304738/mdadm-checking-raid-5-array-after-each-restart|External Link]]
 +
 +
  
 ===== How do I replace a disk marked as removed from a linux md raid-5 array ===== ===== How do I replace a disk marked as removed from a linux md raid-5 array =====
 +
 +== If drives are "hot swap", don't need to power off server/pc...  ==
 +
  
 First identify removed drive: First identify removed drive:
  <code>lsblk</code>  <code>lsblk</code>
 +Find serial number, if necessary:
 +<code>smartctl -a /dev/sdb | grep Serial</code>
  
-the, if drive is **just remved**:+If drive is **just remved**:
 <code>mdadm --zero-superblock /dev/sdXn <code>mdadm --zero-superblock /dev/sdXn
 mdadm /dev/md0 --add /dev/sdXn</code> mdadm /dev/md0 --add /dev/sdXn</code>
Line 12: Line 31:
  If **replacing damaged** drive, then only:  If **replacing damaged** drive, then only:
 <code>mdadm /dev/md0 --add /dev/sdXn</code> <code>mdadm /dev/md0 --add /dev/sdXn</code>
 +=== Check every drive manually ===
 +
 +<code>mdadm --examine /dev/sdX</code>
 +
 +====== “not enough to start the array” – error while staring mdadm RAID array ======
 +
 +Stop failed array:
 +<code>mdadm -S /dev/md0</code>
 +
 + Assemble the pre-existing array:
 +<code>mdadm -A -f /dev/md0</code>
 +
 +
 +RUN raid 1 with one disk:
 +<code>
 +mdadm --run /dev/md126
 +</code>
 +
 +Then Add disk:
 +<code>
 +mdadm --manage /dev/md126 --add /dev/sdf4
 +</code>
 +
 +====== Test Email Settings ======
 +
 +<code>mdadm --monitor --scan --test</code>
 +
 +If got error: **"mdadm: Only one autorebuild process allowed in scan mode, aborting"**
 +<code>mdadm --monitor /dev/md0 --test</code>
 +
 +
 +
 +====== Simple Script to read Hdd serial numbers ======
 +
 +<code>#!/bin/bash
 +smartctl -a /dev/sda | grep -i 'Serial';
 +echo "";
 +echo "";
 +
 +for i in {a..z} ; do
 +echo $i
 +smartctl -a /dev/sd$i | grep -i 'Serial';
 +done
 +</code>
 +
 +====== A SparesMissing event had been detected on md device ======
 +
 +Removing the spares=1 option or just recreating the mdadm.conf from scratch fixes the problem:
 +
 +====== **Update MDADM config file** ======
 +
 +
 +<code>/usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.copy</code>
 +
 +Double check new configuration ad then save as mdadm.conf
 +
 +====== **Just in case** ======
 +
 +Run <code>update-initramfs -u</code>
 +====== Speed Up or Slow Down Raid rebuild ======
 +
 +To see current limits, enter:
 +
 +<code>sysctl dev.raid.speed_limit_min
 +sysctl dev.raid.speed_limit_max</code>
 +
 +
 +To change minimal speed (ex. min.= 10000), enter:
 +
 +<code>echo value > /proc/sys/dev/raid/speed_limit_min</code>
 +
 +or 
 +<code>sysctl -w dev.raid.speed_limit_min=value</code>
 +
 +To change maximal speed (ex. max.= 200000), enter:
 +
 +<code>echo value > /proc/sys/dev/raid/speed_limit_max</code>
 +
 +or 
 +<code>sysctl -w dev.raid.speed_limit_max=value</code>
 +
 +
 +If you want to override the defaults you could add these two lines to: <code>nano /etc/sysctl.conf</code>
 +
 +<code>#################NOTE ################
 +##  You are limited by CPU and memory too #
 +###########################################
 +dev.raid.speed_limit_min = 50000
 +## good for 4-5 disks based array ##
 +dev.raid.speed_limit_max = 2000000
 +## good for large 6-12 disks based array ###
 +dev.raid.speed_limit_max = 5000000</code>
 +
 +Source: [[https://www.cyberciti.biz/tips/linux-raid-increase-resync-rebuild-speed.html|External Link]]
 +
 +
 +
 +===== Speed Change Script Example =====
 +
 +
 +<code>
 +#!/bin/bash
 +clear;
 +speed=$(cat /proc/sys/dev/raid/speed_limit_max)
 +echo ""
 +echo -e "\e[92m *\e[0m Speed Was: \e[92m$speed\e[0m"
 +echo ""
 +echo -e "\e[92m *\e[0m Switching to:\e[0m"
 +tput setaf 2
 +tput bold
 +if [[ $speed == '150000' ]]; then
 +    sysctl -w dev.raid.speed_limit_max=10000 | cut -c 28- | sed  -e   's/^/                 /'
 +    sysctl -w dev.raid.speed_limit_min=1000  | cut -c 28- | sed  -e   's/^/                 /'
 +else
 +    sysctl -w dev.raid.speed_limit_max=150000 | cut -c 28- | sed  -e 's/^/                 /'
 +    sysctl -w dev.raid.speed_limit_min=10000  | cut -c 28- | sed  -e   's/^/                 /'
 +fi
  
 +tput sgr0
 +</code>