Search code examples
debiangrub

Debian GRUB rescue - "invalid arch independent ELF magic"


I have recently dual-booted a Windows PC with Debian Wheezy. The installation went fine with no errors, but when I boot to Debian I am immediately greeted with GRUB rescue:

Welcome to GRUB!

error: unknown filesystem.
Entering rescue mode...

After examining further using the set command I notice that it is booting to the wrong partition:

grub rescue> set
prefix=(hd0,gpt4)/boot/grub
root=hd0,gpt4

Here it is pointing to (hd0,gpt4) when the location Debian is installed to is (hd0,gpt5). So, I did a quick fix using set to change the variables back to what they should be:

grub rescue> set prefix=(hd0,gpt5)/boot/grub
grub rescue> set root=gd0,gpt5

After doing this, I did only what I remembered I should do to boot to the OS and ran:

grub rescue> insmod normal

This is where things start to go wrong as I get the error:

error: invalid arch independent ELF magic.

I then did some research on this problem and it seemed the common solution was to reinstall GRUB from a live CD. So, I booted into a live CD of Debian and ran the following:

sudo mount /dev/sda5 /mnt
sudo grub-install --root-directory=/mnt /dev/sda

Where I am given the error:

The file /mnt/boot/grub/stage1 not read correctly.

Although I can assure that this file does exist and is editable as I could edit it with

sudo nano /mnt/boot/grub/stage1

So what could be the problem?


Solution

  • Whilst installing grub-efi fixed things on your system (because it supports both the traditional BIOS boot process, as well as EFI booting), if you wanted to fix the original grub install, the answer was possibly:

    apt-get install --reinstall grub-pc-bin grub-pc

    followed by:

    grub-install /dev/sdX

    where /dev/sdX should be replaced by your boot drive (or drives).

    ... this will replace what looks to be corrupted versions of the grub binaries (which is what "invalid arch independent ELF magic" means) on the boot drive.