Return to Level1Techs.com

How to RAID your Linux OS disks during installation

linux
guide
raid
#1

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.

  1. Disk setup
  2. 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.

Disk setup

Partitioning

Select “Manual”.

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.

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.

Testing

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.

Rebuilding

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.

6 Likes

#2

Great post, mate.

0 Likes

#3

Nice write up.

Don’t forget that in the event of adding a replacement drive…

you would need to partition it to get sdx1
and then install the boot loader on to the new drive.

2 Likes

#4

It’s a shame more installers don;t have it as an option… Unless they do?

0 Likes

#5

This may no longer be an issue, but in the past, the boot partition couldn’t be on md v1.2. I believe this is still the case for CentOS 7 (possibly attributable to ancient kernel).

Additionally, in my experience, grub needs to be manually installed on all mirror members.

0 Likes

#6

Does the installer for Debian install the bootloader+grub+raid drivers/config onto each drive?

0 Likes

#7

IIRC

The initramfs image has the md and lvm modules in it. Grub is just on both drives with enough stuff to get it going.

0 Likes

#8

so each drive needs a copy of GRUB, the intamfs and this needs to be in a format that the bios can read and load from? like fat/exfat/fat32 or something?
And I presume it would just be a carbon copy on each member disc?

0 Likes