MDADM
Contents
Install
1 aptitude install mdadm
The swap problem
In a high-availability setup you don't want to loose the whole system when virtual address space is reduced by a failing swap partition (on failure of a disk).
To be prepared to this scenario you may:
- put swap to a MD-ARRAY
- use a swap file on a
- MD-ARRAY
- filesystem that is capable of swap files and multiple disks (zfs, btrfs, bachefs?)
Swap to a MD-RAID1
Assuming you have added a second and empty disk /dev/sdb to the system.
Unmount swap /dev/sda3
1 swapoff /dev/sda3
Clone gpt partitioning from one disk to another with sgdisk
Create a RAID1 multi disk array from /dev/sda3 and /dev/sdb3
1 root@rescue ~/ # mdadm -v \
2 --create md_swap1 --level=1 --symlinks yes \
3 --raid-devices=2 /dev/sda3 /dev/sdb3
4 mdadm: Note: this array has metadata at the start and
5 may not be suitable as a boot device. If you plan to
6 store '/boot' on this device please ensure that
7 your boot-loader understands md/v1.x metadata, or use
8 --metadata=0.90
9 mdadm: size set to 133890048K
10 mdadm: automatically enabling write-intent bitmap on large array
11 Continue creating array? y
12 mdadm: Defaulting to version 1.2 metadata
13 mdadm: array /dev/md/md_swap1 started.
14
15 ### DEFAULTS ARE
16 #--chunk=512K # 2^x * 4KiB
17 #--metadata=1.2
18 #--bitmap-internal
19
Format a swap-header to the RAID1 device
Update fstab to use the UUID of the new swap-device
1 blkid /dev/md/md_swap1 |sed -r 's/^/# /' >> /etc/fstab
Update initramfs
1 update-initramfs -k all -u
Repair degraded RAID5
Acquire some info
Gather some information
1 parted /dev/sdd print free
mdadm --detail --scan \ |tee -a /etc/mdadm/mdadm.conf
Actions
#TODO, SORRY BAD DOCUMENTATION
Remove failed disk from array Add new disk to array Resync disks and monitor
Grub
/usr/local/sbin/grub-mkdevicemap-full
/etc/default/grub
1 GRUB_PRELOAD_MODULES="part_gpt raid mdraid1x ext3"
mdraid1x for Metadata >= 1.0
Update initramfs
1 update-initramfs -k all -u
Install boot loader to both disks
Or as a little script /usr/local/sbin/grub-install-multi
1 #!/bin/bash
2
3 set -v
4
5 [ -d /var/log/grub ] \
6 || install -o root -g adm -d /var/log/grub
7
8 for DEVICE in $@; do
9 FILE_LOG="/var/log/grub/grub-install-${DEVICE##*/}-$(date +%F).log"
10 echo -e '\n['"$(date +%T)"'] Installing to device "'"$DEVICE"'"…'\
11 |tee -a "$FILE_LOG"
12 grub-install -v --no-floppy "$DEVICE" 2>&1 |tee -a "$FILE_LOG"
13 done
Configure grub