Software RAID (mdadm) on Linux

OS: CentOS 5.4
mdadm — software RAID management tool

Raid device names
partitions in raid: /dev/md0, /dev/md1
disks in raid: /dev/md_d0, /dev/md_d1 and partitions /dev/md_d0p1, /dev/md_d0p2, /dev/md_d0p3, /dev/md_d0p4.

Example 1

Goal: Create RAID1 (mirroring) between two new disks and mount as /data

# create array
mdadm --create /dev/md_d0 --level=1 --raid-disks=2 /dev/hdb /dev/hdd
# check status
cat /proc/mdstat
# create partition and filesystem
fdisk /dev/md_d0
mkfs.ext3 /dev/md_d0p1
# mount
mount /dev/md_d0p1 /data
# detect array during boot
mdadm --examine --scan > /etc/mdadm.conf
# replace /dev/md0 with /dev/md_d0 in file /etc/mdadm.conf

Automount in /etc/fstab

/dev/md_d0p1   /data   ext3   defaults   0 0

Remove disk from array

mdadm --manage /dev/md_d0 --fail /dev/hdd
mdadm --manage /dev/md_d0--remove /dev/hdd

Remove raid related data

mdadm --zero-superblock /dev/hdd

Add disk again

mdadm --add /dev/md_d0 /dev/hdd

Monitor synchronization

watch cat /proc/mdstat

Example 2

Raid was between partitions on system disk. When first disk failed, system cannot boot because second disk without GRUB.

Boot from Install DVD CentOS 5.4 in boot prompt:

boot: linux rescue

Detect raid

mdadm --auto-detect
# check
cat /dev/mdstat

Mount partition

mkdir /mnt/sysimage
mount /dev/md_d0p1 /mnt/sysimage
mount -o bind /dev /mnt/sysimage/dev
mount -o bind /selinux /mnt/sysimage/selinux
mount -t proc none /mnt/sysimage/proc
mount -t sysfs none /mnt/sysimage/sys
chroot /mnt/sysimage

Install GRUB:

$ grub
grub> root (hd0,0)
  Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)

Additional information

Get raid information

# raid status
cat /proc/mdstat
# detailed raid info
mdadm --detail /dev/md_d0
# if disk is part of raid
mdadm --query /dev/hdb

Duplicate partitions

sfdisk -d /dev/sda | sfdisk --force /dev/sdb

Add disks to raid:

mdadm --add /dev/md1 /dev/sdb2
mdadm --add /dev/md3 /dev/sdb3

Boot from Install DVD CentOS 4

boot: linux rescue
mdadm --assemble /dev/md0 /dev/sda1
mdadm --assemble /dev/md1 /dev/sda2

Create isolated chroot

mkdir /mnt/sysimage
mount /dev/md1 /mnt/sysimage
mount -o bind /dev /mnt/sysimage/dev
mount -t proc none /mnt/sysimage/proc
mount -t sysfs none /mnt/sysimage/sys
chroot /mnt/sysimage

Leave a Reply

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