How can I tell if grub is installed on a disk, and if it is what settings it has (noteably, what it has for the root parameter)

I need to check a lot of disks in software RAID1 arrays to make sure both disks have grub installed, with the grub on each disk having the appropriate root value.

  • 4
    Can you consider to accept the new answer below? since the accepted answer is outdated by now
    – rubo77
    Commented Oct 15, 2015 at 19:48
  • @rubo77, my answer was correct at the time, when grub 0.9x or lower was in common usage and long before it became renamed to grub-legacy. If this bothers you, I suggest asking a new question specifically about grub2. alternatively, conduct a campaign correcting every question and answer that has become obsolete through the passage of time.
    – cas
    Commented Mar 23, 2016 at 23:07
  • 4
    No offence. I think SO is a knowledge base and is meant to be changing over time. Once outdated answers should be updated.
    – rubo77
    Commented Mar 24, 2016 at 1:22

4 Answers 4


This is a simple way to tell if GRUB is installed. If it doesn't work your file command's database is likely out of date and you can either update the its database or use an alternate method from another answer.

You can use file to identify GRUB in an MBR. e.g.

# file -s /dev/sda
/dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3
, stage2 address 0x2000, stage2 segment 0x200; partition 1:
ID=0xfd, starthead 1, startsector 63, 1044162 sectors; partition
2: ID=0x82, starthead 0, startsector 1044225, 1028160 sectors;
partition 3: ID=0xfd, starthead 0, startsector 2072385,
1951447680 sectors, code offset 0x48

The root= paramater is not stored in the MBR, that's stored in GRUB's menu.lst file which is stored on a file-system (typically in the /boot/grub directory of the root fs or the grub directory of the /boot filesystem - but not always, it could be anywhere).

You'll have to parse the output of file above, determine which disk/partition the menu.lst file is on, mount it, read it in and parse it. You'll also want to read in the grub/default file to figure out which grub menu entry is the default, because that's probably the one that has the root= parameter that you're most interested in.

  • In that case I need a way to make sure grub is looking for menu.lst in the proper place... somewhere the boot loader must be told which disk & partition it has to go to so it can get the boot menu.
    – DrStalker
    Commented Sep 2, 2009 at 5:51
  • there's a lot of useful info about grub at the grub home page gnu.org/software/grub , the grub wiki grub.enbug.org , and at wikipedia en.wikipedia.org/wiki/GRUB
    – cas
    Commented Sep 2, 2009 at 21:31
  • 12
    This is no longer correct with grub2. See @benrifkah's answer instead. Commented Apr 8, 2013 at 21:19

Alternate Method

file -s didn't work for me in Ubuntu Lucid because my file command's magic files were out of date. Another way to do this if your magic files haven't caught up with GRUB changes is to examine the first 512 bytes of the device using the dd command like this:

user@host:~$ sudo dd bs=512 count=1 if=/dev/sda 2>/dev/null | strings
Hard Disk

This sends the output of the dd command through the strings command thus stripping out unprintable characters (transfer statistics get discarded to /dev/null).

If you see any messages that GRUB would display when it encounters failure then you've got grub installed.

Hat tip to louib on ubuntuforums.org for answering in this password protected post: http://ubuntuforums.org/showthread.php?t=363372

To scan all devices, lsblk (list block devices) comes handy:

user@host:~$ sudo sh -c 'for d in $(lsblk -Ardpn -o NAME); do dd bs=512 count=1 if=$d 2>/dev/null | strings | grep -qi grub && echo "Grub found on dev: ${d}"; done' 
Grub found on dev: /dev/sda

For the curious this is what I got from file -s:

user@host:~$ sudo file -s /dev/sda
/dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 20
48, 337211392 sectors; partition 2: ID=0x5, starthead 254, startsector 337215486, 1434214
6 sectors, code offset 0x63

There's nothing about GRUB in there specifically.

  • 7
    Spot on. The accepted answer didn't work for me on several machines, but yours did.
    – Cerin
    Commented Aug 5, 2011 at 3:35
  • 15
    The accepted answer was written in 2009 and (as should be obvious from the mention of menu.lst rather than grub.cfg) was for grub1 aka "grub-legacy". obviously things have changed since then, and grub2 doesn't put an identifier in the MBR. if it worked on some machines for you but not on others, that would imply you have grub1 on some and grub2 on others.
    – cas
    Commented Sep 11, 2011 at 23:09
  • 1
    Thanks for the clarifications Craig. The system I originally tried the file -s command on uses grub-pc which is apparently GRUB2 so it sounds like you're partially correct. However, I ran file -s on some other systems running GRUB 0.97 and on some it worked while on others it didn't. The difference between these systems was in the numbers in the magic files that come with the file command. Swapping magic number files confirmed that the definitions from the non-working system caused the working system to fail.
    – benrifkah
    Commented Sep 12, 2011 at 19:02
  • I don't understand how that output tells us if grub is there or not
    – simplename
    Commented Mar 26, 2021 at 16:44
  • 1
    @cas this worked for me with grub2. The command I use is grub2-install. Before running install I get blank, afterwards I get pretty much exactly as above.
    – MikeKulls
    Commented May 13 at 5:04

You can use grub-emu to see the menu that grub will show when the machine next reboots.

$ sudo apt-get install grub-emu
$ sudo grub-emu

On my desktop machine the menu was displayed as expected, although if I actually pretended to boot a kernel I got a "no such device" error. I think that is expected behaviour.

On my DigitalOcean VPS no entries were displayed in the grub menu, although the server did actually reboot fine. (This is a 2013 VPS, so your mileage may vary.)

Some notes when running grub-emu:

  • In X-windows, if you want to interact with grub, you need your keyboard focus to be on the terminal from which you ran grub-emu, and not on the window which popped up.
  • You can exit the emulator by pressing c then typing exit.
  • After exiting, your terminal emulator may be in a poor state (e.g. Enter will not display on a new line). Fix that by typing reset. (Don't worry it won't restart your machine. It will just clean up your terminal.)
  • Typing c followed by exit didn't work for me. Commented Jun 18, 2017 at 9:23
  • 1
    make sure your have the focus on the original terminal that spawned the grub window and not the grub window itself (took me a second to realise this)
    – Madivad
    Commented Jun 29, 2017 at 23:12

Just a primitive script using info from benrifkah's answer, for convenient use:

strings_found=`dd bs=512 count=1 if=${device} 2>/dev/null | strings`
if [[ ${strings_found} == *"GRUB"* ]]; then
  echo "${device} has GRUB installed"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .