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?

2

3 Answers

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.

It turns out the answer was simple, I needed to install the grub-efi package:

sudo apt-get install grub-efi 

You can rebuild the master boot sector with bootrec.exe, the tool available in the Windows Recovery Environment.

  1. Insert your Windows install disc
  2. Press any key at the “Press any key to boot from CD or DVD” message to boot from the disc
  3. Choose Repair your computer after you select the language, time and keyboard method (for Windows 7 users). XP users: Press R to access Recovery Console
  4. Select your Windows installation drive (usually C:) and click Next. XP users may not have this step.
  5. Select Command Prompt in the System Recovery Options box. Users of XP will need to enter their Administrator password to open Command Prompt
  6. Write the following commands in the Command Prompt:

     bootrec /fixmbr bootrec /fixboot bootrec /rebuildbcd 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like