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
1 Answer
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.
-
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– HumberJan 5, 2010 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''.– pfoJan 5, 2010 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.– HumberJan 5, 2010 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.– pfoJan 5, 2010 at 14:17
-
Great. Actually, my grub version (Grub 2 1.97~beta4-1ubuntu4.1) does show the GRUB string. Tnks again Pfo– HumberJan 5, 2010 at 14:33