How to restore grub with a live CD

I borked my primary boot device’s grub installation last week because I wanted to start Windows 7 to play some LAN games. Windows 7 wouldn’t boot from grub, so I thought I’d install a new grub version. I reinstalled grub before regenerating the config file and rebooted. Too bad the Arch packages don’t handle that for you, as I was used to in Debian. This caused the grub to fail booting both Windows and Arch, so I resorted to changing my primary boot device in the BIOS.

Now, one week later, I decided to fix it, and as I can never recall by heart what the steps to take are, here’s a recipe, pretty much for my own convenience.

I’m running Arch Linux currently, but the same principle should work for any Linux flavour you might be using.

Recipe

  1. Boot from whatever live CD you have lying around
  2. Login in a shell
  3. Create a local mount point for your hard disk’s root device (eg /mnt/root)
  4. Mount the root partition onto that mount point

    # mount /dev/sda1 /mnt/root
  5. Mount the device system

    # mount -o bind /dev /mnt/root/dev
  6. Mount the proc file system

    # mount -t proc none /mnt/root/proc
  7. Change root

    # chroot /mnt/root
  8. Make sure the boot partition is mounted, if you have one.

    # mount /boot
  9. Regenerate grub config

    # grub-mkconfig -o /boot/grub/grub.cfg
  10. Reinstall grub

    # grub-install /dev/sda
  11. Reboot and enjoy.

    # shutdown -r now

Of course, you need to substitute the device names with your own.

This entry was posted in Linux & BSD and tagged , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.

2 Comments

  1. ArchiMark
    Posted June 27, 2013 at 18:40 | Permalink

    Hi,

    Great and relevant post….

    Recently setup little Libretto U100 laptop to dual boot WinXPP and Arch…..worked well…

    Then I decided to install Win 7 over WinXPP and after that I can only boot up to Win7, don’t see Grub boot menu now…

    So, your instructions are just what I was looking for….

    However, when I try to do Step 7 Change Root in your instructions, I get the following error message:

    chroot: failed to run command /bin/zsh: No such file or directory

    This seems odd as I did create the /mnt/root directory and did Steps 1-6 before trying to do Step 7

    Any suggestions?

    Thanks,

    Mark

    • drm
      Posted July 6, 2013 at 14:12 | Permalink

      I am assuming your chrooted environment lacks zsh, which is probably set up as your account’s shell. I suggest either trying to install zsh within the /mnt/root, or try changing your user’s default shell, by calling chsh first.

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Subscribe without commenting