Resizing boot partition to install grub 2

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.

  1. Backed up the contents of /boot.
  2. Backed up everything else! Best to be on the safe side when partitioning.
  3. Stopped /dev/md1 array:

    mdadm --stop /dev/md1
    
  4. 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.
  5. Copied the partition table of /dev/sda to /dev/sdc:

    sfdisk -d /dev/sda > part_table
    sfdisk /dev/sdc < part_table --force
    
  6. 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

  7. 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
    
  8. Removed old ‘ARRAY …’ lines from the end of /etc/mdadm.conf and generated the new ones:

    mdadm --detail --scan >> /etc/mdadm.conf
    
  9. Created ext2 filesystem on /dev/md1:

    mkfs.ext2 /dev/md1
    
  10. 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
    ...
    
  11. Tested that array starting and mounting worked.

    mdadm --stop /dev/md1
    mdadm --assemble /dev/md1 /dev/sda1 /dev/sdb1 /dev/sdc1
    mount /boot
    
  12. Copied backed-up boot files back in to /boot:

    cp backup/boot/* /boot/. -r
    
  13. Installed grub on all disks:

    grub2-install /dev/sda
    grub2-install /dev/sdb
    grub2-install /dev/sdc
    
  14. Removed old grub:

    emerge -C sys-boot/grub:0
    
  15. Configured grub2:

    grub2-mkconfig -o /boot/grub/grub.cfg
    
  16. Restarted computer:

    shutdown now -r
    

It booted :-)

References

Last modified: 19/10/2013 Tags: (none)

This website is a personal resource. Nothing here is guaranteed correct or complete, so use at your own risk and try not to delete the Internet. -Stephan

Site Info

Privacy policy

Go to top