grub2 embedding is not possible

Well it seems it’s finally time to move my gentoo machine away from “grub legacy” and over to grub2.

All was going well following the official instructions until after reboot and running the install to replace the MBR.

grub2-install /dev/sda

At which point it spat out the error below.

/usr/sbin/grub2-bios-setup: warning: your core.img is unusually large.  It won't fit in the embedding area.
/usr/sbin/grub2-bios-setup: error: embedding is not possible, but this is required for RAID and LVM install.

It turns out this is because the disk partion was created when it started at the 63rd sector, recently limitations were found with this and it’s increased to 2048 in most distros.

Here’s what sfdisk -d /dev/sda gives.

# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 63, size= 39070017, Id=fd, bootable
/dev/sda2 : start= 39070080, size= 3919860, Id=82
/dev/sda3 : start= 42989940, size=543077325, Id=fd
/dev/sda4 : start=586067265, size=1367452800, Id= 5
/dev/sda5 : start=586067328, size=1367452737, Id=fd

Fortunately I use raid1 so I can kill a disk and rebuild it, it’s also possibly part of the reason I have the problem in the first place.

I failed and removed each of the partitions on this disk from the raid arrays, and turned off the swap partition. This leaves me with a disk that is not used in any way and I can manipulate the partition table with ease.

Luckily I put the swap partition in 2nd place, I’m going to sacrifice swap space to move the start of the first partition up by 1985 to set it at 2048.

I re-ran the above sfdisk command outputting to a text file (diskpart.txt)

I then edited it to look like below.

# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 2048, size= 39070017, Id=fd, bootable
/dev/sda2 : start= 39072065, size= 3917875, Id=82
/dev/sda3 : start= 42989940, size=543077325, Id=fd
/dev/sda4 : start=586067265, size=1367452800, Id= 5
/dev/sda5 : start=586067328, size=1367452737, Id=fd

Here’s the differences if you can’t spot them.

  • sda1 starts at 2048 (+1985)
  • sda2 starts at 39072065 (+1985)
  • sda2 size is 3917875 (-1985)

What I’ve done here is reduce the size of sda2 and shifted sda1 up, to give me a start point on the disk of 2048.

Up to this point I’ve only modified a text file and not the actual partitioning, so it’s time to do that.

cat diskpart.txt | sfdisk /dev/sda</code></pre>

This shows the old partion table and the new.

Checking that no-one is using this disk right now ...
OK

Disk /dev/sda: 121601 cylinders, 255 heads, 63 sectors/track
Old situation:
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+   2431    2432-  19535008+  fd  Linux raid autodetect
/dev/sda2       2432    2675     244    1959930   82  Linux swap / Solaris
/dev/sda3       2676   36480   33805  271538662+  fd  Linux raid autodetect
/dev/sda4      36481  121600   85120  683726400    5  Extended
/dev/sda5      36481+ 121600   85120- 683726368+  fd  Linux raid autodetect
New situation:
Units: sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1   *      2048  39072064   39070017  fd  Linux raid autodetect
/dev/sda2      39072065  42989939    3917875  82  Linux swap / Solaris
/dev/sda3      42989940 586067264  543077325  fd  Linux raid autodetect
/dev/sda4     586067265 1953520064 1367452800   5  Extended
/dev/sda5     586067328 1953520064 1367452737  fd  Linux raid autodetect
Warning: partition 1 does not end at a cylinder boundary
Warning: partition 2 does not start at a cylinder boundary
Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

One thing to note here is that the partion and cylinder boundaries don’t match up.

Adding the partitions back into their arrays, mkswap and turning on the swap partition give me a bit of time to wait for the re-sync to finish and I should halfway through this update.

Once the raid array is in sync I then turn off swap on sdb, drop the drives from the array and then mirror sda’s partition onto sdb.

sfdisk -d /dev/sda | sfdisk /dev/sdb

There’s no need to recalculate the partition table as I have both drives setup with identical partitioning.

Add the disks back into the array, sort swap out and a re-sync wait again.

Running the grub2-install command again produces no errors installing to both drives.

# grub2-install /dev/sda
Installation finished. No error reported.
# grub2-install /dev/sdb
Installation finished. No error reported.

Give the machine one final reboot to make sure that it’s loading grub2 immediately rather than going through the grub pre-load and you’re all done.