Automatically adding other distributions to Fedora Grub using os-prober


Recently I decided to play a little with Fedora’s Grub2 to see how it works. Fedora Grub2 package does not replace Grub1 and adds itself to its menu, so it is safe to install.

It is clear that Fedora is not ready to switch to Grub2 currently (while it is not much work to do so), since the grub2 menu of it is not polished at all: a simple black background, and Fedora menu entries appear as “GNU/Linux, with Linux VERSION”. Well, both are just a very simple polish work, one of them is tracked here.

I was surprised to see that other installed operating systems, like my Windows and the other installed Fedora was not added to Grub2’s menu. It is generally the task of grub2’s /etc/grub.d/30_os-prober script. I was surprised to find out that this script depends on os-prober for detecting other operating systems, which is a tool developed for Debian installer and is not available in Fedora. Therefore, I decided to package it and it is up for review here, waiting for someone to approve it! ;) Also, it is clear that grub2 package should depend on it, so a bug report is created for it too.

But there is nothing in os-prober to make it useful only for grub2. Fedora is currently using grub1 and there is no clear plans for migrating to grub2 currently, and there are people who are frustrated when find out that Fedora is unable to automatically detect and add other installed Linux distributions to its Grub menu, which is also reported here. So, I decided to modify grub2’s os_prober script to generate menu entries for Grub1, and the result is available here. If you’ve installed os-prober, you can run this script and it should generate grub1 menu entries for other operating systems installed on your system (Windows and other distribution installations). However, I’m not sure if it generates correct entries for all systems, specially as it currently depends on /boot/grub/device.map to convert Linux device names to grub names. The script outputs the results to standard output and doesn’t modify your grub.conf directly, so you can try it safely.

An example output of this script is like this:

title Windows Recovery Environment (loader) (on /dev/sda1)
        rootnoverify (hd0,0)
        chainloader +1
title Windows Vista (loader) (on /dev/sda2)
        rootnoverify (hd0,1)
        chainloader +1
title Parsidora (2.6.35.11-83.fc14.x86_64) (on /dev/mapper/VolGroupLaptop-lvroot2)
        root (hd0,2)
        kernel /vmlinuz-2.6.35.11-83.fc14.x86_64 ro root=/dev/mapper/VolGroupLaptop-lvroot rd_LVM_LV=VolGroupLaptop/lvroot rd_LVM_LV=VolGroupLaptop/lvswap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
        initrd /initramfs-2.6.35.11-83.fc14.x86_64.img
title Fedora 15 tmp Installer (on /dev/mapper/VolGroupLaptop-lvroot2)
        root (hd0,2)
        kernel /vmlinuz askmethod
        initrd /initrd.img
title Fedora (2.6.38-0.rc5.git1.1.fc15.x86_64) (on /dev/mapper/VolGroupLaptop-lvroot2)
        root (hd0,2)
        kernel /vmlinuz-2.6.38-0.rc5.git1.1.fc15.x86_64 ro root=/dev/mapper/VolGroupLaptop-lvroot2 rd_LVM_LV=VolGroupLaptop/lvroot2 rd_LVM_LV=VolGroupLaptop/lvswap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
        initrd /initramfs-2.6.38-0.rc5.git1.1.fc15.x86_64.img
title GNU GRUB 2, (1.98) (on /dev/mapper/VolGroupLaptop-lvroot2)
        root (hd0,2)
        kernel /grub2/core.img

About these ads

39 responses to this post.

  1. Posted by mohsen on March 2, 2011 at 7:38 am

    great tip dude, tnx a lot!

    Reply

  2. I tried to install the SRPM but I got the following error:

    mahdi@mahdi-TECRA-A8 Downloads$ sudo rpm -Uvh os-prober-1.42-2.fc14.src.rpm
    1:os-prober warning: user hedayat does not exist – using root
    warning: group hedayat does not exist – using root
    warning: user hedayat does not exist – using root)
    warning: group hedayat does not exist – using root
    ########################################### [100%]

    Reply

    • This is OK. However, installing an SRPM only extracts the .spec file and the source .tar.gz file (when running as root, they’ll be installed under /usr/src IIRC).
      You should either install an appropriate RPM, or you should first build the src.rpm with rpmbuild and then install the resulting rpm packages. (e.g. rpmbuild -bb os-prober-1.42-2.fc14.src.rpm).

      Reply

  3. Posted by VastOne on May 5, 2011 at 4:02 am

    Hedayat,

    I am using Fedora 15 without legacy grub. I came over from Ubuntu and kept the Grub 2 on sda1 and use it but I want to eliminate it eventually..

    My question is do I install grub2 first and then build the os-prober? I want to be able to test this for you and hope that it will be a step in the direction needed to bring grub2 to all of Fedora.

    Whatever your needs may be, feel free to contact me via email to discuss..

    Thank you

    Reply

  4. Well it seems that the package has been approved: https://admin.fedoraproject.org/updates/os-prober-1.46-2.fc15

    Great job Hedayat!

    Reply

  5. Posted by VastOne on May 6, 2011 at 3:37 am

    sudo os-prober to run? I have it installed but have nothing supporting it in documentation… that I know of

    Reply

    • Yes, you can run os-prober as root to see its output. But, if you want it to be used by grub2 for menu generation, you don’t need to do anything! If you install grub2 after installing os-prober, it’ll automatically use it to generate correct menu entries for other installed operating systems. If you have installed grub2 before, all you need to do is to tell it to generate its config file again: grub2-mkconfig

      For grub 1, you can use my script mentioned in the post.

      Good luck
      Hedayat

      Reply

  6. Posted by VastOne on May 7, 2011 at 5:04 am

    I also had to run

    sudo grub2-install –grub-setup=/bin/true /dev/sda

    to set it up as a replacement for my Ubuntu Grub2 installation that was already there..

    One issue is that every thing is labeled the same

    GNU/Linux, with Linux 2.6.39-0.rc4.git2.0.fc15.x86_64

    GNU/Linux, with Linux 2.6.38.5-22.fc15.x86_64

    for Fedora entries coming from

    /etc/grub.d/10_linux

    but the Ubuntu ones coming from

    /etc/grub.d/30_linux

    are showing correctly

    Ubuntu, with Linux 2.6.38-020638-generic (on /dev/sda1)

    Also, do you know if something like this will work now

    menuentry “Daily on sda13″ {
    set root=(hd0,13)
    linux /vmlinuz root=/dev/sda13 ro quiet splash
    initrd /initrd.img
    }

    Where that entry in /etc/grub.d/40_linux

    would boot the latest entry it finds in /boot..

    Great job on this!!! I can slip further away from Canonical now…

    I really appreciate it

    Reply

    • I have talked about the issue in the blog post, and a bug report (including the solution) is already filled (the first link in the post0: https://bugzilla.redhat.com/show_bug.cgi?id=678453

      AFAIK, the mentioned entry would only work if the latest kernel and initrd/initramfs are correctly linked to by vmlinuz and initrd.img symlinks. And Fedora doesn’t create any links for the latest kernel and initramfs itself, so you should do it manually so that the entry will work as expected.
      :) Thanks

      Reply

      • Posted by VastOne on May 7, 2011 at 10:31 pm

        I apologize Hedayat, I missed that completely …

        Adding

        GRUB_DISTRIBUTOR=$(sed “s/.*(\(.*\))/\1/” /etc/system-release)

        to /etc/default/grub solves this? Does it replace the current line of

        GRUB_CMDLINE_LINUX=”quiet rhgb”

        Or is it added to it?

        Thanks again…

      • Posted by VastOne on May 7, 2011 at 10:46 pm

        I tried adding

        GRUB_DISTRIBUTOR=$(sed “s/.*(\(.*\))/\1/” /etc/system-release)

        But got an error when re-running grub2-mkconfig…

        /etc/default/grub: command substitution: line 2: syntax error near unexpected token `(‘

        I will wait for it to be added upstream… (hopefully) :-)

      • No, it does not replace the current line. Just add it in a new line.

      • About the error: you have copied the line from web, and the problem is that the double quotes you pasted in the file are NOT double quotes, but another character. Please replace “ and ” in the mentioned line with double quotes typed using keyboard (“).

      • Posted by VastOne on May 7, 2011 at 11:09 pm

        Arrrgghhh

        I should have seen that…

        Thank you and sorry for the alarm it worked perfectly….

  7. Posted by VastOne on May 7, 2011 at 5:09 am

    One other thing I wanted to say…

    For the first time ever, in all the failed attempts in Ubuntu, to the Fedora 15 drone scroll…

    Plymouth works PERFECTLY!!!!

    Well Done!!!

    Reply

  8. Posted by VastOne on May 8, 2011 at 8:44 am

    I have put together a How-To on the Fedora Forums here

    http://forums.fedoraforum.org/showthread.php?t=262670

    Please leave me a note for anything you want added or changed

    Reply

    • Thanks for the post. A few notes about it:
      os-prober is now in updates-testing repository and can be installed from there. Also, it will be moved to updates repository soon (Unfortunately your karma for the update is ignored since you were not logged in there).

      I have never installed grub2 on mbr. Why grub-setup is set as /bin/true? Can’t grub2-setup be used there?!

      Also, in the default grub2 setup in Fedora (grub2 as a menu entry in grub1), /boot/grub2/grub.cfg is updated when a new kernel is installed. Isn’t it true when you install grub2 in MBR?

      Unfortunately, grub2’s maintainer has been silent for a long time. Maybe we should do something about it…

      Reply

      • Posted by VastOne on May 8, 2011 at 6:00 pm

        I fixed the karma by logging in and reposting

        I fixed the post to reflect that, it now just says to

        sudo yum install os-prober

        as step 1

        I had grub2 already installed and when I installed the new, nothing happened to my existing grub2

        I corrected the post to take out the –grub-setup=/bin/true

        grub.cfg should be updated when a new kernel is installed. I have that there as a failsafe if it does not pick up a new kernel

    • Posted by VastOne on May 8, 2011 at 6:40 pm

      I had to leave

      sudo grub2-install –grub-setup=/bin/true /dev/sda

      in there for now…

      I tried to install grub2

      sudo grub2-install /dev/sda

      and all I got was a grub command line and had to reinstall grub to sda1 from a livedcd

      What am I missing in that step?

      Thanks

      Reply

      • Posted by VastOne on May 8, 2011 at 8:17 pm

        I added the correct step to install grub2 to the mba

        sudo grub2-install /dev/sda

        This is tested… and is correct..

      • Thanks a lot. Just wondering what was the problem in your previous post with grub2-install which caused getting at a grub command line?

      • Posted by VastOne on May 8, 2011 at 8:40 pm

        Honestly, I am not sure…

        The only thing different I did was not running

        sudo grub2-mkconfig -o /boot/grub2/grub.cfg

        after I installed it to mba

        I am now working on getting updated to grub 1.99~rc2

      • Posted by VastOne on May 8, 2011 at 11:50 pm

        Got grub2 1.99~rc2 up and functioning perfectly with os-prober

      • Happy to hear that :)

      • Posted by VastOne on May 9, 2011 at 7:23 pm

        Additional note:

        If you compile grub2 1.99~rc2 you must create

        /usr/local/etc/default

        and then you must copy the file grub from /etc/default to /usr/local/etc/default

  9. Posted by Quintesse on May 12, 2011 at 12:04 pm

    Sorry for resurrecting this thread, I just came across it. But I just wanted to know something: wouldn’t it be possible to just include the os-prober in grub itself?
    There have been many times that fooling around with things I left my system unbootable and although it isn’t too hard to fix it I always wondered why the bootloader couldn’t just try to detect what’s on the drives?

    Reply

    • That’s fine! :)
      If your system is unbootable, in many cases it is because grub cannot find its boot partition. In this case, having os-prober in grub won’t help since it’ll not find its os-prober too (the initial part of grub which is loaded at first is very small and cannot include such extra stuff).
      However, if Grub is OK (you can see the boot menu, but you cannot boot), it is possible to use os-prober in that cases as a recovery method. You might propose it to Grub2 development team. That is indeed a great feature.

      Reply

  10. [...] interesting features. One of them is auto-detecting other installed OSes using os-prober (as I have written here, you can do the same for Legacy Grub using my script). This means that now Fedora will detect other [...]

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 671 other followers

%d bloggers like this: