3 ms·
Thanks, Colin. 1) MDADM requires specific parameters in order to mount physical drives into a virtual RAID drive. 2) Meaning, piping outputs doesn't work, sinc
by marknadal 14y ago
Thanks, Colin.
1) MDADM requires specific parameters in order to mount physical drives into a virtual RAID drive.
2) Meaning, piping outputs doesn't work, since the text that is output does not equal the parameters needed.
3) First, the script has to automatically determine which drives should be used. This is done by calling lsblk -l (easier to parse than fdisk) and looking for non-mounted partitions. It outputs:
NAME MAJ:MIN RM SIZE RO MOUNTPOINT
sr0 11:0 1 49.8M 0 /media/VBOXADDITIONS_4.1.18_78361
sda 8:0 0 8G 0
sda1 8:1 0 7.5G 0 /
sda2 8:2 0 1K 0
sda5 8:5 0 510M 0 [SWAP]
4) MDADM's command parameter is the following:
sudo mdadm --create --verbose /dev/md0 --level=10 --chunk=256 --raid-devices=$RNUM $DRIVES
Where $RNUM is an integer corresponding to the number of drives, and $DRIVES is a space-separated list of the paths to the unmounted drives (which should probably further be filtered on size, since one of them is only 1K but let's ignore its size for now). We also have to remember to prefix '/dev/' since that is where the drives are mounted onto. So explicitly:
DRIVES=/dev/sda /dev/sda2
RNUM=2
Which then makes:
5) sudo mdadm --create --verbose /dev/md0 --level=10 --chunk=256 --raid-devices=2 /dev/sda /dev/sda2
Notes:
a) I've been able to accomplish this using node, since in JS I can just do things like string.split(" ") and get an array which I can loop through, or split on newlines, or whatever. But I don't know how this is accomplished in bash scripting.
Thanks for helping out somebody very unintelligent with respect to CLI, despite the last year and a half being fully involved, and trying to google the help out of every issue and tutorials. I hope some day I'll be good enough to help teach people as well.