grub2 cannot read core.img

When trying to install grub2 (whatever snapshot was current as of today) I kept getting the following error:
$ sudo /sbin/grub-setup -v --directory=/media/sysrescd/boot/grub \
--device-map=/media/sysrescd/boot/grub/ -r '(hd1,1)' '(hd1)'
.... snip ...
grub-setup: error: Cannot read `/media/sysrescd/boot/grub/core.img' correctly

The error was not very descriptive because grub was apparently able to read other important files like boot.img and such. The filesystem on my USB stick was identical (feature wise) to the /boot on my HDD -- ext2. And the same command worked just fine for installing to my hard disk.

Digging through the code revealed where the problem is. The error was caused by grub-setup being unable to embed core.img in the MBR. The core.img prepared by grub-mkimage was 25k big. That is about 50 sectors. The first partition on my hard disk starts on sector 63. The first partition on my USB stick was starting on sector 32 (or was it 31?). 32 < 50 => core.img cannot be embedded. If only the error message had been a little clearer it would have saved me some headache.

Destroying the first partition on the USB stick and recreating it starting from sector 63 fixed the problem.


  1. Thanks for posting this information. This helped me with my long-standing problem. Grub2 despirately needs some basic technical documentation, including common issues like this one. So sad that it is so neglected, since it is so important.

  2. Thanks pal. You've saved lot of my time.

  3. how do you destroy the first partition and recreate it from sector 63?

  4. @cmh: You can do it with fdisk, but you should tell it to use sectors as a unit. Either start fdisk as "fdisk -u", or type "u" once you are in the fdisk interface. Then delete the partition and create it again (you will of course lose all data on the partition). A snipped down fdisk session:

    $ sudo fdisk /dev/sdb
    Command (m for help): p
    Device Boot Start End Blocks Id System
    /dev/sdb1 * 1 3011 3915204 b W95 FAT32
    Command (m for help): u
    Changing display/entry units to sectors
    Command (m for help): p
    Device Boot Start End Blocks Id System
    /dev/sdb1 * 1144 7831551 3915204 b W95 FAT32
    Command (m for help): d
    Selected partition 1
    Command (m for help): n
    Command action
    e extended
    p primary partition (1-4)
    Partition number (1-4): 1
    First sector (51-7831551, default 51): 63
    Last sector, +sectors or +size{K,M,G} (63-7831551, default 7831551): +1G
    Command (m for help): p
    Device Boot Start End Blocks Id System
    /dev/sdb1 63 2097215 1048576+ 83 Linux


Post a Comment

Popular posts from this blog

LVM metadata corruption

ADSL Router Model CT-5367 user and pass (VIVACOM)