Table of Contents |
---|
RAID 1
Create a RAID 1 system of 2 disks and 2 partitions
In the following examples we are going to use sdb and sdc for the disc to use in the RAID. Adapt it to your situation.
Create the partitions
Code Block |
---|
fdisk /dev/sdb |
- p check the partition table
- n create partition (ex +128M)
- t filesystem
- a bootflag
- w write
Set the RAID1 system on the 2 partitions
...
Introduction
md is a Linux kernel facility with user space supporting tools and files.
md was originally "mirror disk". It was renamed "multiple devices" when functionality was extended to more than mirrored disks. Functionality now includes non-mirrored RAID and multipathing.
md assembles multiple devices into a single virtual devive.
The multiple devices are variously called "underlying devices" and "RAID devices" in the documentation. On this WIKI page they are always "underlying devices".
At the time of writing, Blue Light has:
- Only used the Linux kernel facility md to create RAID 1 devices.
- Has preferred the traditional /dev/md[[:digit:]]* device file names.
TODO: better we move with the times and start using /dev/md/* device names as the installer does?
RAID 1
Creation
Create the block devices to be used as underlying devices. Typically these are HDD partitions but any block devices can be used. In the following example, /dev/sdb1 /dev/sdc1 are used.
Code Block |
---|
mdadm --create /dev/md1md0 --level=1 --raid-devices=2 /dev/sdb2sdb1 /dev/sdc2 |
Check the RAID-DEVICES
Code Block |
---|
cat /proc/mdstat |
Make the file system
Code Block |
---|
mkfs.ext3 /dev/md0
mkfs.ext4 /dev/md1 |
Mount the disks
Code Block |
---|
mkdir /mnt/md0
mkdir /mnt/md1
mount /dev/md0 /mnt/md0/
mount /dev/md1 /mnt/md1/ |
Copy the data of Home
Code Block |
---|
cd /home
tar c * | tar x -C /mnt/md1 |
Find the UUID of the 1st partition
Code Block |
---|
blkid
/dev/md1: UUID="3968404e-6571-4671-a157-9113a9f2fcba" TYPE="ext4" |
Make md1 be the home directory
Code Block |
---|
emacs /etc/fstab
# /home was on /dev/sda9 during installation
UUID=3968404e-6571-4671-a157-9113a9f2fcba /home ext3 defaults 0 2 |
Add new Hard drive
Connect the new hard disk and boot a system.
This will create on the new drive a partition table identical to the one of the existing working drive (this will also copy GRUB).
...
sdc1
|
The md device may now be used like any other block device except when:
- Used for /boot The section "Booting from an md device" below applies.
- Used as an LVM PV The section "LVM PVs on md devices" below applies.
Replacing an underlying device
Typically this is done when an HDD has failed.
In case the replacement HDD is the same size and has the same partitions as a working HDD, the partitions can be created and GRUB installed in a single command. Assuming sda is the working HDD and sdb the replacement:
Code Block |
---|
dd if=/dev/sda of=mbr.bin bs=512 count=1 dd if=mbr.bin of=/dev/sdb bs=512 count=1 |
Check the status of the RAID devices to see the device numbers
Code Block |
---|
cat /proc/mdstat |
Add the appropriate partition of the new drive to the RAID devices, repeat for each RAID device.In other cases the block device for the new underlying device must be created as appropriate.
Regardless of how the underlying device was created, it can now be added to the md device. Assuming the underlying device is sdb1 and the md device is md0:
Code Block |
---|
mdadm --manage --add /dev/md0 /dev/sdb1 |
Remove an md device
Removing /dev/md1 as an example ...
...
Finally remove the device:
mdadm --remove /dev/md1
Common to all RAID
...
Booting from an md device
TODO: confirm and clarify this section.
Assuming a RAID 1 md device is being used for /boot, the only mechanism available before GRUB2 was for the boot loader to load initrd (or the kernel directly) from one of the underlying block devices in the normal way and then assemble the /boot md.
GRUB2 can be configured to include md support so can assemble the /boot md before loading initrd (or the kernel directly).
Start all md devices
Some linux system integrated an mdadm tool called mdadm-startall. You can install it if not already done.
It doesn't require any argument and will assemble all the md drives devices found.
Code Block |
---|
mdadm-startall |
Troubleshooting
initrd fails to assemble md devices
When initrd is responsible for assembling the md devices, it needs to be rebuilt when the md devices (not their underlying devices) change, for example when an md is removed and a new one created with the same name.
If this has not been done and the md devices were required to boot, a busybox prompt is presented. mdadm --assemble --scan
was not effective. The md device had to be created by running mdadm --assemble /dev/md1 /dev/sda2 /dev/sdb2
When the system has been booted, the damage can be fixed by:
- Updating /etc/mdadm/mdadm.conf to include current md UUIDs (updated lines can be generated by running
mdadm --detail --scan
). - Updating the current initrd by running
update-initramfs -u
LVM PVs on missing md devices
After fixing the missing md devices as above, the VGs and LVs can be enabled by running the busybox command lvm
and then using its help to find the commands to do so (cut down versions of the GNU Linux equivalents).
References
- Overview: md man page
- mdadm man page
- mdadm.conf man page