Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have the following RAID 1 on a Centos 6.5 server:

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[3]
    974713720 blocks super 1.0 [2/1] [_U]
    bitmap: 7/8 pages [28KB], 65536KB chunk

md1 : active raid1 sdb2[3] sda2[2]
    2045944 blocks super 1.1 [2/2] [UU]

unused devices: <none>

# df -h
Sist. Arq.            Size  Used Avail Use% Montado em
/dev/md0              915G  450G  420G  52% /
tmpfs                 7,8G     0  7,8G   0% /dev/shm

/dev/sda is about to fail. I even marked it as faulty since it was causing read errors.

I got the new HD today which will replace /dev/sda.

The issue is that when I unplug the current /dev/sda, I can't make it boot only with /dev/sdb. It looks like the PC's BIOS can't find anything bootable on /dev/sdb.

1) How can I detect if grub is installed in /dev/sdb's MBR?

2) Is it safe to run grub-install in /dev/sdb? Is this the correct way of making it bootable?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

1) How can I detect if grub is installed in /dev/sdb's MBR?

You can issue:

# dd if=/dev/sda bs=512 count=1 | xxd | grep -i grub
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00103986 s, 492 kB/s
0000180: 4752 5542 2000 4765 6f6d 0048 6172 6420  GRUB .Geom.Hard

2) Is it safe to run grub-install in /dev/sdb? Is this the correct way of making it bootable?

Yes, you need to have grub installed on both disks in the array.

share|improve this answer
    
What's the point to do xxd before grep? Being more general it could make grep fail even if the string actually is there (if the string is split to occupy more than one lines due to its position or length or both). For GNU it's more straightforward to do sudo head -c512 /dev/sda | fgrep -i grub –  poige Jul 16 at 3:02

You tagged software-raid, so learning grub can help: How to boot after RAID failure (software RAID)?

GRUB Legacy identifies HDD devices in the /boot/grub/device.map file and maps them to the Linux devices. The GRUB Legacy (boot manager) file doesn't identify disks the same as Linux does. Instead of /dev/sda, the first disk would be identified as (hd0).

Tutorials on the grub command can be found elsewhere online.

Essentially, the author in the link runs grub commands where each Linux device is treated as the same drive for GRUB Legacy (as it sees it according to the device.map file), e.g. (hd0) for all three disks and not (hd1) etc. This ensures the correct mapping between (hd0) and /dev/sda, etc. for redundancy purposes.

The solution the link author noted doesn't modify the MBR however. The alternate software-raid specific solution needs to be done before disk failure; otherwise, you'll need a boot disk/device. The MBR of each disk should be the same for each disk for a RAID 1 array, even with LVMs. A MBR bootloader can't direct the system to another disk, only to the same boot flagged partition's GRUB Legacy or it will bypass the boot sector and load the kernel (depending on the code), and only within the same disk to my understanding.

share|improve this answer
1  
Thank you! Excellent information. Upvoted since I already accepted the other answer. –  Fernando Jul 16 at 2:31
    
No problem. In addition, sfdisk can be used to backup the MBR. Here's the edit that I didn't have time to re-edit into the answer above: (hda=IDE, sda=SCSI) (hd0 or hd0,0 - for the first partition on the first disk or hd0,4 for the first logical partition on the first disk) –  paulcube Jul 16 at 2:33
    
One example of MBR backup: #sfdisk -d /dev/sdb > sdb-backup.txt You'll have to check if the sfdisk MBR backup example really does backup the MBR correctly however. –  paulcube Jul 16 at 3:15
    
The dd answer given will allow you to see if the files match for both HDD devices, and it should. –  paulcube Jul 16 at 3:21
    
The xxd command does a hexdump (translates the symbols into numbers and characters), so you can get grep the "GRUB". –  paulcube Jul 16 at 3:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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