Home > Linux, Storage > Check if GRUB is installed

Check if GRUB is installed

Odin! Guide our ships
Our axes, spears and swords
Guide us through, storms that whip
And in brutal war!!!
(Amon Amarth – The Pursuit of the Vikings)

GRUB boot loader installs on a MBR of a block device or on a partition during the operating system deployment procedure. A need rarely occurs for a GRUB reinstallation. One of the most often situations is when MD raid is used for boot device and one of the mirrored drives fails. New drive comes blank and grub has to be installed to ensure safe boot in case of potential failure of other drive.

To see if the grub is already installed on a drive, there are two methods. First method implements file command:

# file -s /dev/sda
/dev/sda: x86 boot sector; GRand Unified Bootloader, 
stage1 version 0x3, boot drive 0x80, 1st sector stage2 0x1941f250,
GRUB version 0.94; .....

But, this method is not reliable. Because we know that grub occupies first 512 bytes of a drive, we can use dd with output parsed by strings:

# dd bs=512 count=1 if=/dev/sda 2>/dev/null| strings
Hard Disk

If you can see string GRUB in this output, that tells us that Grub is indeed installed. Just for comparison, checking sda1 partition on the same drive gives a little bit different results:

# dd bs=512 count=1 if=/dev/sda1 2>/dev/null| strings
A disk read error occurred
BOOTMGR is missing
BOOTMGR is compressed
Press Ctrl+Alt+Del to restart

This partition is obviously NTFS with BOOTMGR from Windows. OK, I have a dual boot so this is ok 🙂 Now, just for demonstration purposes, lets fix a real world situation: sda from md raid failed and was replaced and this is what we found on a system:

[root@machine ~]# dd bs=512 count=1 if=/dev/sdb 2>/dev/null | strings
Hard Disk
[root@machine ~]# dd bs=512 count=1 if=/dev/sda 2>/dev/null| strings
[root@machine ~]# grub 
Probing devices to guess BIOS drives. This may take a long time.

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub>  setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  15 sectors are embedded.
 Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
grub> quit
[root@machine ~]# dd bs=512 count=1 if=/dev/sda 2>/dev/null| strings
Hard Disk

It’s obvious that grub is installed on sdb but not on sda. After the grub installation we can check for results.

Categories: Linux, Storage Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: