Ubuntu – degraded software raid boot

bootsoftware-raidUbuntu

I've installed Ubuntu 12.04.1 in a new server and set up the 4 hard drives with 3 RAID 1 devices, the configuration is such that the first two drives have md0 (swap space) and md1 (/) with the third and fourth drives having md2 (/var).

I've been testing the operation under a drive failure and found that the system boots fine if I remove disk two but if I remove disk one then the system gets to grub and then just restarts. I'm confused as to why grub appears to be loading properly from disk two but then the boot fails.

I've tried to copy the MBR from disk 1 to 2:

dd if=/dev/sda of=/dev/sdb bs=512 count=1

but this didn't make a difference.

grub.cfg

#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
if [ -s $prefix/grubenv ]; then
  set have_grubenv=true
  load_env
fi
set default="0"
if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function recordfail {
  set recordfail=1
  if [ -n "${have_grubenv}" ]; then if [ -z "${boot_once}" ]; then save_env recordfail; fi; fi
}

function load_video {
  insmod vbe
  insmod vga
  insmod video_bochs
  insmod video_cirrus
}

insmod raid
insmod mdraid1x
insmod part_msdos
insmod part_msdos
insmod ext2
set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
if loadfont /usr/share/grub/unicode.pf2 ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  insmod raid
  insmod mdraid1x
  insmod part_msdos
  insmod part_msdos
  insmod ext2
  set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
  search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
  set locale_dir=($root)/boot/grub/locale
  set lang=en_GB
  insmod gettext
fi
terminal_output gfxterm
if [ "${recordfail}" = 1 ]; then
  set timeout=-1
else
  set timeout=2
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_linux ###
function gfxmode {
    set gfxpayload="${1}"
    if [ "${1}" = "keep" ]; then
        set vt_handoff=vt.handoff=7
    else
        set vt_handoff=
    fi
}
if [ "${recordfail}" != 1 ]; then
  if [ -e ${prefix}/gfxblacklist.txt ]; then
    if hwmatch ${prefix}/gfxblacklist.txt 3; then
      if [ ${match} = 0 ]; then
        set linux_gfx_mode=keep
      else
        set linux_gfx_mode=text
      fi
    else
      set linux_gfx_mode=text
    fi
  else
    set linux_gfx_mode=keep
  fi
else
  set linux_gfx_mode=text
fi
export linux_gfx_mode
if [ "${linux_gfx_mode}" != "text" ]; then load_video; fi
menuentry 'Ubuntu, with Linux 3.2.0-29-generic' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod raid
    insmod mdraid1x
    insmod part_msdos
    insmod part_msdos
    insmod ext2
    set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
    search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
    linux   /boot/vmlinuz-3.2.0-29-generic root=UUID=c3a8948c-4ca8-4d3b-acbe-64baa0f7a181 ro   
    initrd  /boot/initrd.img-3.2.0-29-generic
}
menuentry 'Ubuntu, with Linux 3.2.0-29-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod gzio
    insmod raid
    insmod mdraid1x
    insmod part_msdos
    insmod part_msdos
    insmod ext2
    set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
    search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
    echo    'Loading Linux 3.2.0-29-generic ...'
    linux   /boot/vmlinuz-3.2.0-29-generic root=UUID=c3a8948c-4ca8-4d3b-acbe-64baa0f7a181 ro recovery nomodeset 
    echo    'Loading initial ramdisk ...'
    initrd  /boot/initrd.img-3.2.0-29-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
    insmod raid
    insmod mdraid1x
    insmod part_msdos
    insmod part_msdos
    insmod ext2
    set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
    search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
    linux16 /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
    insmod raid
    insmod mdraid1x
    insmod part_msdos
    insmod part_msdos
    insmod ext2
    set root='(mduuid/bec69e6b53a222d6726d1f6a11d27043)'
    search --no-floppy --fs-uuid --set=root c3a8948c-4ca8-4d3b-acbe-64baa0f7a181
    linux16 /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

mdadm configuration

:~$ mdadm /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Wed Aug 29 10:28:02 2012
     Raid Level : raid1
     Array Size : 15615872 (14.89 GiB 15.99 GB)
  Used Dev Size : 15615872 (14.89 GiB 15.99 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Sep  3 10:35:25 2012
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : norsewind-obs:0  (local to host norsewind-obs)
           UUID : b55552d2:1e554573:82671934:3831d058
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1


:~$ sudo mdadm -D /dev/md1
        Version : 1.2
  Creation Time : Wed Aug 29 10:28:11 2012
     Raid Level : raid1
     Array Size : 1937758016 (1847.99 GiB 1984.26 GB)
  Used Dev Size : 1937758016 (1847.99 GiB 1984.26 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Sep  3 10:47:40 2012
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : norsewind-obs:1  (local to host norsewind-obs)
           UUID : bec69e6b:53a222d6:726d1f6a:11d27043
         Events : 263

    Number   Major   Minor   RaidDevice State
       0       8        2        0      active sync   /dev/sda2
       2       8       18        1      active sync   /dev/sdb2

fdisk

:~$ sudo fdisk -l

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ccfa5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    31250431    15624192   fd  Linux RAID autodetect
/dev/sda2   *    31250432  3907028991  1937889280   fd  Linux RAID autodetect

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ccfa5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    31250431    15624192   fd  Linux RAID autodetect
/dev/sdb2   *    31250432  3907028991  1937889280   fd  Linux RAID autodetect

Disk /dev/sdc: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c73aa

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048  3907028991  1953513472   fd  Linux RAID autodetect

Disk /dev/sdd: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00035b05

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048  3907028991  1953513472   fd  Linux RAID autodetect

Disk /dev/md2: 2000.3 GB, 2000263380992 bytes
2 heads, 4 sectors/track, 488345552 cylinders, total 3906764416 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/md2 doesn't contain a valid partition table

Disk /dev/md0: 16.0 GB, 15990652928 bytes
2 heads, 4 sectors/track, 3903968 cylinders, total 31231744 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/md0 doesn't contain a valid partition table

Disk /dev/md1: 1984.3 GB, 1984264208384 bytes
2 heads, 4 sectors/track, 484439504 cylinders, total 3875516032 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/md1 doesn't contain a valid partition table

Best Answer

Use grub-install rather than dd to install grub into the MBR.

e.g. (as root, or with sudo):

grub-install /dev/sda
grub-install /dev/sdb

BTW, unless you're hibernating to the swap partition, you don't need RAID on swap devices. You might be better off destroying md0 and using the swap partitions on sda and sdb individually.

Related Question