18

In my setup, I have two disks that are each formatted in the following way:

(GPT)
1)  1MB   BIOS_BOOT
2)  300MB LINUX_RAID   
3)  *     LINUX_RAID   

The boot partitions are mapped in /dev/md0, the rootfs in /dev/md1. md0 is formatted with ext2, md1 with XFS. (I understand that formatting has to be done on the md devices and not on sd - please tell me if this is wrong).

How do I setup GRUB correctly so that if one drive fails, the other will still boot? And by extension, that a replacement drive will automatically include GRUB, too? If this is even possible, of course.

15

If the two disks are /dev/sda and /dev/sdb, run both grub-install /dev/sda and grub-install /dev/sdb. Then both drives will be able to boot alone.

Make sure that your Grub configuration doesn't hard-code disks like (hd0), but instead searches for the boot and root filesystems' UUIDs.

I'm not aware of support in Grub to declare two disks as being in a RAID-1 array so that grub-install would automatically write to both. This means you'll need to run grub-install again if you replace one disk; it's one more thing to do in addition to adding new members to the RAID arrays.

  • 1
    "Make sure that your Grub configuration doesn't hard-code disks like (hd0), but instead searches for the boot and root filesystems' UUIDs." How? – lifeofguenter Mar 7 '18 at 18:56
  • 1
    @lifeofguenter With search – Gilles Mar 8 '18 at 7:46
  • 1
    gnu.org/software/grub/manual/grub/grub.html#GNU_002fLinux or look at your distribution's file – Gilles Mar 8 '18 at 21:45
  • 1
    On some systems it's grub2-install instead of grub-install. – ndemou Mar 15 '18 at 13:06
  • 1
    Notice that the RAID is at partition level, not disk level; if it were, there would be no problem, as the mirroring would also mirror the MBR. – Marcos Dione Aug 24 '18 at 10:30
3

I've done this on quite a few servers over the past while and found issues sometimes, usually what I do is run the following

sudo grub-install /dev/sdb
sudo update-grub /dev/sdb

The problems I've run into are usually displayed with error messages like

update-grub … update-grub failed with no such disk …

To resolve this i've run

sudo mv /boot/grub/device.map /boot/grub/device.map.old 
sudo update-grub 

and this seems to have resolved the issue - as a test in some cases I have removed /sdv/sda and just used /dev/sdb to boot from but this is not ideal and most likely not possible in most production environments!

0

My experience installing CentOS 5 and CentOS 6 is that during the installation phase I configured the RAID-1 at that time - the installation does give you the choice to do this. What transpired was the following: 1. Defined /dev/sda1 as 1 GB as a RAID partition 2. Defined /dev/sdb1 as 1 GB as a RAID partition 3. Created RAID device /dev/md0 made up of /dev/sda1 and /dev/sdb1 4. Created the /boot partition using /dev/md0 5. Created additional partitions using steps 1 - 3. 6. Implemented LVM on partitions created in step 5 by following instructions.

After the initial system boot, in the grub.conf I altered the entry /dev/sda1 to /dev/md0. I then copied the entry the splashimage line the has (hd0,0) and added a # at the beginning and changed (hd0,0) to (hd1,0). Looking at the above answers showing how to install grub to /dev/sdb follow them. Modify the fstab so that the boot mount point uses /dev/md0 (by doing this, when you do a yum update a there is something updated on the /boot partition it will be written to both /dev/sda1 and /dev/sdb1). If you have a /dev/sda hard drive failure, you would have to boot using the rescue and comment out the (hd0,0) line and uncomment the (hd1,0) line. Your system should be bootable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.