2

I'm trying to implement some unusual idea on my PC.

I've got a total of 6 partitions:

  • First one is for Windows 7 (my basic OS)
  • 2nd one for Ubuntu
  • 3rd and 5th are Windows storage partitions
  • 4th is a /home for Ubuntu
  • and 6th is a recovery partition with some extreme-case tools.

My idea looks like this:

  • Windows is the default boot option
  • Ubuntu is bootable both natively and inside Windows-hosted VM
  • GRUB2 can launch some tools from the last partition

So far it works just fine. My MBR and 1st BS are untouched, Windows-default sectors. 2nd BS has GRUB2 installed, which is used to launch Ubuntu. There are also GRUB4DOS and memdisk on the last partition, which are chainloaded from Grub2win. VM has a virtual drive connected with GRUB on it, so the Ubuntu partition is bootable.

So booting looks like this:

  • Windows: MS BootMgr -> Windows 7 (default)
  • Ubuntu: MS BootMgr -> Grub2win -> GRUB2 -> Ubuntu
  • Tools: MS BootMgr -> Grub2win -> GRUB4DOS -> (some other tools)

What I want to achieve is make (some) GRUB2 virtually the first boot manager to start, preferably the current Grub2win. Perfect scenario would be:

  • Windows: static GRUB2 -> MS BootMgr -> Windows 7 (default)
  • Ubuntu: static GRUB2 -> Ubuntu's GRUB2 -> Ubuntu
  • Tools: static GRUB2 -> GRUB4DOS -> (tools)

The problem is I have no idea how to install another, independent GRUB2 or how to make Grub2win my default boot manager (if I get it right, it's not even possible).

Setting BootMgr's timeout to 0 and making Grub2win its default boot option would make Grub2win virtually the first, but then it would be impossible to launch Windows. Solution would be to launch Windows directly (without BootMgr), but as far as I know, it's not possible.

However, Ubuntu seems to do that with it's GRUB2 - it's just skipping over BootMgr and booting Windows. I've tried copying that entry from /boot/grub/grub.cfg to Grub2win's config, but then it didn't work that way - just launched BootMgr.

Reason why I don't want to use Ubuntu's GRUB is that every time update-grub is run inside a VM, Windows is gone from the list. It happens because VM only has access to two Linux partitions, so there's no Windows partition visible for virtualized Ubuntu.

So, for now my point is to launch Windows directly from Grub2win the way Ubuntu's GRUB2 does it. Can you guys help me?

Edit: Few more things to consider:

  • GRUB4DOS is an integral part of some tool set, so it's basically untouchable. I don't want to do any additional work on each update of the tool set.
  • I need some way to boot from ISO images - currently I'm using Grub2win + memdisk.
  • Ubuntu GRUB's menu is exactly the same when chainloaded and on VM. As the VM has only 2 Ubuntu partitions connected, I want only Ubuntu-related options in that menu.
0

2 Answers 2

4

I see what you're trying to do (one-level boot menu, instead of two separate menus) and would like to propose an alternate solution to the same effect:

Keep bootmgr the main menu, don't set timeout to zero. Use EasyBCD to add two separate entries: an Ubuntu entry and a GRUB4Dos entry (EasyBCD has its own copy of Grub4Dos called NeoGrub).

Make sure to erase everything but Ubuntu from Ubuntu GRUB's menu. Configure EasyBCD's NeoGrub menu to mimic your existing Grub4Dos menu.

You'll have a single-level menu where you can boot into Windows, Ubuntu, or GRUB4Dos.

You will never have to update Grub4Dos/NeoGrub and your boot will work through Ubuntu upgrades and kernel upgrades without needing to modify a thing.

3
  • Thanks for your reply. I haven't heard of NeoGrub before, it looks promising, but unfortunately there are some aspects I didn't mention. (I've just added those to the question)
    – gronostaj
    Commented Feb 2, 2013 at 2:05
  • @gronostaj See my update. NeoGrub is Grub4Dos (they used to be separate, have since been merged). You won't need to change a thing. Will not break when you upgrade kernel, etc. Commented Feb 2, 2013 at 3:56
  • NeoGrub did the job. In BootMgr I can choose between Windows and NeoGrub, then in NeoGrub there are options for booting Ubuntu, some ISOs and configfile-ing menu.lst from the last partition. VM still has GRUB2 working, so everything's perfect. Thanks a lot!
    – gronostaj
    Commented Feb 2, 2013 at 9:08
3

The problem is I have no idea how to install another, independent GRUB2

Installing an independent GRUB2 is straight forward (for always having it point to the current Linux/Ubuntu Kernel, see my question).

Make enough backups (dd is your friend) before you start!

[I want this post to be plain and easy, so everybody who is not familiar with the GRUB configuration can use it to install an independent GRUB. If anyone has suggestions on how to improve this post, please let me know.]

Create a separate boot partition where you will install GRUB2 and nothing else. It will not be mounted on any operating system that you have installed, it's only used for selecting the first system. You might eventually have to do some some rearrangements (moving partitions around to make space or maybe even destroy and recreate them in different order). I like to have my GRUB partition to be the first partition on the disk (or the second, after the BIOS partition if using GPT), 50 MB in size (could be 5, but hdds are large). Install all the operating systems first, because they'll overwrite the MBR. Do NOT use /dev/sda1 in any operating system.

Boot some live system that comes with GRUB2 tools. I recommend Parted Magic (which you can also use for all your partitioning).

  • Be careful not to type sda2 instead of sda1 or something. You can easily wipe your hdd clean with one typo (of course you have a full backup, so nothing would be lost).
  • Format /dev/sda1 with ext2.

mkfs.ext2 /dev/sda1

  • Mount GRUB partition and install GRUB2:

cd /mnt

mkdir sda1

mount /dev/sda1 sda1

grub-install --boot-directory=/mnt/sda1 /dev/sda

  • "Installation finished, no error reported."

cd sda2

ls

  • "grub/ lost+found/"
  • Create a new menu config manually (it's also possible to have GRUB generate one).

vi grub/grub.cfg

menuentry "Windows 7 (loader)" --class windows --class os {

insmod    part_msdos

insmod    ntfs

set       root='(hd0,msdos2)'

chainloader +1

}

menuentry 'Debian (or Ubuntu)' {

insmod    part_msdos

insmod    ext2

set       root='(hd0,msdos3)'

echo      'Loading Linux...'

linux     /boot/vmlinuz root=/dev/sda6 ro quiet <- current vmlinuz file name

echo      'Loading initial ramdisk...'

initrd    /boot/initrd.img <- current initrd.img file name

}

menuentry 'Fedora (just another example)' {

insmod    part_gpt

insmod    ext2

set       root='(hd0,msdos3)'

echo      'Loading Linux...'

linux     /boot/vmlinuz-3.7.3-101.fc17.x86_64 root=UUID=[UUID of /dev/sda3] ro rd.md=0 rd.lvm=0 rd.dm=0 SYSFONT=True  KEYTABLE=us rd.luks=0 LANG=en_US.UTF-8

echo      'Loading initial ramdisk...'

initrd    /boot/initramfs-3.7.3-101.fc17.x86_64.img

}

  • I've tried this with Parted Magic 11.11.11 (lucky version number), the GRUB tools on there created only the "grub" directory on /dev/sda1. A different version might create a "grub2" directory. Either way, you put your GRUB2 configuration file in there (GRUB2 looks like a Shell script, in GRUB1, it was a simple menu.lst, but that's way back).
  • Replace "[UUID of /dev/sda3]" with what ls -l /dev/disk/by-uuid | grep sda3 tells you.
  • Replace "/boot/vmlinuz" with the real file name (in /dev/sda3, your Linux partition).
  • Replace "/boot/initrd.img" in the same way.
  • Unmount and reboot. Your computer will boot a simple GRUB2, listing the entries you have specified ("Windows 7 (loader)", "Debian (or Ubuntu)"). If you've done it right, you'll be able to boot both Windows and Linux directly from that independent GRUB.
  • Again, the Linux entry points to a specific Kernel version. It would have to be manually updated (mount /dev/sda1 and modify grub/grub.cfg), which is a major drawback. Again, see my other question about setting up GRUB for that.

(lol, superuser removed every instance of the word "have")

2
  • Thanks for your detailed answer, it may come in handy one day. Just one tip: Ubuntu (and maybe some other distros too) will create links to the latest kernel and initrd on each update, so it's even easier to boot it.
    – gronostaj
    Commented Feb 11, 2013 at 18:22
  • Oh, that'll probably solve the problem for Ubuntu. I hope this post will be helpful for someone. Feedback is welcome.
    – basic6
    Commented Feb 11, 2013 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .