grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to check if stage1 is or is not in a MBR ?


From: address@hidden
Subject: How to check if stage1 is or is not in a MBR ?
Date: Thu, 16 Dec 2010 16:23:41 +0900

Dear all,

For the "Linux uninstaller" project [1], I need your help :
- Is there a reliable way to check (in bash) if a functional (not altered, e.g. by another bootloader) stage1 is in a MBR ?
- Or/and the contrary (stage1 is altered or not present) ?

I observed that we can read (in hex) the word "GRUB" in the MBRs containing GRUB.
FYI, please find below [2] a little script I made to detect the word "GRUB" in a MBR. Are its conclusions always true ?

Thank you in advance for your help.

Best regards
Yann

[1] http://ubuntuforums.org/showthread.php?t=1615667
[2] Script below :


#! /bin/bash
mbr=$(sudo dd if=mbrtobechecked.img bs=446 count=1 | hexdump -C)
control1=$(echo "$mbr" | grep -i "GRUB")
control2a=$(echo "$mbr" | grep -i "G|"); control2b=$(echo "$mbr" | grep -i "|RUB")
control3a=$(echo "$mbr" | grep -i "GR|"); control3b=$(echo "$mbr" | grep -i "|UB")
control4a=$(echo "$mbr" | grep -i "GRU|"); control4b=$(echo "$mbr" | grep -i "|B")
if [ "$control1" ] || [ "$control2a" -a "$control2b" ] || [ "$control3a" -a "$control3b" ] || [ "$control4a" -a "$control4b" ];then
  echo "the MBR contains the word <grub>, so stage1 is installed into the MBR."
else
  echo "the MBR does not contain the word <grub>, so stage1 is not installed into the MBR."
fi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]