8

On a Debian Linux box, I'm running into a very strange situation where after power-on, GRUB fails with the error "no such partition", but if I then hit the reset button, it boots normally. I'm trying to diagnose the situation, and I realized that I don't know which versions of what bootloaders are installed where? How can I find out? That is, how can I find out what bootloader is installed on the MBR of each of my disks, and how can I find out which second-stage bootloaders are installed on the various partitions?

If I can't find out exactly what I have, I'd settle for being able to find out just which version of GRUB is installed where.

Norman Ramsey
  • 2,843
  • 8
  • 31
  • 41
  • Have you pressed the "Esc" key (to display Grub's boot menu) before the error message appears? – sawdust Aug 25 '12 at 01:45
  • @sawdust we don't get as far as a menu. Just "Grub loading; Welcome to Grub;" and then the error. Normally I would expect a menu and then autoboot after a timeout of 10s. But I'm not getting that far. Hence the question about "how do I figure out what is there." Maybe my job is just to reinstall everything :-( – Norman Ramsey Aug 25 '12 at 01:48
  • related: https://serverfault.com/questions/61400/how-do-i-tell-if-grub-is-installed-on-a-device – Ciro Santilli OurBigBook.com Jan 15 '19 at 23:38

2 Answers2

14

You can see whether GRUB (1 or 2) is installed on the MBR with dd:

dd if=/dev/sda bs=512 count=1 2> /dev/null | grep -q GRUB && echo "GRUB found"

If a GRUB signature was found, you can then run:

file -s /dev/sda

If the output is something like:

/dev/sda: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3...........

then you have GRUB1 installed on the MBR. If there isn’t any mention of GRUB, like this:

/dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead 32, startsector 2048........

then you have GRUB 2 installed on the MBR of that disk.

To find the essential GRUB files ("stages" for GRUB 1, "images" for GRUB 2):

GRUB 1:

Configuration file:

find / -name menu.lst

Stages:

find / -name stage1

or

find / -name stage2

GRUB 2:

Configuration file:

find / -name grub.cfg

Images:

find / -name core.img

or

find / -name boot.img
Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
don_crissti
  • 2,804
  • 1
  • 20
  • 20
  • 1
    Absolutely brilliant. It seems `file(1)` has everything these days. – Norman Ramsey Aug 25 '12 at 22:49
  • Using `file -s` helped me find the Windows bootloader on my PC. Thanks! – wjandrea Mar 08 '17 at 20:58
  • What is the gist of the `dd` command? Examine the first 512 bytes of the device? – Peter Mortensen Mar 11 '23 at 11:40
  • This could be updated for [UEFI](https://en.wikipedia.org/wiki/UEFI) / [GPT](https://en.wikipedia.org/wiki/GUID_Partition_Table) partitioning. But ********* ********* ***without*** ********* ********* "Edit:", "Update:", or similar - the answer should appear as if it was written today) – Peter Mortensen Mar 11 '23 at 11:42
6

You can use Boot Info Script which gives you detailed information about your boot status and tells you which bootloader is installed where, combined with lots of detailed other information relevant to booting. It's available in Debian as package boot-info-script.

WD40
  • 103
  • 4
drott
  • 201
  • 2
  • 3
  • 2
    `sudo apt install boot-info-script` and then `sudo bootinfoscript`. The output is in `RESULTS.txt`. Valid on Ubuntu 18.04 (5 years later). – estibordo Apr 29 '18 at 13:43