GRUB 2 Headaches: where is it installed?

Discussion in 'all things UNIX' started by wat0114, Dec 27, 2014.

  1. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    To clear up misunderstandings I've had regarding Grub 2, where exactly does it install to when the standard and recommended option "/dev/sda" is selected during installation of Linux?

    My most recent Manjaro setup is within an extended partition as follows:

    /dev/sda3 = Extended, flag = lba

    within this Extended partition:

    /dev/sda5 = / (root), flag = boot
    /dev/sda6 = swap
    /dev/sda7 = /home

    there is no other O/S, just a Primary storage partition alongside it.

    The confusion for me happens when I open Gparted and I see the "boot" flag on sda5, but I know I selected "sda" when I chose where grub 2 would be installed. I guess grub 2 is installed on MBR, and it points to grub configuration files on sda5 / ?

    Part of this confusion arose last night when the h/drive it was installed on started making ticking/clunking noises - not good - even when booting, so I had to scrounge yet another h/drive (second dying drive this week!) then restore an IFL (Image for linux) backup of this setup to it. Restore went without a hitch. So far so good.

    The problems started, however, when I booted off this restored image (on the new h/drive) and Grub is not found, or something to that effect. luckily I was able to boot off the live Manjaro disk and recover it using a fairly involved procedure found here. I failed miserably at first thinking I had to install grub to sda5, but then finally figured out that I just had to install to sda.

    So did my restored image not boot because grub 2 is installed on MBR, so the backup does not include it? I chose to backup only the extended partition and the partitions within it. Even though it's not recommended to install grub 2 on one of the Linux partitions, such as "/", does it maybe make more sense to install it this way, so that an image of this extended partition containing the Linux O/S will also back up grub 2?
     
    Last edited: Dec 27, 2014
  2. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Hi, Yes it seems you are on to it. You installed Manjaro grub2 to a boot sector only: /dev/sda5, with the original grub2 installed to MBR on sda.
    So, by just imaging the extended partition, the grub2 installed to sda (MBR) was missing, that's why the restored image was unable to boot.
     
  3. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    Thanks Ocky. That makes sense, especially because the restored image went to an entirely different h/drive. Maybe next time I will try installing grub2 to the / partition and just make sure it never gets updated.
     
  4. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    EDIT:

    okay, still I'm not convinced I understand this correctly. I now think grub2 is installed on sda5 and not at the beginning of the h/drive. In the grub.cfg file, I see:

    set root='hd0,msdos5' ...this would seem to imply it's installed on sda5?

    Also, in the /etc/default/grub plain text file I see:

    # Uncomment if you want GRUB to pass to the Linux kernel the old parameter
    # format "root=/dev/xxx" instead of "root=/dev/disk/by-uuid/xxx"
    #GRUB_DISABLE_LINUX_UUID=true


    ...and this is now where I believe *maybe* the problems occurred when I restored the image to a different h/drive. grub2 is looking for the disk's uuid signatures, so the new h/drive with different uuid was not recognized?? Maybe un-commenting the above parameter would solve the problem?
     
  5. Nebulus

    Nebulus Registered Member

    Joined:
    Jan 20, 2007
    Posts:
    1,635
    Location:
    European Union
    When you install GRUB2 to /dev/sda (without any partition number), it installs a part of it in the MBR and a part on the boot partition (or /boot folder in the root partition).
     
  6. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    Thanks Nebulus. Maybe I guessed right in my initial post, then. Part of the confusion for me is seeing the boot flag on sda5, but what you're saying makes sense because if I were to install Windows on this drive, it will most certainly screw up the grub2 bootloader, because Windows will overwrite it in the MBR with its own.

    EDIT

    okay I found a way to view the hex dump of the MBR, and it does show something GRUB related in there, although I don't know what the ERROR is about. I guess it does indeed point to the sda5 partition so it can read/load the grub configuration file(s).
     

    Attached Files:

    Last edited: Dec 28, 2014
  7. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Can you use sudo blkid in Manjaro ? That would give you the uuid's. You can only have one MBR per disc but many boot sectors. Partition boot sector is located at the begining of that partition. It is not the same as MBR, which basicaly means if you don't have a bootloader in MBR, you cannot boot, because your BIOS only launches whichever bootloader it finds in MBR, it does not look for it in partition(s) boot sectors.

    MR56.png
     
    Last edited: Dec 29, 2014
  8. Nebulus

    Nebulus Registered Member

    Joined:
    Jan 20, 2007
    Posts:
    1,635
    Location:
    European Union
    That is just a list of strings used by the MBR part of GRUB to show you an error if it finds something wrong with the disk during the boot process.
     
  9. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    Thanks again, Ocky and Nebulus. Actually, it makes sense to me now, especially regarding only one mbr and many boot sectors. That error is *hopefully* nothing serious. As it stands now, I'm going to have to purchase at least one h/drive to get things up to speed here, since I've got two of them dying a slow death this past week.

    It's too bad it wasn't as easy to fix Linux boot issues with grub2 as it is with Windows boot problems. With Windows just using the Startup repair off the disk or even fixmbr is all it takes, but I have found over the years with Linux I need to run a whole bunch of commands to fix problems, like the procedure from the link in my first post. I think the main issue I ran into here was that the replacement h/drive I required has a 32GB storage partition at the beginning of the drive, whereas the Linux extended partition is next. If they were the other way around, then the image would have covered the mbr as well as the Linux extended partition (containing /, swap, /home).
     
  10. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Hope you get it all sorted wat0114. But you are right, Linux can be a royal pita. With me it's printing, have spent, or rather wasted many hours trying to get the damn HP deskjet to print. It's a hit and miss affair. Disabled cups stuff in apparmor etc. Mrk. says try foomatic drivers but there are none for my pride and joy. Nonsense like that can really put one off Linux.
     
  11. wat0114

    wat0114 Registered Member

    Joined:
    Aug 5, 2012
    Posts:
    4,065
    Location:
    Canada
    I think I've got it all sorted , Ocky.Thanks again for your help.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.