This guide was inspired by Wendell’s video on building the ultimate dev ops workstation.
In it Wendell says he is just going to use MD for the RAID. This lead me to ask the question, how do you RAID the OS disks of a Linux machine during the installation? I didn’t know.
In most business or enterprise scenarios you are relying on the servers RAID card (when installing onto bare metal) so by the time you get to the OS installation Linux only sees one disk (depending on your requirements).
Virtual machines are a pretty much a moot point in the same scenario as they will exist in a SAN.
But in this scenario we are talking about a workstation with no RAID card.
I have used MD before in the very limited capacity of RAID’ing a pair of old spinning HDD in my PC.
For that is was the command below which put /dev/sdc1 and /dev/sdd1 into a RAID1 array.
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sd[cd]1
And indeed I am still using them for my Timeshift backups.
But to the question at hand. Here I am going to use Debian 10. I found there are two points during the installation that you need to be aware of deviation from the normal workstation installation process.
- Disk setup
- GRUB installation
The screen shots below are taken from the relevant sections of the installation and detail the easiest way to perform this task, without LVM or any complex partitioning.
Here you can see the two blank virtual disks.
Create a new partition table on both disks.
So it looks as below.
Now partition the disks as “Physical volume for RAID” by following the screen shots below
Click into “Use as”.
Select “Physical volume for RAID”.
Repeat for the second disk until we have the view below. Now select “Configure software RAID”.
Now we have our RAID1 device select “Guided partitioning”.
In this example we are simply going to use the entire disk without LVM.
Select the RAID1 device.
And again for the easiest example we are just going to put everything in one partition.
We can now finish the disk setup and write all the changes.
Continue with the installation as normal until you reach GRUB.
Select “Enter device manually”.
Enter all the disks you want GRUB written to. This is what threw me initially as I was entering /dev/md0 expecting it to work.
We can now reboot into a working VM.
Inside the VM the disks appear as below. The mdadm command shows the RAID to be clean.
So now we shut down and remove a disk.
We can now see the disk missing inside the VM and that the state of the RAID is degraded.
Shut the VM down and re-add the existing disk.
Boot back into the VM. To rebuild the array enter the command.
sudo mdadm --manage /dev/md0 -a /dev/sda1
The progress of the rebuild can be seem with the command.
sudo mdadm -D /dev/md0
As stated this is a very simple example. You can go crazy with different RAID levels and partitions all over the place.
Credit: This video was what filled in the blanks for me with this question.