How can I check if a bootloader (i.e. grub2) is installed on a block device (e.g. CF card)? I know I can mount the device and peek some files but how can I be sure the bootloader is installed without having to test it (try to boot it on some device) Thanks in advance
Asked
Active
Viewed 1,299 times
1 Answers
5
This can be achieved quite easily by using the dd(1) command and copying the first 512 bytes from a given medium. Like:
dd if=/dev/sdX of=mbr-sdX bs=512 count=1
Then check if that file contains the hex signature ``0xAA55'' (don't forget to account for endianess of the machine). See [1] for more details.
![](../../users/profiles/26459.webp)
pfo
- 5,630
- 23
- 36
-
Awesome! Thanks pfo. So, running: '$ hexdump mbr-sdX | grep aa55' Should give me something like this right? '00001f0 0000 0000 0000 0000 0000 0000 0000 aa55' Thanks in advance. Humber – Humber Jan 05 '10 at 13:56
-
Exactly, I just verfied this on my Mac. As already said you should take care of the endianness of the machine, ie on an intel box you should grep for ``55 aa''. – pfo Jan 05 '10 at 14:12
-
Oops, sorry. If after testing a little bit I realize that '$hexdump -Cv mbr-sdX' show some grub string when the bootloader is installed and almost all 0 when it isn't. – Humber Jan 05 '10 at 14:13
-
1Yeah, but the method i described can be used for other MBRs too. It seams that some versions of GRUB also include a ``GRUB'' string in the MBR. – pfo Jan 05 '10 at 14:17
-
Great. Actually, my grub version (Grub 2 1.97~beta4-1ubuntu4.1) does show the GRUB string. Tnks again Pfo – Humber Jan 05 '10 at 14:33