Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a multiboot system that I would like to use Grub to manage. The version of Grub shipping with my Linux distro is Grub2, and it installs its equivalent of stage 1.5-2, core.img, into the remaining sectors on the first track after the MBR but before the first partition. Unfortunately, those sectors are needed by another program.

I have a separate primary /boot partition. If I could only keep boot.img as my MBR but have it look in the /boot partition for core.img rather than the embedded one in the sectors immediately following the MBR, everything would work fine. Is this possible with grub2?

share|improve this question
    
seems like it should be possible. since grub can chainload grub, you might need to fully install grub to the partition boot sector; then you might get away with installing just the stage1 code to the MBR. not sure about this exactly, will need to research more. –  quack quixote Feb 10 '10 at 5:48
    
What sort of application needs to address sectors outside a partition? Is it some sort of ridiculous DRM or antipiracy element to an app? –  Alexander Burke Mar 13 '10 at 7:12
    
Putting any sort of code in the no-man's land preceding the 1st partition is just plain nuts, and certainly one of GRUB's biggest failings. –  kreemoweet Apr 22 '12 at 4:24
    
@kreemoweet: Except that zone is "reserved for boot operations". This is also where TrueCrypt stores its encryption key. Any program which is not required to boot should not ever corrupt this area. –  BatchyX Dec 31 '12 at 14:40

2 Answers 2

It is possible to configure GRUB2 in BIOS mode to boot from a partition without embedding into the area after the MBR, but there are some complications:

  1. You must have /boot on a plain partition (it may be a primary or logical partition, but must not use software RAID (md) or LVM). A separate partition for /boot is not absolutely required, but if /boot is stored on the root filesystem, the same partition restrictions will apply to the root filesystem partition.

  2. The filesystem used for /boot must support blocklist installation mode. Most commonly used Linux filesystems support this; important exceptions are btrfs and xfs (however, btrfs has a large enough bootloader area to embed core.img there, so installing GRUB2 there could still work). Again, if you do not have a separate partition for /boot, these restrictions will apply to your root filesystem.

    The blocklist installation mode is not recommended by GRUB2 developers, because in this mode core.img is stored in the /boot filesystem as a plain file, but actually it is accessed using sector numbers stored in the partition boot sector generated by GRUB (and in core.img itself), therefore doing any file operation on this file may break booting. This is another reason to have separate /boot partition when using this mode — there is less chance that you do some filesystem operation that will affect core.img.

  3. If /boot is on a logical partition, you must have some means to start the bootloader code from the partition boot sector — many versions of MBR code support booting only from primary partitions. One solution is to use the MBR code from Syslinux, which supports booting even from logical partitions.

Suppose that your /boot partition is /dev/sda2; then you should install GRUB2 there with the following command:

grub-install --force /dev/sda2

You need to use the --force option, because recent GRUB2 versions refuse to use the blocklist installation mode without it.

Then you should use fdisk /dev/sda to mark the partition 2 active.

Finally, if you had some non-default boot code in the MBR (e.g., an older GRUB installation), you need to install code which loads the boot sector from the active partition — e.g., you can take mbr.bin from Syslinux:

dd bs=440 count=1 conv=notrunc if=mbr.bin of=/dev/sda

When using a logical partition for /boot, you may also consider using altmbr.bin from Syslinux, which takes the boot partition number from a byte in MBR instead of looking for the active partition, so that any non-Linux operating system you have on the computer will not be confused by a logical partition marked as active.

share|improve this answer

As far as I can see it is not possible to configure Grub2 such that the code in the MBR looks anywhere other than the next sector for its core.img.

You can, however, load all of Grub into your /boot partition. This saves the need to meddle with any of the data stored at the beginning of the disk. By default the code in the MBR will find the active partition and transfer control to the first sector of that partition. If you require a suitable MBR there is one shipped with Syslinux.

This does presume that your /boot partition is a normal primary partition.

share|improve this answer

Your Answer

 
discard

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