annotate content/Linux/software-raid-setup.md @ 112:cf31bf5fce72 default tip

Author of the blog post as mail header for efficient spam filtering
author Dirk Olmes <dirk.olmes@codedo.de>
date Tue, 06 Sep 2022 07:04:11 +0200
parents 1d9382b0329b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 Title: Setting up a software RAID1
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 Date: 2017-07-12
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 Lang: en
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 Tags: Gentoo
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 I'm helping a friend to set up a machine with [Gentoo](http://www.gentoo.org). This will be a machine to host production applications and it is equipped with 2 identical hard drives. I will set up a [software RAID 1](https://raid.wiki.kernel.org). This has been a life saver on a similar machine before where one of the drives failed and we had no data loss and only minimal downtime during which the drive was replaced.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 One goal of the new setup is to remain bootable even if one of the drives fails. I had trouble accomplishing this in earlier setups so this time I tested the process locally on a virtual machine before setting up the real iron.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9
87
abc2401e9958 Typo fix
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 85
diff changeset
10 The first step of the setup is partitioning the drives. The [handbook](https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks) suggests adding a small partition at the beginning of the drive to enable booting from a gpt partitioned drive. The `/boot` partition will be formatted using [ext4](https://en.wikipedia.org/wiki/Ext4) because the filesystem will remain bootable even if one of the drives is missing. The rest of the disk will be formatted using [xfs](https://en.wikipedia.org/wiki/XFS). To recap the layout:
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
12 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 Number Start End Size File system Name Flags
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 1 1.00MiB 3.00MiB 2.00MiB grub bios_grub
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 2 3.00MiB 95.0MiB 92.0MiB boot
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 3 95.0MiB 8191MiB 8096MiB rootfs raid
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 The second drive is partitioned exactly the same.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 Now let's create a RAID 1 for the boot partition:
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
22 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb2 /dev/sdc2
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 and for the rootfs:
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
27 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdb3 /dev/sdc3
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 To maintain the RAID device numbering even after reboot, the RAID config has to be saved. This will be done by
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
31
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
32 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
33 mdadm --detail --scan >> /etc/mdadm.conf
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
34
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
35 Then create an ext4 filesystem on `/dev/md0` and an xfs filesystem on `/dev/md1`. Nothing noteworthy here.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
36
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
37 The observant reader will have noticed from the device names above that I'm testing my installation from a running system on `/dev/sda`. To save the hassle of going through the entire stage3 setup process I'm simply copying the running system to the newly created RAID filesystems.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
38
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
39 After chrooting into the new system some changes have to be made to the [genkernel](https://wiki.gentoo.org/wiki/Genkernel) config in order to produce a RAID enabled initramfs. In `/etc/genkernel.conf` set
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
40
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
41 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
42 MDADM="yes"
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
43 MDADM_CONFIG="/etc/mdadm.conf"
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
44
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
45 Now we're set to build the kernel.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
46
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
47 While it's compiling, edit `/etc/default/grub` (I'm of course using [grub2](https://www.gnu.org/software/grub/manual/grub.html) for booting) and add
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
48
98
1d9382b0329b Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents: 87
diff changeset
49 :::shell
85
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
50 GRUB_CMDLINE_LINUX="domdadm"
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
51
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
52 Setup grub on both devices individually using `grub-install /dev/sdb` and `grub-install /dev/sdc`.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
53
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
54 After the kernel has finished compiling, generate the proper grub config using `grub-mkconfig -o /boot/grub/grub.cfg`.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
55
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
56 Before rebooting the `fstab` has to be set up correctly. I prefer to use UUIDs for filesystems instead of device names - this is a bit more fault tolerant in case device numbering is mixed up. It was a main challenge to find an unambiguous UUID for the both RAID filesystems. There are a number of places to get a UUID from: `mdadm --detail`, `blkid`, `tune2fs -l`, `xfs_admin -u` and I'm sure I forgot more. The helpful guys at the [gentoo IRC channel](https://www.gentoo.org/get-involved/irc-channels/) pointed me in the right direction. Use `lsblk -f /dev/md0` to find a UUID that uniquely identifies the RAID and check using `findfs UUID=<uuid>`.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
57
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
58 After updating the `fstab` the system is ready for a first boot into the RAID setup.
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
59
2444e4533089 add the RAID setup article
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
60 I tested failing drives by simply removing the first (or the second) drive from the virtual machine. The whole setup still boots off either drive.