sainthilarious.dev

Brian's personal website

Installing Gentoo Linux with RAID Arrays

This week I had the pleasure of reinstalling Gentoo Linux on Dvorak, my trusty desktop server PC since 2021. The reason for the reinstall is that I had gotten too busy working for clients in recent months or even years, and had regrettably neglected the maintenance of my own systems. It had gotten so bad, that a simple reinstall became much more feasible than a gigantic emerge update, especially with the new Python and Portage versions that have come along since the last time… Besides, I wanted to hone my skills in the Gentoo install process, and I also noticed that there were numerous new changes to the Gentoo handbook…

One particular challenge that I faced is the fact that my hardware consists of RAID arrays. 2 mirrored SSDs of ca. 220 GB each, and 2 mirrored HDDs of 1 TB each. This required some special consideration, which I outline below. I hope that someone else finds this helpful, and this might also save me some trouble the next time I have to do this.

Most sysadmins installing Gentoo will follow along with the Gentoo handbook: https://wiki.gentoo.org/wiki/Handbook:Main_Page

Those who are installing on a RAID array will also want to have the “Tips and Tricks Page” open: https://wiki.gentoo.org/wiki/Gentoo_installation_tips_and_tricks

Those pages outline in detail what needs to be done, but to summarize:

Preparing the disks:

In the live boot environment, load the kernel module for RAID: modprobe raid1

When partitioning the disks, make sure to set the partition type to Linux RAID (or something like that). With fdisk you can change the partition type of a selected partition with the t command.

Create the metadevice nodes with the mknod command. Something like:

  • mknod /dev/md1 b 9 1
  • mknod /dev/md2 b 9 2

Use mdadm to create /etc/mdadm.conf:

  • mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 --metadata=0.90 /dev/sda1 /dev/sdb1
  • mdadm --create --verbose /dev/md2 --level=1 --raid-devices=2 --metadata=0.90 /dev/sda2 /dev/sdb2
  • Wait until the metadevices are created. Monitor the file /proc/mdstat (tail -f won’t work, do something like watch cat /proc/mdstat instead.)
  • Once it’s done, dump the configuration to /etc/mdadm.conf: mdadm --detail --scan > /etc/mdadm.conf

From now on, every time the handbook says something like /dev/sda1, you actually need /dev/md1

Before chrooting, make sure to copy /etc/mdadm.conf into /mnt/gentoo/etc/

Kernel configuration

The astute sysadmin, who has the Gentoo handbook and the “Tips and Tricks Page” open, will now want to also open another page containing additional documentation for RAID arrays: https://wiki.gentoo.org/wiki/User:SwifT/Complete_Handbook/Software_RAID

The Gentoo handbook outlines several options for configuring and building the kernel. I have found that I need to use genkernel for this step.

To make the RAID arrays work, I had to give the genkernel command a few additional parameters. Here is the full command that worked for me: genkernel --menuconfig --busybox --mdadm --all-ramdisk-modules --dmraid --mountboot --install all (Depending on how many CPUs you have to compile with, you might also want to pass in something like for example --makeopts=-j28)

Now a text based menu will open, in which you configure the kernel. You need to compile the RAID support directly into the kernel, and not as a module. The needed configuration is found under Device Drivers -> Multiple devices driver support -> RAID support. See https://wiki.gentoo.org/wiki/User:SwifT/Complete_Handbook/Software_RAID for the exact configuration.

Exit out of genkernel’s configuration menu, and enjoy watching the Linux kernel compile.

Setting up /etc/fstab

Finally, you just need to find out the UUIDs of the metadevice nodes, and add those to your /etc/fstab

So do something like this: lsblk -f

That will print information about your block devices, along with the required UUIDs. You can write the output to a temporary file, and then, when editing /etc/fstab with vim, you can yank the required values into the file. It’s important that you use the UUIDs of the metadevice nodes, and not the underlying disks.

And that is basically it. The full Gentoo installation process is superbly documented in the handbook, and if you need to install it on a RAID array, you just need to observe these few additional steps outlined here.

Leave a Reply

Your email address will not be published. Required fields are marked *