Restore GRUB (Archlinux)
Sometimes I have the need to restore GRUB as bootloader. This especially happens after a Windows installation/upgrade.
Note: this only works for grup version 1, not for grub version 2 and greater.
Anyway, I wanted to document (and share) and easy method for doing just this. Reason: I found it hard to find on the internet. If it turns out to be useful for you… then it would be nice if you leave a short (friendly) comment.
Here we go.
1. Boot linux
Well, of course we will boot Linux from a livecd. Personally I use the archlinux install cd for this, but all this is up to you! With the arch install cd at least I know that the following procedure works.
2. Set up the chroot environment
Now we need to use the originally installed linux system in order to install grub nicely. For this we use a chroot environment. Before we can start, find out what hard disk your linux system is on (use fdisk -l).
Create a directory where you would like to mount the device or partition, then mount it:
mkdir /mnt/arch mount /dev/<device-or-partition-name> /mnt/arch
Now create the chroot environment:
cd /mnt/arch mount -o bind /dev dev/ mount -t proc proc proc/ mount -t sysfs sys sys/
Mount other parts of your filesystem (e.g. /boot, /var, /usr…) that reside on separate partitions but which you need access to. For example:
mount /dev/<device-or-partition-name> boot/
Now chroot to your installed device or partition and define your shell:
chroot . /bin/bash
As we will be dealing with GRUB we need to ensure that our mtab file is up-to-date:
grep -v rootfs /proc/mounts > /etc/mtab
3. Install GRUB (again)
First we start the GRUB shell:
Now we are in the GRUB shell and we tell it where to boot from;. Let us ensure that we know where to boot from:
The answer to this will be used in the next command (example: for a /dev/sda5, the answer will be (hd0,4)):
root (hd0,4) setup (hd0)
If this was succesfull, then exit GRUB:
and exit the chroot environment:
Now make sure all changes have been saved
and reboot to check if everything worked as planned.
Anonymous (not verified)
Thanks for this. I have exactly the same situation and hope this will fix it normally. I’ll try it out later, it looks genuine. Thanks again! -Roelof
Anonymous (not verified)
. February 12th, 2011
I googled for something like this and your instructions were straightforward and easy to understand. It fixed my Grub after Windows7 for no apparent reason caused my Grub to bootloop when loading menu.lst.. This fixed it! Thannks again (will follow your posts closely now)
Krum (not verified)
. May 22nd, 2011
Great! Thanx a lot.
Alvinator (not verified)
. August 27th, 2011
For people who have a separate /boot partition
Thank you very much for this. I had a small problem on the find step. Checking out the official GRUB ArchWiki, people who have a separate /boot partition like me have to do this instead:
Take note that yo just have to omit the /boot prefix. After that, all will be fine! :)
Dennis Martinez (not verified)
. June 26th, 2012
This worked perfectly on my laptop with the latest Arch Linux (fully up-to-date). Thank you so much! One small hiccup I encountered was that when I was trying to chroot to the mounted partitions, I got the following error: “chroot: cannot run command ‘/bin/bash’: Exec format error”. After a quick search I found out it was due to me using the 32-bit (i686) boot disc as the rescue disc, while I installed the 64-bit (x86-64) version of Arch on my laptop. After using the 64-bit version as the rescue disc, everything was flawless. You might want to update the blog post in case someone else encounters this :)
V. T. Eric Layton (not verified)
. July 8th, 2012
Patrick, I know this is a somewhat dated post, but I wanted to add my thanks to the others here. I was playing around with LILO earlier today, but couldn’t get it to do what I wanted, so I was going to chroot into my Arch and reinstall GRUB to the MBR. Ooops! My previous chroot methods weren’t working… bad block errors. :( Your tutorial fixed it for me. Thanks a bunch! :) ~Eric
Aashish (not verified)
. December 17th, 2012
I use Arch Linux and I have the same problem, I installed Win 7 and now no linux bootloader. I have been trying to follow the method that you describe here and the same thing is described in the Arch Linux wiki as well. I used both ArchBang Live CD and Arch Linux installation image from USB but I cannot get to the grub shell. When ever I type grub it says cannot find command grub.
. December 19th, 2012
Please notice that the description above only works on systems with the grub version 1. For grub 2 a different method is required. I am concidering to update the documentation,, but I had no need for it myself yet.
In the meantime this guide might work: https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows
Aashish (not verified)
. December 20th, 2012
While my question was under review I went ahead and reinstalled everything again. I wanted to do it anyway for a pure systemd installation anyway. I will keep the link in mind if I have the same problem or need to advise others the next time.
Rocksteady_Racer (not verified)
. April 20th, 2013
My Windows 7 OS crashed (thank god for having 6 different partitions). So I had to reinstall it and windows likes to take over the MBR in the process. This worked perfectly. Also FYI USB Stick Installation media is way faster for both Windows 7 from iso and Arch IMHO. Just use winusb in linux from the command line for win7 usb or dd for archlinux. Works like a cupcake.