After attempting to migrate to grub 2 on my gentoo machine, I hit the following problem when attempting to install it:
bpc steph # grub2-install /dev/sda
warning: your core.img is unusually large. It won't fit in the embedding area.
(I also had some other error following that, but I can’t recall what it was. Never mind. I don’t get it now after doing everything in these notes.)
After some digging around on the Internet I found that this was likely due to not having enough space before the first partition of my hard disk. Probably because grub2 was attempting to create a core with RAID and LVM support (my disks are RAID-1 with LVM with dm-crypt, thought the boot partition is only RAID-1). As with most people, my first partition started at sector 63. After freeing up 1M before theh first partition it now starts at sector 4096.
This is what I did to free up space before the boot partition - the first partition on my disk - restore the boot files and install grub 2. This required completely destroying then recreating /boot.
Note that I have /dev/md1 RAID-1 array mounted at /boot. The array consists of /dev/sda1 and /dev/sdb1, with /dev/sdc1 as spare.
- Backed up the contents of /boot.
- Backed up everything else! Best to be on the safe side when partitioning.
-
Stopped /dev/md1 array:
mdadm --stop /dev/md1
- Used gparted to free up an extra 1M at the start of the disk before the first partition. To do this I ran gparted on /dev/sda and /dev/sdb in turn (via e.g.
gparted /dev/sda &
) to reduce the size of /dev/sda1 and /dev/sdb1 by 1M and move them to the right (using the ‘resize and move’ option that you get when right-clicking on the partition.Resized and moved /dev/sda1, as explained above. -
Copied the partition table of /dev/sda to /dev/sdc:
sfdisk -d /dev/sda > part_table sfdisk /dev/sdc < part_table --force
-
Created RAID-1 array for /dev/md1.
mdadm –create /dev/md1 –level=1 –raid-devices=2 –spare-devices=1 /dev/sda1 /dev/sdb1 /dev/sdc1
-
Made sure /dev/md1 was stopped and then assembled it (simply because I wasn’t sure whether
mdadm --create ...
also started and/or assembled them.mdadm --stop /dev/md1 mdadm --assemble /dev/md1 /dev/sda1 /dev/sdb1 /dev/sdc1
-
Removed old ‘ARRAY …’ lines from the end of /etc/mdadm.conf and generated the new ones:
mdadm --detail --scan >> /etc/mdadm.conf
-
Created ext2 filesystem on /dev/md1:
mkfs.ext2 /dev/md1
-
Edited /etc/fstab to correct /boot entry (because I was previously using reiserfs and now I’m using ext2):
... /dev/md1 /boot ext2 defaults,noauto 1 1 ...
-
Tested that array starting and mounting worked.
mdadm --stop /dev/md1 mdadm --assemble /dev/md1 /dev/sda1 /dev/sdb1 /dev/sdc1 mount /boot
-
Copied backed-up boot files back in to /boot:
cp backup/boot/* /boot/. -r
-
Installed grub on all disks:
grub2-install /dev/sda grub2-install /dev/sdb grub2-install /dev/sdc
-
Removed old grub:
emerge -C sys-boot/grub:0
-
Configured grub2:
grub2-mkconfig -o /boot/grub/grub.cfg
-
Restarted computer:
shutdown now -r
It booted :-)