7

Out of curiosity, is it possible to find out which bootloader was used to start a given system? Was the system booted by GRUB, LILO or any other boot loader?

I guess there must exist some /sys or /proc variable for the same?

EDIT:

Boot Info Summary: => Lilo is installed in the MBR of /dev/sda

sda1: ___________________________________________________________________

File system:       
Boot sector type:  Unknown
Boot sector info:
Mounting failed: mount: unknown filesystem type ''

/dev/sda is the only device I have to boot with.

I wonder, if there is no known file system on the only available single partition, then how did it manage to boot?

3 Answers 3

6

I don't believe this info is tracked in meaningful way under either /sys or /proc. About the only way I can fathom this would be accessible to you after a boot is by interrogating the system either by looking to see if a GRUB or Lilo configuration file was present, or by making use of a script such as bootinfoscript.

Example - check boot device

If you know which device your system was booted with you can use dd to dump the contents of the boot loader and then grep for either GRUB or LILO.

                      ss #1

You can use these commands to determine whether you're using GRUB or LILO:

$ sudo dd if=/dev/sda bs=512 count=1 2>&1 | grep GRUB
$ sudo dd if=/dev/sda bs=512 count=1 2>&1 | grep LILO

Which ever returns this string is the boot loader you're using:

Binary file (standard input) matches

Example - using bootinfoscript

$ sudo ./bootinfoscript --stdout
                  Boot Info Script 0.61      [1 April 2012]


============================= Boot Info Summary: ===============================

 => Grub2 (v1.99) is installed in the MBR of /dev/sda and looks at sector 1 of 
    the same hard drive for core.img, but core.img can not be found at this 
    location.

sda1: __________________________________________________________________________

    File system:       ext4
    Boot sector type:  -
    Boot sector info: 
    Operating System:  
    Boot files:        /grub2/grub.cfg
    ...

Neither of these approaches is "conclusive", however, since multiple boot loaders can coexist, but at least it gives you a rough idea of the boot loaders that "might" be in use.

References

1
  • 2
    Worth pointing out how useful sudo dd if=/dev/sda bs=512 count=1 2>&1 | strings might be over just grepping here as you'll get some info no matter what you're running.
    – Thom
    Commented Oct 23, 2019 at 20:17
2

See this. This script is written in Bash, however, so if you need to run it on an embedded platform you will have to modify it. I have tested this script and it has correctly recognized GRUB on Ubuntu and LILO on Slackware.

2

To get bootloader id use bootloader_type

echo $((`cat /proc/sys/kernel/bootloader_type`>>4)) 

Find your bootloader id

You must log in to answer this question.

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