How to find where Grub is installed

dual-bootgrub2partition

How can I find where Grub2 is installed?

This is my current disk partitioning (if it matters, I'm running openSUSE Tumbleweed)

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x34fe34fd

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1              63 205404159 205404097    98G  7 HPFS/NTFS/exFAT
/dev/sda2       205404160 407547903 202143744  96.4G  7 HPFS/NTFS/exFAT
/dev/sda3  *    407547904 976773167 569225264 271.4G  5 Extended
/dev/sda5       407549952 489474047  81924096  39.1G 83 Linux
/dev/sda6       489476096 974725119 485249024 231.4G 83 Linux
/dev/sda7       974727168 976773119   2045952   999M 82 Linux swap / Solaris

I can only see a single partition labelled as bootable, and I'm pretty sure that sda1 was bootable as well (it contained a Windows installation, but I had to wipe it out and now is empty).

After I will have reinstalled Windows, I will need to run grub2-reboot to restore it, but I don't know how can I find where it is installed currently (i.e. sda or sda3).

Is there a command that can show me this information? And, ultimately, does this matters, or I can reinstall wherever I like?

Best Answer

sudo fdisk -l 2>/dev/null | egrep "Disk /|/dev/" | sed "s#^/dev/#Part /dev/#" | awk '{print $2}' | sed 's/://' | xargs -n1 -IX sudo sh -c "hexdump -v -s 0x80 -n  2 -e '2/1 \"%x\" \"\\n\"' X | xargs -n1 -IY sh -c \"case  \"Y\" in '48b4') echo X: GRUB 2 v1.96 ;; 'aa75' | '5272') echo X: GRUB Legacy ;; '7c3c') echo X: GRUB 2 v1.97 oder v1.98 ;; '020') echo X: GRUB 2 v1.99 ;; *) echo X: Kein GRUB Y ;; esac\"" 
Related Question