Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When you have multiple Linux OS's on the same computer, each installation has its own installation of GRUB, and the most recent installation is usually the one that is used when booting up. The issue comes up when I can no longer remember which is the most recent installation and I want to make modifications to the GRUB menu. How do I figure out which one is in use short of checking each installation individually? Is there a cleaner setup which avoids the problem in the first place by only having one installation of GRUB?

share|improve this question
    
Isn't the one at the top of the list the most recent one or am I missing something? –  Simon Hoare Jan 29 '13 at 13:44
    
possible duplicate of How do I make sure grub is only installed once? –  hildred Dec 26 '13 at 21:06

4 Answers 4

It sounds like you are installing GRUB in the master boot record of your primary hard disk. As hard disks only have one MBR, only one bootloader can reside in it at a time. You also appear to have told all of your operating systems to install a bootloader.

The proper way to handle this (assuming you want to use the MBR) is to stop GRUB from installing itself to the MBR on any operating systems that you don't want to install GRUB from. The most trivial way to do this is probably to remove the grub package.

Another way would be to have your bootloader installed on a partition and boot from there, but that's not as common.

share|improve this answer
    
Will "removing the grub package" return the system to its previous state? Ie, do you know if grub keeps a copy of the original MBR for this purpose? –  goldilocks Jan 29 '13 at 11:24
    
It won't uninstall the MBR, if that's what you mean, but you will need to make sure that the GRUB installation you ultimately have is a working one (ie. it has /boot, etc). –  Chris Down Jan 29 '13 at 11:50
    
I'm a little confused then. You wrote, "the proper way to handle this is to stop GRUB from installing itself" and that the "way to do this is probably to remove the grub package" but if you are removing the grub package, then it has already installed itself to the MBR... –  goldilocks Jan 29 '13 at 11:59
1  
@goldilocks You install the GRUB bootloader from your preferred operating system first, and then remove the GRUB package from the others. –  Chris Down Jan 29 '13 at 12:02

Ideally you should only install grub once and manually add entries for each new distro that you install.

One way to figure out would be to see the monitor when your computer boots up, there is generally a distribution specific message.

Even if that isn't the case you could make the changes in any distro that you are currently using and then update grub, this will update the grub menu after which you could do a grub-install to the mbr.

Also this answer tells you how you can find where the different grub stages are.

share|improve this answer

Ideally, as nikhil says, "you should only install grub once" then "manually add entries for each new distro that you install", or even more ideally, have fresh installs prompt for the location of your grub files and add their own entry; I think some distros can do this.

Unfortunately, it is not always that simple, particularly if you are messing around with trying new distros you are unfamiliar with, etc. etc., and once your MBR is overwritten you must deal with the tedious task of re-installing your old grub. The MBR is the physical first half kilobyte of the disk (aka. the boot sector), loaded and executed by the PC BIOS (read more), and that's where grub starts, but it then loads more stuff from a partition (eg, the stuff you might find in /boot/grub2/i386-pc).

So, here's a quick hack/shortcut to dealing with the whole issue: before you install a distro, copy your MBR out. Let the installer do whatever it wants without any fuss, then afterward, 1) put your MBR copy back onto the boot sector, 2) add an entry to the appropriate grub menu.

Step #1 is quite simple, and is in fact a good idea whenever you do an install in case something gets screwed up and you just want to go back to where you started. Beware this does not apply to new Windows formatted UEFI/GPT disks. The boot sector containing the MBR is exactly 512 bytes:

dd if=/dev/sda of=mbr.copy bs=512 count=1

"/dev/sda" should be the physical disk the MBR is on. Notice this is not "/dev/sda1", which refers to the first partition on /dev/sda.

Do your install and boot into the new system. You can then mount where ever you put your MBR backup, and:

dd if=mbr.copy of=/dev/sda bs=512 count=1

Presto! Reboot, and it's like that new install never happened. It is still there in its partition, however, and all you have to do is step #2 add a grub menu entry for it to your old grub menu.

Step 2 is the harder bit, because it requires you scrutinize the /boot/grub2/grub.cfg on both partitions and decide how to add the new entry. First, make a backup copy of grub.cfg as is. You should be able to just cut n' paste the entries straight out, but beware if they reference some function that is defined in the file, eg:

    load_video
    insmod part_msdos

Looking at the rest of grub.cfg, it is implicit that the second line is a grub built-in function, but the first one, load_video is defined further up:

function load_video {
    [...]

So remember to include that definition if you include a reference to it. Don't be too scared of experimenting here, if it doesn't work, you can still boot your old system and start asking more specific questions ;). Worst comes to worst and you completely screw up grub.cfg, boot a live CD and replace it with the back-up copy you made.

share|improve this answer
    
The MBR is the first half kilobyte (not megabyte) of data on the disk. Wikipedia And of course, your dd command will copy 512 bytes, not 512 KiB or KB. –  Michael Kjörling Jan 29 '13 at 12:42
    
WHOOPS! Must get coffee...changed "mega" to "kilo" and "kb" to "bytes". The dd was correct, as you say. I do do this myself, btw ;) –  goldilocks Jan 29 '13 at 12:50

I recommend installing a single version of Grub in your boot sector, the one from your most stable distribution. If you have other operating systems, install their bootloader in the first sector of their own partition and chainload it from the boot Grub. That way, you'll always have a bootable system, and all upgrade mechanisms will work as designed.

Grub's setup scripts are capable of detecting kernels from other Linux installations as well. That's a nice extra, but it is prone to break, for example after you've upgraded a kernel but not booted the main operating system. So use that facility only in addition to chainloading.

(But really, who dual boots nowadays? With virtual machines, you can run all your OSes at the same time!)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.