Freely Scripted Soul

February 3, 2008

Reinstalling Grub boot loader

Filed under: Software and Technology,Ubuntu — Roshan @ 8:41 am
Tags: , , , ,

REASONS:

 

  • Grub, by default, resides in the Master Boot Record(MBR). When you try to install some other boot loader or try to install/reinstall Windows, the grub information in the MBR will be overwritten. So, Grub might have to be reinstalled.
  • When some/any part of partition information is changed, the grub configuration won’t be automatically notified of it and so, the grub configuration will remain as it is. There maybe many cases in which the partition information maybe changed like when you create an extra partition, which is something trivial and may or may not affect the grub boot loader. However, most of the times, changes in the partition information will result in errors when the grub boot loader is loaded. So, the grub configuration has to be updated and the easiest way is to reinstall Grub.

 

There are many such cases and in these cases, people tend to treat the effect, more than the cause. By this, I mean people tend to usually reinstall Ubuntu or Fedora or whichever GNU/Linux operating system they are using, through which Grub will be automatically reinstalled. But is it necessary? No, Grub can be reinstalled without reinstalling the entire operating system! In fact, Fedora CD/DVD does offer to reinstall Grub if you choose to upgrade your system. However, I have tried to use that option in many of my friends’ computers and it has never worked! I have no idea why it doesn’t work. So I resort to the easiest fool-proof method I know – COMMANDS @ TERMINAL

 

COMMANDS TO REINSTALL GRUB:

 

All you need to do is access the terminal using the installation CD/DVD of your GNU/Linux operating system. Ubuntu installation CD is a live CD and so, when it loads, you can run the terminal from there. Fedora installation CD/DVD offers options through which you will have to choose to upgrade the system using commands(rescue mode).

 

Once you are at the terminal, you will have to access the ‘grub’ shell to change the grub configuration. So, give this command at the terminal:

$ grub

If it says that you don’t have the permission, in which case you will not have logged in as root(as in Ubuntu), give this command at the terminal:

$ sudo grub

You will get the grub-shell prompt:

grub>

 

Now, you will have to find out in which partition Grub had been installed before, so that you reinstall in that partition only. Give this command at the terminal:

grub> find /boot/grub/stage1

(returns value)

It returns the number of the partition in which Grub i.e your GNU/Linux had been installed.

e.g.,

grub> find /boot/grub/stage1

(hd0,2)

 

NOTE:

Sometimes, when Grub has not been installed properly, the file “/boot/grub/stage1” may not exist. So, the output will be “Error 15: File not found”. In such a case, come out of the grub-shell by pressing “Ctrl+c”. Then, at the shell prompt, give this command at the terminal:

$ fdisk -l

Again, if you are not logged in as root, give this command at the terminal:

$ sudo fdisk -l

The output will list all the partitions and it’s properties, including the file system type.

e.g.,

Device Boot Start End Blocks Id System
/dev/sda1   1 654 5253223+ b W95 FAT32
/dev/sda2 * 655 1962 10506510 7 HPFS/NTFS
/dev/sda3   1963 3924 15759765 83 Linux

The “System” attribute of your GNU/Linux operating system will be “Linux”. So note down that partition number.

e.g., sda3

Since it’s array numbering, sdaN is mapped to (hd0,N-1).

Just (hd0) will be the Master Boot Record(MBR).

sda1 will be (hd0,0) and so on.

So, sda3 will be (hd0,2)

Now, log into the grub-shell prompt again.

 

Before reinstalling Grub, you will have to notify the partition that your Grub i.e. GNU/Linux is resided in. So, give this command at the terminal:

grub> root (returned value)

e.g.,

grub> root (hd0,2)

 

Now, reinstall grub in the MBR i.e. the returned value without number part.

e.g., (hd0)

So, give this command at the terminal:

grub> setup (returned value without number part)

e.g.,

grub> setup (hd0)

 

Exit the grub-shell prompt using “Ctrl+c”.

Exit the shell prompt using “Ctrl+d”.

 

PS:

You can also reinstall Grub in your GNU/Linux partition, only if this GNU/Linux partition is “primary” and you have another boot loader installed at the MBR(in case of more than one GNU/Linux operating systems) through which you can boot this primary partition. To do that, give this command at the terminal:

grub> setup (returned value)

e.g.,

grub> setup (hd0,2)

Advertisements

43 Comments »

  1. Soooper Roshan. Its really awesome. Its now easy to tell people how to do this simple job. All these days we had to explain this petty thing for hours on phone. Now its just a matter of giving one link.
    Thanks a lot for this. Great Work!!!
    One more thing, I saw you using GNU/Linux. Thats the way to set an example to others. Great!!! Most of them do the mistake of using only Linux part of it which is a blunder according to me. Thanks a lot for giving GNU its due credits. Thanks a lot.

    Comment by Madhusudan.C.S — February 29, 2008 @ 3:39 pm | Reply

  2. Roshan. Wherever You Are Right Now…
    I Just Wanted You to Know that You Just Saved My Life, Man! Thanks!!!

    Comment by Darryl — April 21, 2008 @ 11:55 am | Reply

  3. Super Grub Disk rocks! Multi Linux!!
    repair restore recover [reinstall] linux GRUB bootloader/menu,
    or multi OS/distro multi disks/partitions MBR!
    It works on my ubuntu 7.04 in 1 minute!
    see their wiki for
    “SGD Quick Menu”
    “Multi Distribution Boot Howto”
    “Boot Problems”
    “Howto Fix Grub”

    Comment by meka4996 — June 20, 2008 @ 3:02 am | Reply

  4. Roshan,

    Thanks so much! I blew my grub loader tinkering with a program in Mandriva Spring 2008. I was sure I had hours of tedious, frustrating work ahead of me, but as luck would have it, I hit upon your page first.

    The reinstallation process worked instantly, exactly as you described it!

    drblock

    Comment by drblock — July 5, 2008 @ 3:15 pm | Reply

  5. Roshan

    Thanks a lot for the informative piece on installation of grub.It should help me big time because twice I wrecked up my Grub and both the times I had to re-install Ubuntu losing all my software installation.

    Comment by Siddharth — July 8, 2008 @ 8:31 am | Reply

  6. thanx a lot, God bless you

    Comment by fares — August 22, 2008 @ 3:54 pm | Reply

  7. When I tried the find /boot/grub/

    Comment by That Anonymous Kid Down The — October 4, 2008 @ 12:39 am | Reply

  8. stage1 thing, it returned two hard drives. One of them was (0,0), which was my Ubuntu hard drive, and the other was (2,0), with openSUSE 11.0. What do I do?

    Comment by That Anonymous Kid Down The — October 4, 2008 @ 12:41 am | Reply

  9. new to linux, installed fedora9, got the problem error, after dropping the “$”, I got the drive info, but it also told me “Disk /dev/dm-0 doesn’t contain a valid partition table”. I did just the standard install, only one 80gig drive, anything I’m missing?
    thanks in advance.

    Comment by bowwhyte — October 21, 2008 @ 4:25 am | Reply

  10. Thanks a million!

    Comment by brennan — October 31, 2008 @ 6:51 am | Reply

  11. fantastic! best step by step recovery of a mangled linux install or partition that this noob (migrating from mac os x, not windows, no less) has yet encountered. especially good are the anticipations of common error messages.

    Comment by dave — December 6, 2008 @ 8:37 am | Reply

  12. Useful and informative, thanks!

    Comment by Shujaa — December 25, 2008 @ 3:21 am | Reply

  13. This is the first how-to I have found, in a whole day trying to fix my grub problem, that said what to do if the “find” command came back as “not found”. Thanks!

    Comment by Amanda — January 30, 2009 @ 12:56 am | Reply

  14. I finally clued in. I was trying to install grub to (hd1,1) which is my Ubuntu partition instead of (hd0) which is my windows boot partition. If I selected to boot to my second hard drive I would see the grub menu list but it would not let me start Ubuntu from there but it would let me start windows. Thank you!!!

    Comment by smith_mg — February 6, 2009 @ 4:36 am | Reply

  15. You guys are all experts but you really need to understand that for people that are trying to NOT HAVE WINDOWS then Ubuntu support does nothing when the grub loader is lost, no way to recover, no way to reload it, all you guys do is fall back on WINDOWS to fix the mess. To hell with windows and Gates PUT a system boot resotore function on the live CD!!!!!!!!!!!!!!!!! As there are things that somhow destroy the MBR in Liniux and i am tired of having to reinstall a whole OS and live with lost data cause while Unbuntu is GREAT, it is only great if it will BOOT, and this is making me very angry as it has happened a lot. For some reason the Wubi systems do not have this problem but Linux as a stand alone, has a very unstable grub loader and boot system that in time will fail and when it does all of you expert guys fall back on your custom hybrid Vista this or XP that crap with no consideration for people who used the Ubuntu live CD install and either used one of the two choices it gives in the first partition manager on install.

    This is what holds you back Ubuntu all your experts have window on the brain, and I do not want a MBR done by gates and I hate haing to go back to dos to Fdisk and start all over and spend a day fixing what a little THOUGHT could have anticipated and stuck a programs on the live CD to RESTORE A BOOT GRUB ON WINDOWLESS SYSTEMS!

    Comment by ohn — March 3, 2009 @ 6:10 am | Reply

  16. The guy is right Ubuntu needs to drop the Windows and start making it with people who do not use windows in mind. Once Ubuntu crashes if you don’t have windows then you are screwed and no one at support stops to think about people using a standard install as a stand alone system……. Great system if if starts….. but you never know about the MBR and if the grub is gone.

    Comment by Ryah — March 3, 2009 @ 6:13 am | Reply

  17. Thank you very much for this. These instructions worked on CentOS 5.2. That installation wants to either install grub to MBR on hda (where my windows system sits), or to partition record in /boot; I chose the second. After install, Grub would part-way load and then stall with error 15. After doing the grub setup (hd1), everything worked fine. Note, on my system, hdb is initial boot drive in bios.

    I was going to reinstall OS after pulling windows drive until I found this helpful place.

    Comment by unclesmrgol — March 18, 2009 @ 5:51 pm | Reply

  18. Hi,Roshan…Thank you very much..simply explained you..This will very useful for beginers and all others..

    Comment by Abhilash.S>V — March 31, 2009 @ 9:56 am | Reply

  19. I don’t like your blog.

    Comment by Nikhil V — April 3, 2009 @ 10:50 am | Reply

  20. This is too much ansuththe

    Comment by Nikhil V — April 3, 2009 @ 10:51 am | Reply

  21. and u can use the live disk to boot up your own os too

    alls u do is press F6, then escape, then remove the stuff before the “initrd=” stuff

    then can put “root=/dev/(root-partition-number) rw” before “initrd=”
    and it will boot your system, it gets u into YOUR gui, to which u can do what was suggested up top in a terminal window, and you can have your system back, good as new

    thats what i just did.

    i do agree it needs the restore option from the DVD editions put in as a option in the live discs.

    Comment by sm — April 17, 2009 @ 12:04 am | Reply

  22. delete those two comments man, I didnt write them, why do you still have them around

    Comment by n — May 4, 2009 @ 1:43 pm | Reply

  23. Nice work.

    Comment by Govanthan M — May 15, 2009 @ 6:23 am | Reply

  24. YAA Adding this to my bookmarks. Thank You

    Comment by women high heel shoes — June 14, 2009 @ 2:08 pm | Reply

  25. Dear Roshan,

    Linux lovers need people like you.I did read your post with awe! How lucidly you explained solution for the nightmare of a Linux beginner.Thank you
    – Rajeev

    Comment by Rajeev — July 8, 2009 @ 6:14 pm | Reply

  26. Awsome guide, simple and to the point, saved me a lot of time with trial and error

    Thanks!!

    Comment by Davve — November 8, 2009 @ 3:37 pm | Reply

    • It’s complicate this guide… realy try to make it more short to be more easy to read and understand it

      Comment by kordosoft — November 19, 2009 @ 7:16 pm | Reply

  27. Thankzzzzzzzzzzzz dear..

    Comment by anand — December 5, 2009 @ 9:11 am | Reply

  28. Hi there…
    My bootloader doesn’t work so I used ubuntu 9.10 live CD to repair it, I did all the instruction which u gave above but there is sth wrong here, THERE IS NO STAGE1 in my grub?!?!?!?!

    grub> root (hd0,6)

    grub> setup (hd0)
    Checking if “/boot/grub/stage1” exists… no
    Checking if “/grub/stage1” exists… no

    Error 15: File not found

    BTW I’m new in Linux so plz help me 😦

    Comment by Cambyses — December 7, 2009 @ 8:34 am | Reply

  29. Hi,

    One more thank-you for writing up this tutorial. I was able to recover my instance of Ubuntu (needed to refer to the ‘Note’ section – so thanks, too, for contributing that).

    Best,
    Ian

    Comment by Ian — December 30, 2009 @ 6:00 am | Reply

  30. hi,

    i have grub installed in the first partition and window xp and xp 64 in the next two

    linux is installed in a logical partition

    the machine won’t boot to grub (all of a sudden). i can reach grub through typing “help” but that’s about it.

    I’s like reinstall grub on the first partition, and will have to use the menu info I have stored.

    how do i place it i the first partition and enter the correct positions for each of the operating systems?

    Comment by dorian jones — November 5, 2010 @ 1:19 pm | Reply

  31. GRUB4DOS 0.4.4 2009-4-20,memory 639k/ 1788m Menu End 0×434CE
    [Minimal BASH -like line is
    supported. For the first word, TAB list possible command completions.
    Anywhere else TAB lists the possible completion of a
    device/filename.ESC at any time exists.]
    GRUB>root (hd0,1)
    FileSystem type is ntfs,partition type 0×07
    GRUB>setup (hd0)
    Error 15 file not found
    GRUB>setup (hd0,1)
    Error 15 file not found

    please help me immediately………………..

    your’s obediently

    A.Nijamudeen

    Comment by nijam — December 4, 2010 @ 10:17 pm | Reply

  32. I can’t find the returned value i,e. It tells me error 15:File not found.

    Comment by Psam — June 21, 2011 @ 1:19 pm | Reply

  33. Thanks,

    Nice post… You saved me a lot of time….

    Comment by Rajendra Kumar — October 29, 2011 @ 4:59 pm | Reply

  34. Fantastic job you did laying out this well reasoned and throughtout solution to reinstalling a wayward bootloader.

    Now that you have armed me with the howto of reinstalling, I will get to work.

    I am running Windows XP home edition
    along with
    Ubuntu 11.10

    With a grub bootloader which

    Boots up to Ubuntu for 60 seconds

    if not selected within 60 seconds it automaticallt loads OS Ubuntu

    I can also select Windows XP within the 60 Seconds

    Something went wrong and I get three pages of commands terminal commands and my choices nolonger are available to me.

    Comment by JM — November 3, 2011 @ 2:23 pm | Reply

  35. Hello,
    I am using CentOS 5.2 Servers with Kickstart but in this days i am facing problem while booting and some time ” Please select Proper Boot device or Reboot the system ” Error come and then i cant boot to system without restore the database. so please give me the solution. Please help me.

    Comment by Ashok Gawali — August 1, 2012 @ 6:32 pm | Reply

  36. I’ll post my question here because I’m a little confused.

    My Centos install has 3 partitions
    100 meg for /boot
    6000 for swap
    and the rest is created for /

    my device names are:
    /dev/dciss/c0d0p1
    /dev/dciss/c0d0p2
    and /dev/dciss/c0d0p3 respectively.

    I am not sure which parition (the boot ‘p1’ or the ‘/’ ‘p3’ should contain the grub loader. My /boot partition is marked as boot with an asterisk?

    any help would be appreciated

    Comment by Jeff Jennings — December 6, 2012 @ 3:57 pm | Reply

  37. […] partition is marked as boot with an asterisk? I am following the instructions provided here: https://roshan18.wordpress.com/2008/0…b-boot-loader/ however I'm a little concerned because I though I'd be installing the grub loader in (hd0,2) and I […]

    Pingback by need to some identifying where to re-install grub loader on my system. — December 6, 2012 @ 5:06 pm | Reply

  38. I hardly leave a response, however after looking at through a
    great deal of responses on Reinstalling Grub boot loader « Freely Scripted Soul.
    I do have some questions for you if you do not mind. Could it be simply me or do some of the responses look like they are written
    by brain dead people? 😛 And, if you are writing on additional places, I would like to follow you.
    Could you post a list of all of all your social community
    pages like your Facebook page, twitter feed, or linkedin profile?

    Comment by Great Movie Site — January 4, 2013 @ 6:13 am | Reply

  39. は友人、家族、同僚に感謝、個々のときあなた供給それらあなたの高品質の卸売財布とハンドバッグとしてもの-彼ら間違いなくは知っていることどのようにそれくらいあなたの費用が!かどうかしようとして革、スエード、コンパートメントのジッパー、ひも、長いまたは簡単な言葉ストラップ、または参考無限の多様性の色、あなたすることができます何を見つけるお客様から必要卸売財布販売代理店。

    Comment by グッチ リュック — June 28, 2013 @ 1:49 am | Reply

  40. 、ウェブサイト紹介新しいファッションも格安卸売ハンドバッグ。我々はすべて使用問題材料良い選択私たちproductsgucciボックス。私たちのハンドバッグです特定に厳格な必需品品質のまた長寿。すべての格安ハンドバッグされる完璧な品質と手頃な価格ここ。我々しようとするは非常に最高する私たち顧客満足度と私たち商品と支援繁体.

    likesヴェルサーチのバッグ、ミュウミュウバッグだけ待機を!

    Comment by www.maypole.co.kr — June 28, 2013 @ 1:58 am | Reply

  41. シャネル 3213 メガネのペア は は 「オタク
    シックな」外観に 2010 年 したいが 場合に 迷う の 1 つの chunkier
    フレーム、 人 シャネル眼鏡 フレームをサポート は、 さらに 繊細な方法 参加する に、 開発。大きな黒いフレーム が 薄肉リム を使用して、 小さな CC シンボル アクセント、 寺院や寺院 銀の。

    Comment by シャネル コピー — June 28, 2013 @ 2:13 am | Reply

  42. Despuu00e9s de ver la foto donde salen varios detenidos se ve que levantaron a cuanto borrachu00edn vieron, se nota que de chiripa dieron con los que tenu00edan la droga, por que y hay varios que se nota que por estar en la calle los levantaron por pasar cerca de ahu00ed. Come on http://tropaadet.dk/spencehendricks67608190

    Comment by spencehendricks676 — April 8, 2016 @ 11:05 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: