Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: [SOLVED] How to determine which Linux partition w/ Grub controls the MBR?

  1. #1
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Question [SOLVED] How to determine which Linux partition w/ Grub controls the MBR?

    If in addition to Ubuntu I have other linux distros installed in separate partitions on my HD, what is a good way to determine exactly which distro (partition) is controlling the MBR? I know I can figure it out by examining the menu.lst files for all the partitions, but is there some Grub command in the grub CLI that will just tell me what partition controls the MBR?

    Thanks for any help.

  2. #2
    Join Date
    Mar 2008
    Location
    NSW Australia
    Beans
    232
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    ubuntuforums.org/showthread.php?t=224351

    Best grub tutorial ever. I think the command you're looking for is

    Code:
    sudo grub
    find /boot/grub/stage1
    Good luck.

  3. #3
    Join Date
    Jun 2006
    Location
    Texas
    Beans
    3,930
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Not anyway I know of to tell which Linux installs GRUB controls
    the MBR. (other that the one you mentioned about checking the menu.lst).

    If you have always used the default install then I'd bet the GRUB you get belongs to the last distro you installed.

    Most Linux installers let you put the GRUB stage1 code in the boot sector of its install partition. thats what I do. then I just add a configfile or chainloader option to my 1st GRUBS menu.lst to boot the other Linux distro.

    Cood stuff here on GRUB IDBS GRUB Page

    Good to know stuff here too GrubHowto - Community Ubuntu Documentation
    UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn
    SystemRescueCd | Dual Boot | psychocats | FAQ

  4. #4
    Join Date
    Apr 2008
    Beans
    3,317
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    I don't really recommend this (since "dd" is one of those dangerous commands and you have to be really careful whenever you use "dd"), but this will tell you which linux is in control of the MBR

    Code:
    sudo dd if=/dev/sda  bs=1 skip=1049 count=2 | hexdump
    (Here you need to replace /dev/sda by whatever drive you are booting from. Also this is a command in a linux terminal, not in the grub command line))

    The output will look like this


    00000000 ff05
    00000002

    or

    00000000 8205
    00000002

    In the first case the controlling linux is (hd0,5)
    ff means the controlling linux is on the boot drive, "ff 0n" means (hd0,n).

    In the second case the controlling linux is (hd2,5) "8m 0n" means (hdm,n)
    Last edited by meierfra.; September 4th, 2008 at 07:25 PM. Reason: fixed a mistake

  5. #5
    Join Date
    Jun 2006
    Location
    Texas
    Beans
    3,930
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Quote Originally Posted by meierfra. View Post
    I don't really recommend this...
    Nice. Do you remember where you found this little nugget.?
    UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. -- Doug Gwyn
    SystemRescueCd | Dual Boot | psychocats | FAQ

  6. #6
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Quote Originally Posted by meierfra. View Post
    Code:
    sudo dd if=/dev/sda  bs=1 skip=1049 count=2 | hexdump
    I agree with louieb, where did you find this extremely useful gem of pure Linux voodoo? Do you know the translation behind the number for the HD? If "ff" is the first HD, "52" the second, what would be the third or fourth for instance?

    Although I wish grub had some command to simply tell which partition the MBR points to, this command gets the job done. Thanks much for sharing it!
    Last edited by caljohnsmith; June 23rd, 2008 at 03:24 PM.

  7. #7
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Quote Originally Posted by louieb View Post
    Nice. Do you remember where you found this little nugget.?
    Here is a good explanation of how Grub works on the machine level. It describes in detail how Grub works. It displays the hex of the MBR.

    So this might be what your looking for:

    http://mirror.href.com/thestarman/asm/mbr/GRUB.htm

  8. #8
    Join Date
    Apr 2008
    Beans
    3,317
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    If "ff" is the first HD, "52" the second, what would be the third or fourth for instance?
    It's a little different: ff means the first drive. In all other cases , "xy" means (hdy,x).


    Do you remember where you found this little nugget.?
    Well, just by looking at the first few sectors of the hard drive, I have found out where Grub stores the (hdx,y) variables. Later I noticed that the grub manual (Appendix D.2.) contains this information.
    I don't remember where I learned about "dd" and "hexdump".
    The exact code I made up myself to answers the OP's question.
    Last edited by meierfra.; June 23rd, 2008 at 04:28 PM.

  9. #9
    Join Date
    Mar 2008
    Location
    California, USA
    Beans
    8,111

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Thanks for clarifying how the HD numbers are interpreted from the dd command's output, meierfra.

    But here's another important thing I noticed:
    On boot-up, if I enter the Grub CLI, if I do the "find /boot/grub/stage1" command, it finds (hd0,1) which I know is the partition that the MBR points to. BUT, if I enter the Grub CLI after I've booted into one of my linux distros (using "sudo grub"), the "find /boot/grub/stage1" command returns both (hd0,1) and (hd0.3). To clarify, I have 4 partitions like such:
    Code:
    (hd0,0) = Windows
    (hd0,1) = Ubuntu (has Grub installed)
    (hd0,2) = Swap space
    (hd0,3) = Mandriva (also has Grub installed, but Grub was installed to the boot sector of its partition, not to the MBR)
    Thus it seems like when I do the "find /boot/grub/stage1" command from the boot-up Grub CLI, I get the partition the MBR points to. But if I go to the Grub CLI from within one of my Linux distros and do the same command, Grub returns ALL my partitions that contain a Grub stage1 file, and not just the partition that the MBR points to.

    Can someone please either confirm or clarify this?

  10. #10
    Join Date
    Apr 2008
    Beans
    3,317
    Distro
    Kubuntu 9.10 Karmic Koala

    Re: How to determine which Linux partition w/ Grub controls the MBR?

    Thus it seems like when I do the "find /boot/grub/stage1" command from the boot-up Grub CLI, I get the partition the MBR points to. But if I go to the Grub CLI from within one of my Linux distros and do the same command, Grub returns ALL my partitions that contain a Grub stage1 file, and not just the partition that the MBR points to.

    The Grub CLI should also return all partitions containing the stage1 file.

    I'm not sure why it doesn't. Couple of possible reasons:


    1) Your bios are only able to see the first 130GB of your hard drive and the Mandriva stage1 file is beyond the 130 GB limit.

    2) The Mandriva ext3 filesystem uses 256 bytes inodes and older versions of grub are not able to read such a file system.


    But both of these explanations don't make sense to me, since in either case you should not be able to boot Mandriva

    Although in case 1) you might be able to boot. Maybe only the stage 1 files are out of reach (which wouldn't cause a problem) But stage2, menu.lst and the kernel are in reach. What is the output of


    find /boot/grub/menu.lst

    and

    find /boot/grub/stage2
    Last edited by meierfra.; June 23rd, 2008 at 07:03 PM.

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •