Fedora 16 / Windows 7 - Dual booting with GRUB2

Fedora 16 was released almost a month back. This is the first Fedora release to have switched to the GRUB2 boot loader. I had some trouble installing Fedora 16 - the boot loader won't get installed on my MBR since there wasn't enough space to accommodate the boot image. The details of my struggles can probably be the subject of another post. Here, it must suffice to say that I had nuked my first partition, containing Windows 7, to make sufficient space (unallocated sectors) at the beginning of the HDD for grub2 boot image.

After installing F16, I reinstalled Windows 7 on to the first partition on the HDD. Everything was fine, except, unsurprisingly, that it replaced grub2 boot loader with its own.

Getting back grub2 to boot Fedora was a matter of doing this:
  1. Boot using Fedora 16 DVD
  2. Select 'Troubleshoot' and use the 'rescue mode'
  3. Let Anaconda autodetect existing Linux installations, and when prompted, select your F16 installation from among the multiple existing installations
  4. Read the message that says the partition has been mounted under /mnt/sysimage and I could do: chroot /mnt/sysimage if I wanted
  5. Do exactly that:
    chroot /mnt/sysimage
  6. Reinstall GRUB2 on to my MBR:
    grub2-install /dev/sda
  7. Reboot and viola! I was able to boot in to Fedora again :-)

That being said, should I be able to boot in to Windows 7 now? I wasn't! This one was a bit surprising since old grub-install used to auto-detect other operating systems and made everything work. Things have changed, and apparently for the worse!

After booting in to F16, I tried to get Windows entry in to GRUB2 menu. After reading a little bit, here's what I should've done:

  1. Make sure a package called os-prober is installed:
    yum install os-prober
  2. Back-up my existing grub.cfg file
    cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
  3. Re-create the cfg file, hoping grub2 would autodetect Windows
    grub2-mkconfig -o /boot/grub2/grub.cfg
  4. Reboot and hope it works
It seems that the above four steps would've worked. If you reached this page after searching for a way to dual boot Fedora 16 and Windows 7, this is exactly what you should do.



As for me, I did a lot of other stuff:
  1. Assume that grub2 was unable to auto-detect Windows and I should do it manually
  2. Add the following entry in /etc/grub.d/40_custom

    menuentry "Windows 7" {
    insmod ntfs
    set root=(hd0,1)
    chainloader +1
    }

  3. Find the wrong grub2 configuration file at /etc/grub2.cfg and replace it with:
    grub2-mkconfig -o /etc/grub2.cfg
  4. Reboot and find that Windows entry is still missing
  5. Boot back in to Fedora and find that /etc/grub2.cfg indeed contains the entry for Windows
  6. Re-install grub2 in a desperate attempt:
    grub2-install /dev/sda
  7. Reboot and find that nothing has changed
  8. Search the internet and repeat steps 4-7 above without any use
  9. Again verify /etc/grub2.cfg and find that there are in fact two entries for Windows 7 - one that I added manually and one, wait for it, auto-detected by grub2 (os-prober)! Apparently, the assumption I made in step-1 was wrong and step-2 wasn't really necessary!
  10. Get back in to the reality that Windows entry is still missing in grub2 boot menu even though it appears in the cfg file
  11. Search more and stumble up on a bug report that indicates /boot/grub2/grub.cfg is the right grub2 file for Fedora!
  12. Do it  right this time with:
    grub2-mkconfig -o /boot/grub2/grub.cfg
  13. Reboot and find that everything's merry

Apparently, /boot/grub2/grub.cfg is the real file that grub2 uses. On Fedora, /etc/grub2.cfg is a symbolic link to /boot/grub2/grub.cfg.
But if that's the case, then everything should've worked when I used grub2-mkconfig to overwrite the file in /etc, right? Again, as my luck would have it, grub2-mkconfig is buggy in that it doesn't follow the symlink. It just replaced /etc/grub2.cfg with a real file - a file that nobody cares about!


So, if you find that the entries you very clearly see in the cfg file are missing in the boot menu, check if you're using the right cfg file.



Comments

  1. I have Fedora 16 on one hdd and Windows 7 on another each installed from scratch while the other was disconnected and wish this guide had been available earlier because what I ended up doing was steps 1-4 under "here's what I should've done" and they worked. (Actually, I did not do step 1 because some how os-prober was already installed.)
    My only worry was that the new grub.cfg had quite a few other differences mostly adds of recovery mode entries and showing for what its worth that kernel updates do not update grub.cfg by doing step 3.

    ReplyDelete
  2. i`m f*cked
    os-prober does not work for me

    f*ck computers

    ReplyDelete
  3. _THANK YOU_ this did the trick in under a minute, right after my neighbour scared me:).

    ReplyDelete
  4. @Anonymous (the one who got f*cked)
    Even if os-prober didn't work, you can try adding an entry manually.

    You should edit "/etc/grub.d/40_custom" and add an entry for Windows (scroll up to see how it's done) and then do: "grub2-mkconfig -o /boot/grub2/grub.cfg" to recreate the config file.

    ReplyDelete
  5. Thanks, it's very helpful, now I can boot Fedora again

    ReplyDelete
  6. "After installing F16, I reinstalled Windows 7 on to the first partition on the HDD."

    This is pretty much the error as I understand things. The recommendation is to install (any) Windows *first* then followed by Linux install. If you do things in the order you did them Windows tries to take over the bootloader resources for its ownself and won't play well with others. I have FC16 and Win7 dual booting and have no issues.

    ReplyDelete
  7. @John Glotzer
    The reason I had to renistall Windows is that my hdd didn't have enough free space in the beginning to hold the GRUB2 boot image. This was a pre-existing partition layout starting at sector 63. So, I had no other choice than to remove my Windows partition and re-create it with a sufficient offset.

    Having Windows replace grub with its own boot loader is a well known phenomenon. In such cases, I usually reinstall grub using the Fedora rescue mode. But Grub2 requires an additional step of running grub2-mkconfig on the proper grub file. That got me!

    ReplyDelete
  8. Ah OK - so grub2-mkconfig is your friend. Coincidentally, no more than a few minutes ago I saw a thread http://forums.fedoraforum.org/showthread.php?t=274562

    that made the exact same point!

    Thanks.

    ReplyDelete
  9. @John Glotzer

    Well, grub2-mkconfig gave me a hard time because it didn't follow the symlink the Fedora installation has:
    https://bugzilla.redhat.com/show_bug.cgi?id=743977

    Actually, that symlink is quite unnecessary, but the devs need that to support 'grubby'.

    ReplyDelete
  10. OIC - I see the overall point - I'll file this one away for future reference. Thanks.

    ReplyDelete
  11. Someboby help??? I wanted to dual boot windows xp and Fedora 16. I was running windows xp but later installed fedora 16 and after the install the grub only shows fedora 16 and i cant access windows OS anymore, how can i fix the problem.
    Peter

    ReplyDelete
  12. I have installed fedora 16 on my laptop. While doing this under fedora partition I clicked All setting and that cleaned my hard drive and had partition according to fedora 16. Then I tried to load window again so I can run dual OS, some how it does not work. Please guide me step by step to reinstall window 7 on Fedora16 on 32bits total hard drive 149GB 4.2Swap 50Gb partition used for fedora installation. Left with 96GB. Please suggest.... Regards,

    ReplyDelete
  13. @NeeruSharma
    Did you let Anaconda (that's the Fedora installer) partition your disk automatically? If that's the case, you probably have LVMs and stuff.
    Confirm if that's the case..

    ReplyDelete
  14. In 2012 that powerful OS that Linux is considered to be, still can't dual boot easily with Windows...

    ReplyDelete
    Replies
    1. @Anonymous
      This powerful OS can dual boot Windows out of the box. (Remember, Windows still can't!). I just didn't know the right command to ask it to detect other operating systems :-)

      Delete
  15. I have to admit, this is one time EFI was actually worth it. I have EFI boot entries for both Windows 7 and Fedora, and while it was a bitch to set up Fedora to boot from EFI at the time (I was using an older version, which didn't yet have GRUB2 supprot), it has survived updates, upgrades, the works. The reason is that EFI "preselects" whether or not to even make it to GRUB-- so by that point, GRUB's configuration is exceedingly simple. The same is true with the Windows boot manager.

    So, while EFI is indeed a huge hairy mess that feels like a gigantic distraction for people who just want their damned machines to boot, for crying out loud, indeed it is. However, if you can plod your way through GPT partition tables, the details of exactly what goes into that hidden 1MB partition on your drive, and the arcanities of the EFI filesystem "standards" (cough) and boot process, AND you have a modern enough motherboard with a BIOS that implements it all properly, you will give yourself a little more leverage.

    At the end of the day, the critical decision to make is this one: who do you want to own the boot process?
    Windows?
    Linux?
    The BIOS?

    The basic justification for the BIOS case is when the installed operating systems should be treated as equal peers.

    So folks, if time permits, give an EFI multiboot install a shot, and see what you think-- they're only going to get more common, and even if you have no intention of using one unless you have to, giving yourself a heads-up on the technology would be wise.

    ReplyDelete
  16. My copy of Fedora 16 doesnt have a choice of 'Recovery' under the 'Troubleshoot' selection... que paso?

    ReplyDelete
  17. @Anonymous
    I don't remember the boot screen exactly. But there's a 'Rescue mode' somewhere. In older versions, it would prompt you to type in a choice and you could enter "linux rescue" to begin the rescue mode.

    ReplyDelete
  18. Q: Who the fuck thought it would be a good idea to take a perfectly functional boot process - grub - and replace it with an overly complex, poorly documented and randomly implemented pile of crap called grub2?

    A: Someone with a small dick and "not invented here" syndrome?

    No it's not progress; it's fucking about for the sake of it.

    Q: Why the fuck does grub2 have version numbers like 1.99 (release candidate 3)? Do the upstream folks not think this is just a teensy bit confusing? grub2_v0.something_rc3 would make a lot more sense.

    Q: What's with the screwy disk/partition numbering/naming?

    Q: Why are distributions forcing this shite on their users? It may be the future but it's a long way from ready for prime time.

    ReplyDelete
  19. My live-usb Fedora 16 doesn't have a choice of rescue mode either. I installed Windows 7 after I already installed Fedora 16. But I made a copy of my MBR first:

    1) dd if=/dev/sda of=/home/arnaud.kleinveld/mbr.bin count=1 bs=512

    2) Installed Windows 7

    3) Boot from live-usb/cd, start terminal and make copy of Windows MBR:
    dd if=/dev/sda of=/home/arnaud.kleinveld/winmbr.bin count=1 bs=512

    4) I mounted my Linux partition to access the Linux MBR and wrote it back to sda with dd if=/home/arnaud.kleinveld/mbr.bin of=/dev/sda count=1 bs=512. But maybe you can run grub2-install /dev/sda here as well.

    5) Reboot. Should boot Linux again

    6) For fdisk to recognize the Windows 7 partition write back Windows mbr while running Linux:
    dd if=/home/arnaud.kleinveld/winmbr.bin of=/dev/sda count=1 bs=512

    7) Run fdisk -l /dev/sda and remember the windows partition number for the next step.

    8) Add the following entry in /etc/grub.d/40_custom as described by the article above. For me it was my third primary partition so I changed root to (hd0,3)
    menuentry "Windows 7" {
    insmod ntfs
    set root=(hd0,3)
    chainloader +1
    }

    9) grub2-mkconfig -o /boot/grub2/grub.cfg

    10) grub2-install /dev/sda..

    Reboot and check if Windows now appears in your menu.

    Arnaud Kleinveld

    ReplyDelete
  20. Thank you very much, your post helped me resolve / conf very quickly and without headaches and understand how it works. Thanks a lot!

    ReplyDelete
  21. I installed ubuntu on Windows 7 and don't remember how I did because it was so quick and simple. Looking at all comments about Fedora dual booting, I have the impression it is a terrible mess. Why did Fedora people not do a simple installation procedure like ubuntu ones?

    ReplyDelete
  22. @Anonymous ^^
    Oh not at all. Dual booting with Fedora is not a mess at all. It usually works right out of the box. I've been dual booting with all Fedoras till date and never had a problem
    The problem here was that Fedora 16 made a switch to new GRUB2 boot loader which requires more space at the disk beginning. So I had to install Windows *after* I installed Fedora. The mess was how to get back GRUB2 boot loader.

    ReplyDelete

Post a Comment

Popular posts from this blog

പേര്

Qt - Enabling qDebug messages and Qt Creator

ബിഗ് റേഡിയോ ഇതിഹാസം