Linux Software RAID 1

I was in the situation where the primary disk (hda) had dropped out of the RAID arrays it was in due to seek errors so needed to replace the primary disk.

URLs:

  • http://www.royong.com/showthread.php?t=16
  • http://www.linuxselfhelp.com/gnu/grub/html_chapter/grub_3.html
  • http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/Set_up_Grub_by_hand

Needed to install the boot loader onto the secondary disk as no doubt it hadn’t been setup.

Tried the grub-install command:

grub-install /dev/hdc

Thinking that this would do everything required I rebooted and took the primary disk out. The machie started booting up and then it kept printing to the screen “grub grub grub……”. Obviously not right so put the primary disk back in and rebooted.

This time ran the following:

grub
grub>find /grub/stage1
grub>device (hd0) /dev/hdc
grub>root (hd0,0)
grub>setup (hd0)
grub>quit

Then I rebooted and removed the primary disk… this time it booted up fine so I added the new disk.

Partition the new disk:

 fdisk -l /dev/hdc

And create the same partitions on the new machine.

sfdisk -d /dev/hdc | sfdisk /dev/hda

Or manually using fdisk.

Re-add the disks using mdadm…

mdadm /dev/md0 -a /dev/hda1
etc…

Software RAID

Some useful links to software based RAID:

Replacing a disk

[root@server ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 hdc3[1]
78911168 blocks [2/1] [_U]

md0 : active raid1 hdc1[1]
104320 blocks [2/1] [_U]

unused devices: <none>

Replacing a software based raid disk is fairly straight forward, however, on this occasion the system saw the new disk with different head counts and cylinders.

[root@server ~]# fdisk -l /dev/hda

Disk /dev/hda: 81.9 GB, 81964302336 bytes
16 heads, 63 sectors/track, 158816 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes

Device Boot Start End Blocks Id System
[root@server ~]# fdisk -l /dev/hdc

Disk /dev/hdc: 81.9 GB, 81964302336 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 * 1 13 104391 fd Linux raid autodetect
/dev/hdc2 14 140 1020127+ 82 Linux swap / Solaris
/dev/hdc3 141 9964 78911280 fd Linux raid autodetect

Two ways of changing this, one includes rebooting.

  1. In grubs grub.conf change the kernel line to reflect what the values should be:
    WAS: kernel /vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/md1
    NOW: kernel /vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/md1 hda=9964,255,63
  2. Or, execute command:
    echo bios_head:255 > /proc/ide/hda/settings

In this case I went for the echo option and below are the results…

[root@server ~]# fdisk -l /dev/hda

Disk /dev/hda: 81.9 GB, 81964302336 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Now, I can manually edit the partition table with fdisk /dev/hda or sfdisk.

[root@server ~]# sfdisk -d /dev/hdc | sfdisk /dev/hda

But, that some times gives an error, so I did it by hand with fdisk /dev/hda. Once complete/dev/hda looks the same:

[root@server ~]# fdisk -l /dev/hda

Disk /dev/hda: 81.9 GB, 81964302336 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 1 13 104391 fd Linux raid autodetect
/dev/hda2 14 140 1020127+ 82 Linux swap / Solaris
/dev/hda3 141 9964 78911280 fd Linux raid autodetect

Restart the raid syncronisation:

[root@server ~]# mdadm /dev/md0 -a /dev/hda1
mdadm: hot added /dev/hda1
[root@server ~]# mdadm /dev/md1 -a /dev/hda3
mdadm: hot added /dev/hda3

[root@server ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 hda3[2] hdc3[1]
78911168 blocks [2/1] [_U]
[>………………..] recovery = 0.3% (241920/78911168) finish=75.8min speed=17280K/sec
md0 : active raid1 hda1[0] hdc1[1]
104320 blocks [2/2] [UU]

unused devices: <none>

Just wait for it to finish now and hope the new disk has no errors.

Don’t forget about the swap partition, in this case /dev/hdc2.  As it’s already been partitioned you will need to set it up for being a swap partition:

 [root@server ~]# mkswap /dev/hdc2
[root@server ~]# swapon /dev/hdc2

That should ensure that the swap is mounted after reboot.