# Installing grub on RAID1

When you have your kernel image and grub boot stages on a Linux software RAID1 partition, installing grub needs a bit of trickery.

It determines on what hardware device those files are located by looking at /etc/mtab. It will find /dev/md/0 for / or /boot (or whatever) where the files are located. That device has no BIOS device, because it is managed by the Linux kernel. Therefore, when you try to install grub, it says: “/dev/md/0 does not have any corresponding BIOS drive.“. But because the underlying partitions in a RAID1 have the same data as the virtual device, we can trick grub.

All we have to do is edit /etc/mtab and replace the /dev/md/0 with /dev/sda1 (or whatever). You can then run grub-install hd0. Of course, make a backup of mtab first so you can revert it after having installed grub.

I find it kind of weird that grub doesn’t determine that the device in question is a RAID1 and that it can simply use the underlying device; the internet is filled with people having the same problem. If anybody knows a more elegant solution than this, I’m all ears.

Based on the comments, this is what you need to install it from the grub prompt:

# grub
grub> root (hd0,0)
grub> setup(hd0)
grub> root (hd1,0)
grub> setup (hd1)

1. Comment by Ben
On July 24, 2009 at 03:07

There is also a way using the grub command line. You run grub, and at the grub> prompts you say
grub> root (hd0,0)
grub> setup(hd0)
grub> root (hd1,1)
grub> install
where (hd0,0) means something like /dev/sda1, and (hd1,0) /dev/sdb1. See http://www.linuxsa.org.au/mailing-list/2003-07/1270.html

2. Comment by Jean-Emmanuel Orfèvre
On January 15, 2010 at 03:32

# grub –no-floppy
grub> device (hd0) /dev/sda
grub> root (hd0,0)
grub> setup (hd0)
grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)

3. On Apr 28, 2012 at 13:04

[…] at the second example in the comments. It installs grub to both. http://blog.bigsmoke.us/2009/06/21/i…-grub-on-raid1 You might consider having the initial partition being non-raid, and use /dev/sdb1 as a n identical […]