Ubuntu – Install GRUB to Ubuntu Partition

biosgrub2partitioning

So my computer has the following partitions:

/dev/sda — (I know this isn't a real partition, but more so the boot loader)

/dev/sda1 — (Windows 7 Boot Loader)

/dev/sda3 — (Windows 7)

/dev/sda4 — (Data partition, NTFS)

that means i have
/dev/sda2 as free space.

I do not want to change the MBR of the computer. I would like /dev/sda2 to contain GRUB AND Ubuntu. So ideally when I turn my computer on, BIOS would ask if I'd like to boot Windows 7 or Ubuntu(or Grub or partition 2), and I could choose either one. But I would like Grub and Ubuntu to be on the same partition, so they will not interfere in any way with windows or window's boot loader/partition (sda3)

How can I do this?

Catch: when formatting partitions, Ubuntu does not give me the option to make them virtual partitions, so that makes things harder.

I tried: installing Ubuntu to /dev/sda2 (which I formatted as ext4) and then told the Ubuntu installer to install the bootloader to /dev/sda2. But when I select "Ubuntu" from BIOS's boot selection, it loads a black screen and says "invalid arch independent ELF magic

grub rescue> _" and allows me to input stuff. How can I fix this, or tell my computer where Grub is?

Best Answer

BIOS is not smart enough to ask you about partitions, in fact, it knows nothing about partitions. From the BIOS point of view, your disk is just a sequence of 512-byte sectors.

When BIOS is ready to pass the control to the bootloader, it just reads the first 512 bytes from the disk and just blindly passes the control to whatever program is located at the predefined position in that data. It is the job of that program (MBR bootloader) to load the OS (this usually involves loading a more complex bootloader program from some other location on the disk).

Point is - it is your bootloader, stored in MBR, which is aware about partitions and stuff. You may have a Windows bootloader there or GRUB. If you find a way to configure the Windows bootloader to pass control to GRUB which is installed on /dev/sdaX then your schema would work although I never heard of anyone doing this. Windows is not very concerned about being able to load other OSes, you know.

It is possible to do what you want if you have two hard drives in your machine - just install Windows on one and Ubuntu on another, and switch between them in BIOS. Or, I don't know, maybe it is possible to put GRUB on a flash drive? That actually would be cool - if the drive is unplugged Windows would boot, if you plug the drive in then Ubuntu would boot (provided that "boot from USB" comes first in the list of boot devices) .