title: Debian GRUB rescue - "invalid arch independent ELF magic"
body: <p>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:</p>
  
  <pre><code>Welcome to GRUB!
  
  error: unknown filesystem.
  Entering rescue mode...
  </code></pre>
  
  <p>After examining further using the <code>set</code> command I notice that it is booting to the wrong partition:</p>
  
  <pre><code>grub rescue&gt; set
  prefix=(hd0,gpt4)/boot/grub
  root=hd0,gpt4
  </code></pre>
  
  <p>Here it is pointing to <code>(hd0,gpt4)</code> when the location Debian is installed to is <code>(hd0,gpt5)</code>. So, I did a quick fix using <code>set</code> to change the variables back to what they should be:</p>
  
  <pre><code>grub rescue&gt; set prefix=(hd0,gpt5)/boot/grub
  grub rescue&gt; set root=gd0,gpt5
  </code></pre>
  
  <p>After doing this, I did only what I remembered I should do to boot to the OS and ran:</p>
  
  <pre><code>grub rescue&gt; insmod normal
  </code></pre>
  
  <p>This is where things start to go wrong as I get the error:</p>
  
  <pre><code>error: invalid arch independent ELF magic.
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>sudo mount /dev/sda5 /mnt
  sudo grub-install --root-directory=/mnt /dev/sda
  </code></pre>
  
  <p>Where I am given the error:</p>
  
  <pre><code>The file /mnt/boot/grub/stage1 not read correctly.
  </code></pre>
  
  <p>Although I can assure that this file does exist and is editable as I could edit it with </p>
  
  <pre><code>sudo nano /mnt/boot/grub/stage1
  </code></pre>
  
  <p>So what could be the problem?</p>